我有一个 BroadcastReceiver,我知道如何拒绝来电。但是当我按下后退按钮时,我需要帮助拒绝来电,因为我的代码中有某种错误......
public class CallReceiveD extends BroadcastReceiver {
private ITelephony telephonyService;
public String phoneNumber;
public Bundle extras;
public TelephonyManager tm;
public Intent i;
@Override
public void onReceive(Context context, Intent intent) {
i=intent;
extras = intent.getExtras();
if (extras != null)
{
String state = extras.getString(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast toast= Toast.makeText(context,phoneNumber, Toast.LENGTH_LONG);toast.show();
tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(tm);
// telephonyService.endCall();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
//@Override
public void onBackPressed() {
telephonyService.endCall();
return;
}
}
我的清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="denza12Des.call"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".Call2BackActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".CallReceiveD">
<intent-filter android:priority="99999">
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>