-1

In an application, I am trying to implement a service which needs to run every time when device boot process completed. Application unable to broadcast service only in MI devices.

Manifest.xml

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

BroadcastReceiver

public class SavedLocationBroadcast extends WakefulBroadcastReceiver {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onReceive(Context context, Intent intent) {
    App.showToast(context,"BROADCAST","SEND");
        Intent service = new Intent(App.getContext(), MyLocationService.class);
        startWakefulService(App.getContext(), service);

}}

Reciever in manifest

 <receiver android:name="com.geolocation.broadcastreciever.SavedLocationBroadcast">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.geolocation.app.ACTION_PULSE_SERVER_ALARM" />
        </intent-filter>
    </receiver>

Please share your suggestion is anything wrong in implementation.

asb14690
  • 1,757
  • 3
  • 15
  • 21
  • Have you added your app to the list of apps that allowed to "run in the background"? On many devices, including most Xiaomi devices, Android will not automatically start apps that are not in the list of "protected apps" or "apps allowed to run in the background". – David Wasser Mar 18 '18 at 19:15

1 Answers1

0

This is solution for your bug.

What you need to do is that , you need to mention this permission also in your Intent-Filter.

 <receiver android:name="com.geolocation.broadcastreciever.SavedLocationBroadcast"
                 android:enabled="true"
                 android:exported="true" >

       <intent-filter >
               <action android:name="android.intent.action.BOOT_COMPLETED"/>
               <action android:name="android.intent.action.REBOOT"/>
       </intent-filter>
       </receiver>

Here you need to do one thing also.

Go to "Settings-Apps_open your app info-Manage permisson" in yourdevice

Here check all things here.

Because for some devices it will not work. Ex.Red mi

Try this !

matin sayyad
  • 575
  • 3
  • 10