Question

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!

Was it helpful?

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.

OTHER TIPS

In order for a Manifest based Broadcast Receiver to get registered, you need to run your app by opening it from the app drawer. If you don't do that, then the receiver will not be called by Android. So basically, you need at least one Activity that can start - it does not have to do anything, it just has to be started at least once. Did you do that?

This is true after Android 3.0+

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top