Search code examples
androidbroadcastreceiverphone-state-listener

BroadcastReceiver dont catch the phone state


I am trying to start a new app, but i need to know about a change in the phone state... for some reason (i am new to this) i cant catch the broadcast of the change. thats my code:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Log.d("TAG","yyyyyyyyyyyy");
}
}

and thats my manifest:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <receiver
        android:name=".MyReceiver">
         <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE"/>
        </intent-filter>
    </receiver>
</application>

as you can see... very simple. but i cant see the Log in the onReceive on my LogCat. any one knows why? Thanks!


Solution

  • Due to this and this, your BroadcastReceiver won't receive anything. The solution is to design a simple activity for your app that starts at least once after installation, before it starts receiving.