小编Mer*_*ins的帖子

我应该如何将 android 权限用于相机和外部存储

我在我的应用程序中有两个权限,它们基于访问相机外部存储,但我面临的问题是,当应用程序启动时只要求相机权限,而不要求其他权限。

但是在第二阶段,当我运行应用程序时,它询问了第二个权限。

public class MainActivity extends AppCompatActivity {

private DrawerLayout mDrawer;
private Toolbar toolbar;
private NavigationView nvDrawer;
private ActionBarDrawerToggle drawerToggle;

private static final int REQUEST_CAMERA = 0;
private static final int REQUEST_EXTERNAL_STORAGE = 1;

private static String[] PERMISSION_EXTERNAL = {Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_EXTERNAL_STORAGE};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.CAMERA) !=
            PackageManager.PERMISSION_GRANTED) {

        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.CAMERA)) {
            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's …
Run Code Online (Sandbox Code Playgroud)

android android-permissions

5
推荐指数
1
解决办法
5085
查看次数

标签 统计

android ×1

android-permissions ×1