1
這是我的java代碼。如何測試Android M上的ActivityCompat.requestPermission?
public static void checkSinglePermissionCompat(final Activity activity,
ActionNeedsPermission action, final String permission,
final int permissionCode, String message) {
int hasPermission = ActivityCompat.checkSelfPermission(activity, permission);
if (hasPermission == PackageManager.PERMISSION_GRANTED) {
action.performAction();
} else {
if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
showRationaleDialog(activity, message,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
ActivityCompat.requestPermissions(activity, new String[]{permission}, permissionCode);
}
});
} else {
ActivityCompat.requestPermissions(activity, new String[]{permission}, permissionCode);
}
}
}
我gradle這個文件
android {
compileSdkVersion "android-MNC"
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion "MNC"
targetSdkVersion "MNC"
}
}
和我的清單文件
<uses-permission-sdk-m android:name="android.permission.CAMERA"/>
<uses-permission-sdk-m android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission-sdk-m android:name="android.permission.RECORD_AUDIO" />
<uses-permission-sdk-m android:name="android.permission.SEND_SMS" />
它只是回調拒絕的權限,並沒有表現出該系統的權限請求對話框。任何人都可以幫助我? THX