0

I have looked into several similar questions on SO, tried all possible tweaks and changes after referring to countless tutorials, and answers in SO but my receiver is not being called on PHONE_STATE change.

I have already seen the answers here, here and here.

This is my AndroidManifest.xml file.

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
.....
<receiver android:name=".CustomReceivers.MissedCallReceiver" android:enabled="true">
    <intent-filter>
        <action android:name="android.intent.action.PHONE_STATE"/>
    </intent-filter>
</receiver>
.....

This is my BroadcastReceiver.

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class MissedCallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Toast.makeText(context, "Activated", Toast.LENGTH_SHORT).show();

    }}

There is absolutely no error being shown anywhere. I tried calling from another device while the application is active, still there seems to be no change.

Community
  • 1
  • 1
Tanishq Sharma
  • 538
  • 2
  • 14
  • Is the permission outside of the `` tags? Have you handled Marshmallow's new permissions model, if that applies? Have you launched your app at least once after installation to bring it out of the _stopped_ state? – Mike M. May 16 '16 at 15:15
  • Yes, permission is outside of the `` tags. Yes, I have launched the app at least once after installation. In-fact I have also tried calling on my device while the application was open. Marshmallow's new permission model? Could you provide me some documentation or reference? – Tanishq Sharma May 16 '16 at 15:19
  • 1
    If your `targetSdkVersion` is 23 or above, and you're running under API 23 or above, you have to request the `READ_PHONE_STATE` permission at runtime. [This post](http://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it) has some info and a link to the developer page on how to do that, as well as a temporary "fix" you can use to test your Receiver now without having to add a bunch of permissions code yet. – Mike M. May 16 '16 at 15:24
  • Oh thank-you so much. One little doubt, do I have to call for permissions everything this Broadcast Receiver is called? – Tanishq Sharma May 16 '16 at 15:27
  • You'll have to request the permission from one of your Activities, but once the user grants it to your app, it'll have that permission until the user revokes it, which can happen at any time. If your app doesn't have the permission when a broadcast of that type happens, your Receiver just won't run. If that permission is vital to your app's functionality, you should always check for it when your Activity runs, and prompt the user accordingly. – Mike M. May 16 '16 at 15:38
  • 1
    @MikeM. Thank-you so much for the help and references :) – Tanishq Sharma May 16 '16 at 15:48

0 Answers0