I can block incoming calls in android, but the problems that it rings for a split second before the time is turned off. How can I directly turn off the phone without a single call?
I added permission to the Manifest file:
<uses-permission android:name="android.permission.READ_CONTACTS"/> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"></uses-permission> <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission> <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> <uses-feature android:name="android.hardware.telephony" />
Then create an IDL interface to get the basic telephony service.
package com.android.internal.telephony; interface ITelephony { boolean endCall(); void answerRingingCall(); void silenceRinger(); }
Then a broadcast receiver was made for the incoming call.
public class PhonecallReceiver extends BroadcastReceiver { Context context = null; @Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "Receving call..."); TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); try { Class c = Class.forName(telephony.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); ITelephony telephonyService = (ITelephony) m.invoke(telephony); Bundle b = intent.getExtras(); String incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); telephonyService.endCall(); }catch (Exception e){ e.printStackTrace(); }}
source share