Android 如何为所有设备打开Autostart应用程序窗口?

Android 如何为所有设备打开Autostart应用程序窗口?,android,autostart,Android,Autostart,如何为所有设备打开Autostart应用程序窗口?AndroidManifest.xml以下代码: <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <receiver android:enabled="true" android:exported="true" android:name="yourpackage.BootReceiver" android:permiss

如何为所有设备打开Autostart应用程序窗口?

AndroidManifest.xml以下代码:

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

<receiver
android:enabled="true"
android:exported="true" 
android:name="yourpackage.BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

<intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

也许对你有帮助。祝你好运

下面的站点将为您提供有关Autostart的信息

以下代码将帮助您打开设置,为大多数手机启用自动启动

特别感谢和

在您的OnCreate()中

最好像下面的代码那样显示它,让用户理解为什么要启用它

 for (Intent intent : AUTO_START_INTENTS)
      if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
        new MaterialDialog.Builder(this).title("Enable AutoStart")
          .content(
            "Please allow App to always run in the background,else our services can't be accessed when you are in distress")
          .theme(Theme.LIGHT)
          .positiveText("ALLOW")
          .onPositive(new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
              try {
                for (Intent intent : AUTO_START_INTENTS)
                  if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                    startActivity(intent);
                    break;
                  }
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          })
          .show();
        break;
      } 
例如:


希望它可以帮助您。

您可以使用adb comment启动应用程序,但mbl应该是根目录。自动启动应用程序的
窗口是什么,你能编辑你的问题并提供更多信息吗?非常感谢@Sachin Varmacan samsung smart phones需要autostart许可吗?是的,需要一些samsung无监控应用程序(7.0+)我创建了一个具有前台服务的应用程序。我在vivo设备中安装了该应用程序,但它没有显示在autostart应用程序内部设置列表中。如何使我的应用程序出现在列表中?谢谢。它工作得很好@萨钦·瓦尔马
private static final Intent[] AUTO_START_INTENTS = {
    new Intent().setComponent(new ComponentName("com.samsung.android.lool",
      "com.samsung.android.sm.ui.battery.BatteryActivity")),
    new Intent("miui.intent.action.OP_AUTO_START").addCategory(Intent.CATEGORY_DEFAULT),
    new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")),
    new Intent().setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity")),
    new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")),
    new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")),
    new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.startupapp.StartupAppListActivity")),
    new Intent().setComponent(new ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity")),
    new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity")),
    new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager")),
    new Intent().setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")),
    new Intent().setComponent(new ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.entry.FunctionActivity")).setData(
      Uri.parse("mobilemanager://function/entry/AutoStart"))
  };
for (Intent intent : AUTO_START_INTENTS){
      if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
        startActivity(intent);
        break;
      }
   }
  }
 for (Intent intent : AUTO_START_INTENTS)
      if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
        new MaterialDialog.Builder(this).title("Enable AutoStart")
          .content(
            "Please allow App to always run in the background,else our services can't be accessed when you are in distress")
          .theme(Theme.LIGHT)
          .positiveText("ALLOW")
          .onPositive(new MaterialDialog.SingleButtonCallback() {
            @Override
            public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
              try {
                for (Intent intent : AUTO_START_INTENTS)
                  if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                    startActivity(intent);
                    break;
                  }
              } catch (Exception e) {
                e.printStackTrace();
              }
            }
          })
          .show();
        break;
      } 
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.savingyou.android.R;


public class ExampleActivity extends AppCompatActivity {

  private static final Intent[] AUTO_START_INTENTS = {
    new Intent().setComponent(new ComponentName("com.samsung.android.lool",
      "com.samsung.android.sm.ui.battery.BatteryActivity")),
    new Intent("miui.intent.action.OP_AUTO_START").addCategory(Intent.CATEGORY_DEFAULT),
    new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")),
    new Intent().setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity")),
    new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")),
    new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")),
    new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.startupapp.StartupAppListActivity")),
    new Intent().setComponent(new ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity")),
    new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity")),
    new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager")),
    new Intent().setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")),
    new Intent().setComponent(new ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.entry.FunctionActivity")).setData(
      Uri.parse("mobilemanager://function/entry/AutoStart"))
  };

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    for (Intent intent : AUTO_START_INTENTS){
      if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
        startActivity(intent);
        break;
      }
   }
  }
}