0

I know this question is similar to many questions of BroadcastReceiver but as I read, non of them have solutions. the tutorial of BroadcastReceiver tells it will work even app was not running in the background, my question is why I can not use it when app is not running I tried to call broadcast from main activity, use service and .... but non of them solved my problem.

here is my CODE:

MyReceiver java Class:

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context,"BroadCast Trigger",Toast.LENGTH_SHORT).show();
    }
 }

Also MyManifest Code:

<receiver
    android:name=".MyReceiver"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="android.media.VOLUME_CHANGED_ACTION" />
    </intent-filter>
</receiver>
Phantômaxx
  • 36,442
  • 21
  • 78
  • 108

2 Answers2

0

As I found there is no way to active BroadcastReceiver in Huawei Devices programmatically, but here is a solution to find device type and do needed action in this regard such as show an alert to user to activate it manually.

        if ("huawei".equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
        // Do Needed Action
    }
0

I faced with same problem on Huawey Honor with Android 7. On Sony and ZTE devices BroadcastReceiver works as expected. But on Honor it work some time and suddenly stop. I discover, that problem not related with re-boot. I reboot device and broadcast receiver work after it. But sometimes, it stop without rebooting.

First i add my app to protected list according this solution: "Protected Apps" setting on Huawei phones, and how to handle it

But it didn't help :(

Then, i add a fake accessibility service to my app, according to this recommendation: Broadcast Receiver Not Working After Device Reboot in Android

And problem was solved!

Anton Ganichev
  • 1,036
  • 10
  • 12
  • Welcome to Stack Overflow! While links are great way of sharing knowledge, they won't really answer the question if they get broken in the future. Add to your answer the essential content of the link which answers the question. In case the content is too complex or too big to fit here, describe the general idea of the proposed solution. Remember to always keep a link reference to the original solution's website. See: [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – sɐunıɔןɐqɐp Jun 18 '18 at 07:26