简体   繁体   English

Android Studio中的清单权限

[英]Manifest permission in Android Studio

I want to know if I can add permissions to the Manifest in Android Studio in the same way as in eclipse. 我想知道我是否可以像在eclipse中一样向Android Studio中的Manifest添加权限。 What I mean is the permission tab that is generating for you automatically instead of putting it manually. 我的意思是自动生成的权限选项卡,而不是手动生成。

The Question here is if there is an option that makes it automatically instead of adding it manually! 这里的问题是,如果有一个选项自动生成而不是手动添加它!

Yes you can definitely do it manually. 是的,你绝对可以手动完成。 In fact, using the Studio is better for newbies since it avoids errors to certain extent! 事实上,使用Studio对于新手更好,因为它在一定程度上避免了错误!

EDIT: You can only type them manually, but the content assist helps you there, so it is pretty easy. 编辑:你只能手动输入,但内容辅助可以帮助你,所以这很容易。

Add this line 添加此行

<uses-permission android:name="android.permission."/> 

and hit ctrl + space after the dot (or cmd + space on Mac). 点击后按ctrl + space (或Mac上的cmd +空格 )。 If you need an explanation for the permission, you can hit ctrl + q . 如果您需要有关权限的说明,可以按ctrl + q

Reference: Here 参考: 这里

If you just type < in the usual place (below the manifest element at the top), you'll get a menu of options to choose from, including uses-permission . 如果您只是在通常位置(在顶部的清单元素下方)键入< ,您将获得一个可供选择的选项菜单,包括uses-permission Select it, and Studio will put the whole element there, and show a menu of permissions from which to choose. 选择它,Studio将把整个元素放在那里,并显示一个可供选择的权限菜单。

This is the format for using the manifest permission manually Add your needed permission instead of MODIFY_PHONE_STATE 这是手动使用清单权限的格式添加所需的权限而不是MODIFY_PHONE_STATE

HERE IS THE CODE 这是代码

int permissionCheck = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.MODIFY_PHONE_STATE);

    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(MainActivity.this, "permissions denied", Toast.LENGTH_LONG).show();
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.MODIFY_PHONE_STATE}, PERMISSIONS_REQUEST_CODE);
        Toast.makeText(MainActivity.this, "happen", Toast.LENGTH_LONG).show();
    } else {
        //TODO
        Toast.makeText(MainActivity.this, "permissions granted", Toast.LENGTH_LONG).show();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM