私はandroid.intent.action.NEW_OUTGOING_CALLをキャッチするインテントフィルターを備えたBroadcastreceiverを持っています。
NEW_OUTGOING_CALL インテントの処理について多くのチュートリアルを読み、ここで回答しましたが、これを機能させることができませんでした。私の目標は、Broadcastreceiver が受信したインテント android.intent.action.NEW_OUTGOING_CALL をログに記録することです。この単純なことを機能させることができません。
これが私のコードです:
マニフェスト.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.vannus.broadcasttest">
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".TestReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>
これは、Broadcastreceiver (TestReceiver.java) のコードです。
package net.vannus.broadcasttest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class TestReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Log.w("###TEST###",intent.getAction());
}
}
プロジェクトには、機能のない空の MainActivity も含まれています。プロジェクトを実行すると、主なアクティビティは起動ですが、電話をかけたり受けたりしようとするとログが書き込まれません。エミュレーター (Android 7) と Motorola G4 電話 (Android 6.0) でコードをテストしましたが、logcat には何も記録されませんでした。Android Studio 2.3 を使用しています
私は何を間違っていますか?
ありがとう
ヴァンヌス