私はアンドロイド用のプログラムを書こうとしています。プログラムで電話をかけたいのですが、その後、電話の状態を認識します。フロー機能を使用すると、ハングアウトステータスを認識できますが、ステータスに応答する場合は機能しません。この機能を試してみましたが、どちらも機能しません。
「通話が終了」する前に「通話が受け入れられました」を検出したい。
public class OutgoingCallReceiver extends BroadcastReceiver {
protected static final String CLASS_TAG = "OutgoingCallReceiver : ";
private static final String LOG_TAG = "MyActivity";
private ConnectivityManager connectivityManager;
private TelephonyManager telephonyManager;
private NetworkInfo networkInfo;
private String networkStauts = "Not connected !!";
//************************************
@Override
public void onReceive(Context context, Intent intent) {
//Toast.makeText(getApplicationContext(),String.valueOf(isPhoneCalling), Toast.LENGTH_SHORT).show();
Bundle bundle = intent.getExtras();
if(null == bundle) return;
String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
//Log.i(LOG_TAG, CLASS_TAG + "phone number " + phonenumber);
//Toast.makeText(getApplicationContext(),String.valueOf("phone number " + phonenumber), Toast.LENGTH_SHORT).show();
tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Context context = getApplicationContext();
Toast.makeText(getApplicationContext(), "RINGING", Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Toast.makeText(getApplicationContext(), "OFFHOOK", Toast.LENGTH_SHORT).show();
isPhoneCalling = true;
break;
case TelephonyManager. CALL_STATE_IDLE:
if (isPhoneCalling) {
Toast.makeText(getApplicationContext(),
"Your call is disconnected by receiver", 10000)
.show();
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
isPhoneCalling = false;
//duration=c.getLong(c.getColumnIndex(CallLog.Calls.DURATION));
Toast.makeText(getApplicationContext(), "IDLE", Toast.LENGTH_SHORT).show();
call();
}
break;
default:
Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show();
//Log.d(LOG_TAG, CLASS_TAG + "Default: " + state);
break;
}
}
}, PhoneStateListener.LISTEN_CALL_STATE )
//registerReceiver(phoneInfo, new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL));
}
}