1

I want get boot complete event because I want to call service after device is restarted. and I not got any solution. and I want to call service implicitly without open my app. My service working fine if at least once app open manually(when service calling from main activity).

Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.bitsend.swipescreen"
    android:installLocation="internalOnly">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name=".ScreenStatusService"></service>

        <receiver
            android:name=".BootReceiver"
            android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

BootReceiver.java

public class BootReceiver extends BroadcastReceiver
{
    public void onReceive(Context context, Intent intent)
    {
        // Your code to execute when Boot Completd
        String action =intent.getAction();
        if(action.equals(Intent.ACTION_BOOT_COMPLETED))
        {
        Intent service = new Intent(context, ScreenStatusService.class);
        context.startService(service);

        }
    }
}
  • 1
    Since version 3.1, your Receiver won't be delivered that broadcast until some component of your app is explicitly started - e.g., the user opens the app - at least once after installation. There's nothing you can do about that. – Mike M. Oct 14 '17 at 07:28
  • Which device you tested on? There are known issues with Mi, Ippo, Vivo devices. – Aswin P Ashok Oct 14 '17 at 07:48
  • i have tested on gionee p7 max – anil chamar Oct 14 '17 at 07:51
  • [Mike M.](https://stackoverflow.com/users/2850651/mike-m) is right, but you can try to make your app system. Take a look at [this](https://stackoverflow.com/a/26783739/6950238) answer. – Andrii Omelchenko Oct 14 '17 at 08:03
  • thanks, but i don't want to make my app as system app. @AndriiOmelchenko – anil chamar Oct 14 '17 at 08:55
  • Does it have some kind of security app with an autostart manager? If it has, may be your app is disabled (it won't trigger bootBroadcast). – Aswin P Ashok Oct 14 '17 at 11:04

0 Answers0