-1
我想在Android中編寫一些可以檢測電話號碼和狀態的代碼。在Android中拒絕撥打電話號碼
所以當一個特定的號碼正在呼叫(比如123456789)時,應用會拒絕該號碼並結束通話。我該怎麼辦?
public class ReciveCalls extends BroadcastReceiver {
public void onReceive(Context context, Intent intent){
if(intent.getAction().equals("android.intent.action.PHONE_STATE")){
String state=intent.getStringExtra(TelephonyManager.EXTRA_STATE);
String Number=intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast toast=Toast.makeText(context,"Number:"+Number+",state:"+state,Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP|Gravity.LEFT,3,0);
toast.show();
}
}
}
清單:
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>