着信の検出に問題があります。多くのチュートリアルを試しましたが、うまくいきません。どこが間違っているのか本当にわかりません。
アクセス許可 READ_PHONE_STATE を追加しましたが、まだ Android デバイス モニターに次の警告が表示されます (呼び出し時):
Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to com.development.test.rejectcall/.background.IncomingCall requires android.permission.READ_PRIVILEGED_PHONE_STATE due to sender android (uid 1000)
Permission Denial: receiving Intent { act=android.intent.action.PHONE_STATE flg=0x10 (has extras) } to com.development.test.rejectcall/.background.IncomingCall requires android.permission.READ_PHONE_STATE due to sender android (uid 1000)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.development.test.rejectcall">
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
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=".background.IncomingCall">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>
着信コール.java
package com.development.test.rejectcall.background;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class IncomingCall extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Phone state call hook", Toast.LENGTH_LONG).show();
Log.d("mujlog", "phoneNumber received");
}
}
MainActivity.java
package com.development.test.rejectcall;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("mujlog", "Created");
Toast.makeText(this, "started", Toast.LENGTH_LONG).show();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}