我有一個java類,代碼如下。多權限
public class PermisssionAction {
public static void requestPermission(Activity activity, String permission) {
if (ContextCompat.checkSelfPermission(activity, permission)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, new String[]{permission}, 0);
}
}
}
現在我在mainactivity中調用它的方法來獲取應用程序的權限,如下所示。
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
PermisssionAction.requestPermission(this, Manifest.permission.READ_PHONE_STATE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
PermisssionAction.requestPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
}
PermisssionAction.requestPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
PermisssionAction.requestPermission(this, Manifest.permission.READ_CONTACTS);
PermisssionAction.requestPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION);
PermisssionAction.requestPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
PermisssionAction.requestPermission(this, Manifest.permission.READ_SMS);
PermisssionAction.requestPermission(this, Manifest.permission.INTERNET);
PermisssionAction.requestPermission(this, Manifest.permission.BLUETOOTH);
PermisssionAction.requestPermission(this, Manifest.permission.ACCESS_WIFI_STATE);
PermisssionAction.requestPermission(this, Manifest.permission.SEND_SMS);
Intent startupintent = new Intent(MainActivity.this, StartupActivity.class);
startActivity(startupintent);
finish();
}
}
現在我不是能理解爲什麼只問一個許可,而在真正的移動應用程序運行,而它要求所有許可,不得以一氣呵成的模擬器。 還假設應用程序第一次拿到位置許可,當你再次打開應用程序時,它會要求另一個許可待定等等在真實設備上。你能指導嗎?
但我在檢查權限之前還請求,如果你看到密切的方法。唯一的區別是,我是一個一個地問而不是數組。 –