赋料扬雄敌,诗看子建亲。这篇文章主要讲述Android Studio 学习内容提供器相关的知识,希望能为你提供帮助。
运行时权限
- 使用ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.CALL_PHONE)!=PackageManager.PERMISSION_GRANTED//判断是否有权限
- ActivityCompat.requestPermissions(MainActivity.this,
new String[] {Manifest.permission.CALL_PHONE},1); //没有权限 进行申请 - onRequestPermissionResult() //无论哪种结果都会回调到这个函数中 所以重写这个函数
@Override
public void onClick(View view) {
if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.
permission.CALL_PHONE)!=PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(MainActivity.this,
new String[] {Manifest.permission.CALL_PHONE},1);
else
call();
}
});
private void call()
{
try{
Intent intent = new Intent (Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:10086"));
startActivity(intent);
}
catch (SecurityException e)
{
e.printStackTrace();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode){
case 1:
if(grantResults.length >
0 &
&
grantResults[0]== PackageManager.PERMISSION_GRANTED)
call();
else
Toast.makeText(MainActivity.this,"you denied thepermission",Toast.LENGTH_LONG).show();
break;
default:
}
}
}
查找联系人姓名和电话ListView contactsView = (ListView) findViewById(R.id.listview);
adapter = new ArrayAdapter
private void readContanct()
{
Cursor cursor = null;
try{
cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,null,null,null);
if(cursor != null)
while (cursor.moveToNext()){
String displayName = cursor.getString(cursor.getColumnIndex
(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String number =cursor.getColumnName(cursor.getColumnIndex
(ContactsContract.CommonDataKinds.Phone.NUMBER));
contactsList.add(number);
adapter.notifyDataSetChanged();
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally {
if(cursor!=null)
cursor.close();
}
}
推荐阅读
- HDU6405 Make ZYB Happy 广义sam
- 啥是腾讯qim?腾讯qim与tim有哪些区别?
- 微信门店小程序如何添加视频?门店小程序视频添加办法_微信
- 微信公众号图文历史版本在啥地方?_微信
- 微信6.5.10内测版有啥新技巧?微信6.5.10内测版新技巧介绍_微信
- freestyle啥梗?freestyle是啥意思?_其它聊天
- 微信读书电台是啥?微信读书电台怎样运用?_微信
- 微博故事怎样设置互动方式?微博故事互动方式设置办法_新浪微博
- 微信空白朋友圈怎样发?微信空白朋友圈运用图文详细教程_微信