指定Action、Category调用系统Activity,显示联系人、拨打电话等。
时间: 2023-07-10 18:14:14 浏览: 66
可以通过指定 Action 和 Category 来调用系统的 Activity,例如显示联系人、拨打电话等。下面是具体实现步骤:
1. 显示联系人列表:
```
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setData(ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, REQUEST_SELECT_CONTACT);
```
`ACTION_PICK` 表示选择一个数据项,`ContactsContract.Contacts.CONTENT_URI` 表示选择联系人数据项。
2. 拨打电话:
```
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:10086"));
startActivity(intent);
```
`ACTION_CALL` 表示拨打电话,`tel:10086` 表示要拨打的电话号码。
需要注意的是,对于一些敏感的操作,如拨打电话、发送短信等,需要在 AndroidManifest.xml 文件中声明相应的权限。例如:
```
<uses-permission android:name="android.permission.CALL_PHONE"/>
```
这样才能在运行时正常执行相应的操作。