Chi*_*eni 7 android autostart android-manifest android-service
请提供相关的建议或代码,了解如何为我的应用程序添加自动启用自动启动,请在此处查看附带的屏幕截图.
试试这个...它对我有用.它将打开屏幕以启用自动启动.
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);
}
Run Code Online (Sandbox Code Playgroud)
mcd*_*mcd -4
首先,您需要清单上的许可:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Run Code Online (Sandbox Code Playgroud)
仍然在清单中,您需要在您的
<application>
Run Code Online (Sandbox Code Playgroud)
元素:
<receiver android:name="net.example.MyOwnBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
之后在您的“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);
}
}
Run Code Online (Sandbox Code Playgroud)
您可以通过以下链接获得更多帮助:
http://blog.gregfiumara.com/archives/82
http://techblogon.com/android-start-service-on-boot/