7

For check screenshot and detail, click here

Please give related suggession or code for how to add automatic enable auto start for my app , please check here attached screen shot thanks in advance.

Karan sharma
  • 1,511
  • 1
  • 13
  • 37
Chirag Kheni
  • 184
  • 1
  • 8

3 Answers3

8

Try this...it's working for me. It will open the screen to enable autostart.

String manufacturer = "xiaomi";
        if(manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) {
            //this will open auto start screen where user can enable permission for your app
            Intent intent = new Intent();
            intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
            startActivity(intent);
        }
Mohit Mathur
  • 679
  • 8
  • 15
  • 3
    How to check if autostart permission already enabled or not. This code always open autostart permission screen . I want to show this screen only when app is not enabled for autostart. – Ved Feb 22 '17 at 11:16
  • @ved I am also searching for the same... moreover, this code is not able to find the particular activity in some MI phones. I am still searching for the code which will eliminate this issue. – Mohit Mathur Feb 24 '17 at 04:28
  • Guys are you find any solution? – Bhavin Patel Apr 29 '17 at 10:40
  • How to find in which phone need to do auto-start code? Means I know In **MI device** it is required for auto-start But don't know about others . – Bhavin Patel Apr 29 '17 at 10:40
0

Few OEMs including (RedMi) customizes the stack ROM for battery/memory optimization and have blocked the "onDestroy()" and "onTaskRemoved" callbacks. As an user you can prevent the App's service from killing by locking the App. Or, White listing the app by enabling "Autostart" setting for the App. Programmatically you can prompt the user to enable the Autostart for the App Please find details here

Please note: I have tested the Autostart enabling programatically on few devices but found that it does not works always. Please check above link to see the possible options.

Akki
  • 775
  • 8
  • 19
-4

First of all you need a permission at the manifest:

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

Still in manifest you need to add a brodcast receiver within your

<application>

element:

<receiver android:name="net.example.MyOwnBroadcastReceiver">  
<intent-filter>  
    <action android:name="android.intent.action.BOOT_COMPLETED" />  
</intent-filter>  

after that in your Class "MyOwnBroadcastReceiver"

package net.example;

public class MyOwnBroadcastreceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent startServiceIntent = new Intent(context, MyService.class);
        context.startService(startServiceIntent);
    }
}

You can get more help on the following links:

http://blog.gregfiumara.com/archives/82

http://techblogon.com/android-start-service-on-boot/

mcd
  • 106
  • 2
  • 10