如何在MI 4i安全APP中以编程方式为我的应用程序启用自动启动选项?

Chi*_*eni 7 android autostart android-manifest android-service

有关屏幕截图和详细信息,请单击此处

请提供相关的建议或代码,了解如何为我的应用程序添加自动启用自动启动,请在此处查看附带的屏幕截图.

Moh*_*hur 8

试试这个...它对我有用.它将打开屏幕以启用自动启动.

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)

  • 如何检查是否已启用自动启动权限.此代码始终打开自动启动权限屏幕.我想仅在app未启用自动启动时显示此屏幕. (3认同)

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/