[英]Requesting permissions in Android 6.0 (API level 23)
Is it necessary that requesting each dangerous permission it needs while the app is running Android 6.0 or higher?I have requested the following dangerous permissions,but there are only four dialogs. 当应用运行Android 6.0或更高版本时,是否有必要请求每个危险权限?我已经请求了以下危险权限,但是只有四个对话框。
The premissions 前提条件
public static final String[] PERMISSIONS = new String[]{
android.Manifest.permission.CALL_PHONE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.READ_PHONE_STATE,
android.Manifest.permission.WRITE_SETTINGS,
android.Manifest.permission.GET_ACCOUNTS,
android.Manifest.permission.CAMERA
};
The dialogs 对话框
1.Allow the app to make and manage phone calls? 1.是否允许该应用拨打和管理电话?
2.Allow the app to access photos,media,and files on your device? 2.允许该应用访问您设备上的照片,媒体和文件吗?
3.Allow the app to access this device's location? 3.允许应用访问此设备的位置吗?
4.Allow the app to access your contacts? 4.允许应用访问您的联系人吗?
I cant get the permissions such as android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.WRITE_SETTINGS, android.Manifest.permission.GET_ACCOUNTS, android.Manifest.permission.CAMERA,neither code nor system setting. 我无法获得权限,例如android.Manifest.permission.READ_PHONE_STATE,android.Manifest.permission.WRITE_SETTINGS,android.Manifest.permission.GET_ACCOUNTS,android.Manifest.permission.CAMERA,代码或系统设置。
Special Permissions 特殊权限
There are a couple of permissions that don't behave like normal and dangerous permissions.
有一些权限的行为与正常和危险的权限不同。 WRITE_SETTINGS is particularly sensitive, so most apps should not use them.
WRITE_SETTINGS特别敏感,因此大多数应用程序不应使用它们。 If an app needs one of these permissions, it must declare the permission in the manifest, and send an intent requesting the user's authorization.
如果应用程序需要这些权限之一,则它必须在清单中声明该权限,并发送请求用户授权的意图。 The system responds to the intent by showing a detailed management screen to the user.
系统通过向用户显示详细的管理屏幕来响应此意图。
Demo 演示版
public class MainActivity extends AppCompatActivity {
Context context;
TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
textView = (TextView) findViewById(R.id.foodName);
textView.setText(getResources().getText(R.string.txt_name));
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean result = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
result = Settings.System.canWrite(context);
Log.d("TAG", "Can Write Settings: " + result);
if (result) {
Toast.makeText(context, "Write allowed :-)", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Write not allowed :-(", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + context.getPackageName()));
startActivity(intent);
}
}
}
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.