我有一個短信應用程序,現在在6.0用戶必須允許應用程序發送短信。 現在我有這個代碼,我從link here得到。如何使應用程序檢查權限是否被授予(6,x +)Android
int MY_PERMISSIONS_REQUEST_READ_CONTACTS=0;
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.SEND_SMS)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.SEND_SMS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
但是,當我拒絕接取(如果用戶不小心點擊按鈕)逝去的將幾乎使應用程序崩潰(因爲短信按鈕不會工作)。因此,當用戶在用戶拒絕訪問後啓動/重新啓動應用程序時,我希望應用程序再次提問。現在,當我嘗試在我的模擬器上沒有對話框會再次出現,所以我不得不去設置/應用程序並設置權限。或者卸載並重新安裝。
的可能的複製(http://stackoverflow.com/questions/33666071/Android的棉花糖請求 - 許可) – Rohan