Jac*_*ień 10 android android-intent
我似乎缺乏处理这种意图的知识,但是暂时找不到答案.
我有一个片段的活动.片段执行此代码是为了调用联系人:
private void onCall() {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(contact.getBusinessPhone()));
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
还包括许可
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Run Code Online (Sandbox Code Playgroud)
输出是No Activity found to handle Intent和应用程序崩溃.
这是包含片段的活动的清单实现:
<activity android:name="activities.ContactActivity">
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我需要在清单中声明一些特殊活动吗?
Via*_*lav 66
您不需要在清单中声明拨号intent-filter,也不需要ACTION_DIAL的任何权限.寻找我的实施
private void startDialActivity(String phone){
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+phone));
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
也很好检查设备上支持的电话
private boolean isTelephonyEnabled(){
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
return telephonyManager != null && telephonyManager.getSimState()==TelephonyManager.SIM_STATE_READY;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18213 次 |
| 最近记录: |