roiberg
roiberg

Reputation: 13737

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!

Upvotes: 0

Views: 2479

Answers (2)

Erol
Erol

Reputation: 6526

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.

Upvotes: 1

Kaediil
Kaediil

Reputation: 5535

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+

Upvotes: 0

Related Questions