我想阻止Android使用此方法的传入呼叫,但通过 这种异常。我已经尝试了这么多的方法,但未能中止来电,请帮助这个代码的问题。我还在com.android.internal.telephony.ITelephony中添加了ITelephony接口。在Android异常来电阻止
异常
String Messageofenemy;
String Blckno;
public OutgoingReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
try {
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(context, MyService.class);
context.startService(i);
return;
}
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
//outgoing call code here
} else {
//get the phone state
String newPhoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE) ?
intent.getStringExtra(TelephonyManager.EXTRA_STATE) : null;
Bundle bundle = intent.getExtras();
if (newPhoneState != null &&
newPhoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
//read the incoming call number
String phoneNumber =
bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
db = new DatabaseHelper(context);
Cursor res = db.getAllrows();
if (res.getCount() == 0) {
} else {
while (res.moveToNext()) {
Blckno = res.getString(0);
}
}
if (phoneNumber.equals("03352264769")) {
try {
AudioManager am =
(AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
am.setRingerMode(AudioManager.RINGER_MODE_SILENT);
ITelephony telephonyService;
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
telephonyService.endCall();
} catch (Exception e) {
Toast.makeText(ctx, "Exception" + String.valueOf(e),
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(context, "Exception is " + String.valueOf(e),
Toast.LENGTH_LONG).show();
}
}
}
}
} catch (Exception ex) {
Toast.makeText(context, "Error is " + String.valueOf(ex),
Toast.LENGTH_LONG).show();
}
}
}
请格式化您的代码 – Jens
我已格式化请检查。 – DumpsterDiver
看起来像'context'为空 – Jens