简体   繁体   中英

Broadcast Receiver onReceive() not work

events onRecive in Class Broadcast Receiver not work In manifest all ok, but I don't see Log info in android Monitor. How can i solve this problem? I check this problem by calling to my phone i use Xiaomi Redmi3s

Class CallReciver:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.telephony.TelephonyManager;
import android.util.Log;

public class CallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.v("tesat", "test");
    }
}

Mainfest:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="org.koshalogik.showcaller">

        <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

        <application
                android:allowBackup="true"
                android:icon="@drawable/belarus"
                android:label="@string/app_name"
                android:roundIcon="@mipmap/ic_launcher_round"
                android:supportsRtl="true"
                android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">

            </activity>

            <receiver android:name=".CallReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.PHONE_STATE"/>
                </intent-filter>
            </receiver>
        </application>
<activity
                android:name=".ContentActivity"
                android:label="@string/title_activity_content"
                android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

    </manifest>

Use this

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="org.koshalogik.showcaller">

        <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

        <application
                android:allowBackup="true"
                android:icon="@drawable/belarus"
                android:label="@string/app_name"
                android:roundIcon="@mipmap/ic_launcher_round"
                android:supportsRtl="true"
                android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">

            </activity>

            <receiver android:name=".CallReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.PHONE_STATE"/>
                </intent-filter>
            </receiver>

<activity
                android:name=".ContentActivity"
                android:label="@string/title_activity_content"
                android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        </application>
    </manifest>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM