继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Android运行时权限使用

慕运维2858188
关注TA
已关注
手记 123
粉丝 63
获赞 512
9大组需要适配的权限

//通讯录权限组
group:android.permission-group.CONTACTS
permission:android.permission.WRITE_CONTACTS
permission:android.permission.GET_ACCOUNTS
permission:android.permission.READ_CONTACTS

//通话权限组
group:android.permission-group.PHONE
permission:android.permission.READ_CALL_LOG
permission:android.permission.READ_PHONE_STATE
permission:android.permission.CALL_PHONE
permission:android.permission.WRITE_CALL_LOG
permission:android.permission.USE_SIP
permission:android.permission.PROCESS_OUTGOING_CALLS
permission:com.android.voicemail.permission.ADD_VOICEMAIL

//日历、日程信息权限组
group:android.permission-group.CALENDAR
permission:android.permission.READ_CALENDAR
permission:android.permission.WRITE_CALENDAR

//摄像头权限组
group:android.permission-group.CAMERA
permission:android.permission.CAMERA

//身体传感器权限组
group:android.permission-group.SENSORS
permission:android.permission.BODY_SENSORS

//定位权限组
group:android.permission-group.LOCATION
permission:android.permission.ACCESS_FINE_LOCATION
permission:android.permission.ACCESS_COARSE_LOCATION

//外部存储卡权限组
group:android.permission-group.STORAGE
permission:android.permission.READ_EXTERNAL_STORAGE
permission:android.permission.WRITE_EXTERNAL_STORAGE

//录音权限组
group:android.permission-group.MICROPHONE
permission:android.permission.RECORD_AUDIO

//短信权限组
group:android.permission-group.SMS
permission:android.permission.READ_SMS
permission:android.permission.RECEIVE_WAP_PUSH
permission:android.permission.RECEIVE_MMS
permission:android.permission.RECEIVE_SMS
permission:android.permission.SEND_SMS
permission:android.permission.READ_CELL_BROADCASTS

框架

https://github.com/Vanish136/RTPermission

使用
public class MainActivity extends AppCompatActivity implements View.OnClickListener, OnPermissionResultListener
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.btn_main01).setOnClickListener(this);
        findViewById(R.id.btn_main02).setOnClickListener(this);

    }

    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
            case R.id.btn_main01:
                new RTPermission.Builder()
                        .permissions(Manifest.permission.BODY_SENSORS)
                        .start(this, this);
                break;
            case R.id.btn_main02:
                new RTPermission.Builder()
                        .permissions(Manifest.permission.WRITE_EXTERNAL_STORAGE
                                , Manifest.permission.READ_EXTERNAL_STORAGE
                                , Manifest.permission.RECORD_AUDIO
                                , Manifest.permission.CAMERA
                                , Manifest.permission.ACCESS_FINE_LOCATION)
                        .start(this, this);
                break;
        }
    }

    @Override
    public void onAllGranted(String[] allPermissions)
    {
        Toast.makeText(MainActivity.this, "所有权限都已通过", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onDeined(String[] dinedPermissions)
    {
        Toast.makeText(MainActivity.this, "无法获取所有权限", Toast.LENGTH_SHORT).show();
    }
}
打开App,阅读手记
4人推荐
发表评论
随时随地看视频慕课网APP