简体   繁体   English

在Android 6.0中请求权限(API级别23)

[英]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.

相关问题 Android API 23请求多个权限 - Android API 23 Requesting Multiple Permissions Android 6.0中的Android运行时权限(API级别23)最佳做法 - Android Run time Permissions in Android 6.0 (API level 23) best practices 在Android API级别> = 23中获得了事件处理权限 - Permissions obtained Event Handling in Android API level >=23 在Android 6.0(SDK 23)中检查自定义权限 - Checking custom permissions in Android 6.0 (sdk 23) 如果不需要Android 6.0 API 23中的功能,是否需要考虑运行时权限? - If I do not need features from Android 6.0 API 23, do I have to care about runtime permissions? 如何以编程方式更改 Android 中保存的 wifi 网络的密码(API 级别 23,Android 6.0) - How to programmatically change password of a saved wifi network in Android (API level 23, Android 6.0) 使用Android 6.0(API LEVEL 23)消耗休息的最佳方法是什么 - What is the best way to consume rest using Android 6.0(API LEVEL 23) 应用程序如何在没有root的情况下访问Android 6.0(API级别23)中的USB OTG存储上的文件? - How app can access files on USB OTG storages in Android 6.0 (API level 23) without root? 在Android 6.0 API 23中未调用onLocationChanged - onLocationChanged not called in Android 6.0 API 23 Android 应用程序在 Android 6.0(API 级别 23)上崩溃:android.support.v4.content.res.ComplexColorCompat.isStateful() - Android app is getting a crash on Android 6.0 (API level 23): android.support.v4.content.res.ComplexColorCompat.isStateful()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM