0
私はMarshmallow Devicesの次のコードを使用しました。私はヌーガットで私のアプリを動かすために何を使うべきでしたか?Nougatデバイス用にアプリを実行するにはどうすればよいですか?
boolean isMdevice;
boolean pstatus;
String[] perms = {Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.INTERNET,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CALL_PHONE,
Manifest.permission.READ_CONTACTS,
Manifest.permission.SEND_SMS,
Manifest.permission.WRITE_CONTACTS,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.RECEIVE_SMS};
int code = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
isMdevice = isMarshmallowPlusDevice();
pstatus = isPermissionRequestRequired(One_Activity.this, perms, code);
}
public static boolean isMarshmallowPlusDevice() {
return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1;
}
@TargetApi(Build.VERSION_CODES.M)
public static boolean isPermissionRequestRequired(Activity activity, @NonNull String[] permissions, int requestCode) {
if (isMarshmallowPlusDevice() && permissions.length > 0) {
List<String> newPermissionList = new ArrayList<>();
for (String permission : permissions) {
if (PERMISSION_GRANTED != activity.checkSelfPermission(permission)) {
newPermissionList.add(permission);
}
}
if (newPermissionList.size() > 0) {
activity.requestPermissions(newPermissionList.toArray(new String[newPermissionList.size()]), requestCode);
return true;
}
}
return false;
}
最新のAndroidスタジオ(2.3)を使用していて、最新のsdkも使用しています。私のアプリをノーガットでも適用する最良の方法は何ですか?
'targetSdkVersion 23'を設定した場合、最初に' targetSdkVersion 25'を設定してください –