着信時に着信画面(デフォルト、着信時は通常通り)の起動を止めたい。その代わりに、自分のアクティビティを起動して応答したいと考えています。
誰でも私を助けてください。ありがとう
着信時に着信画面(デフォルト、着信時は通常通り)の起動を止めたい。その代わりに、自分のアクティビティを起動して応答したいと考えています。
誰でも私を助けてください。ありがとう
最初にBroadcastReceiverのサブクラスを作成します
public class CallReceiver extends BroadcastReceiver {
マニフェスト.xmlファイルに追加します
<receiver android:name="com.myapp.calldropper.CallReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
onReceiveで、デフォルトで別のアクティビティ画面を開始します
Intent callRejectIntent = new Intent(context, MainActivity.class);
callRejectIntent.putExtra("MOBILE_NUMBER", mobNum);
callRejectIntent.putExtra("REJECT_COUNT", rejectCount);
callRejectIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(callRejectIntent);
アクティビティはデフォルトのアクティビティで起動します。これで、アクティビティからの着信に応答でき、通話を拒否できます。
そのために、という名前の別のパッケージをcom.android.internal.telephony
作成し、この中に。という名前の単純なテキストファイルを作成しますITelephony.aidl
。このファイルには
package com.android.internal.telephony;
import android.os.Bundle;
interface ITelephony {
boolean endCall();
void dial(String number);
void answerRingingCall();
}
onCreateに以下のコードを追加します
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
try {
// "cheat" with Java reflection to gain access to TelephonyManager's ITelephony getter
Class<?> c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(tm);
} catch (Exception e) {
e.printStackTrace();
}
これで、以下の関数を呼び出すことで呼び出しを拒否できます
private void ignoreCall() {
try {
// telephonyService.silenceRinger();
telephonyService.endCall();
} catch (RemoteException e) {
e.printStackTrace();
}
moveTaskToBack(true);
finish();
}