私はSMSアプリケーションを持っています。 今私はlink hereから得たこのコードを持っています。アクセス許可が付与されているかどうかをアプリにチェックさせる方法(6、x +)
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.
}
}
しかし、私はアセスを拒否(ユーザーが誤ってボタンを押した場合)何もかもはかなり(原因SMSボタンが仕事を文句を言わない)アプリのクラッシュを行います。だから、ユーザがアクセスを拒否した後に、ユーザがアプリケーションを起動/再起動したとき、私はアプリに再び尋ねることを望みます。私のエミュレータを試してみたら、ダイアログが現れず、設定/アプリケーションにアクセスしてパーミッションを設定しなければなりませんでした。または、アンインストールして再度インストールしてください。
可能な複製(http://stackoverflow.com/questions [Androidのマシュマロ要求許可?]/33666071/android-marshmallow-request-permission) – Rohan