1
我正在嘗試請求我的啓動程序活動權限。對於API < 23,它完美。但是,當我在運行API 23的設備上測試應用程序時,它會顯示:「PostPaid Balance已停止。」我點擊「關閉應用程序按鈕」,應用程序關閉,並立即要求一個許可。我接受了。然後我點擊應用程序圖標重新打開,同樣的事情發生,除了現在它要求下一個權限。然後點擊應用程序圖標,這一次正確執行。 它似乎是一次要求一個權限。有關如何去做這件事的任何想法?Android API 23請求多個權限
// Below code is implemented on onCreate() of the launcher activity.
if (Build.VERSION.SDK_INT < 23) {
ActivityCompat.checkSelfPermission(this.getApplicationContext(), "android.permission.READ_SMS");
ActivityCompat.checkSelfPermission(this.getApplicationContext(), Manifest.permission.READ_CALL_LOG);
ActivityCompat.checkSelfPermission(this.getApplicationContext(), Manifest.permission.READ_PHONE_STATE);
if ((ActivityCompat.checkSelfPermission(this, "android.permission.READ_SMS") != PackageManager.PERMISSION_GRANTED)) {
requestSmsPermission();
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
requestPhoneStatePermission();
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
requestCallLogPermission();
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if ((this.checkSelfPermission("android.permission.READ_SMS") != PackageManager.PERMISSION_GRANTED) &&
(this.checkSelfPermission(Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) &&
(this.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED)) {
this.requestPermissions(new String[]{"android.permission.READ_SMS", Manifest.permission_group.PHONE}, REQUEST_SMS);
}
}
請求是在單個'requestPermissions所有三種權限()'調用。此外,還不清楚爲什麼您的代碼基於API級別設置爲執行不同的操作。 'ActivityCompat'和'ContextCompat'是向後兼容的。 – CommonsWare
我設置的代碼做不同的事情,因爲某些功能不可用於API <23 –
您會推薦什麼?如果API是23並且不理會if(API <23),我應該只要求權限? –