【发布时间】:2014-12-15 08:03:10
【问题描述】:
我正在尝试使用 ACTION_CALL 意图来调用 USSD 代码。我已将 android.permission.PHONE_CALL 添加到清单文件中,但它不起作用并获得权限错误异常。 PS:如您所见,GPS 和 INTERNET 也有权限,它们工作正常。 以下是代码:
public void onClick(View v) {
String encodedHash = Uri.encode("#");
String number = "*140*1";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setPackage("com.android.phone");
intent.setData(Uri.parse("tel:" + number + encodedHash));
try{
startActivity(intent);
} catch(Exception ex){
Toast.makeText(getApplication(), ex.toString(), Toast.LENGTH_LONG).show();
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.PHONE_CALL" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity .......
【问题讨论】:
-
有什么异常?在此处添加日志
-
权限是
android.permission.CALL_PHONE,不是android.permission.PHONE_CALL。
标签: android permissions call