简体   繁体   English

如何在没有用户许可的情况下自动自动启动android应用?

[英]How to autostart android app automatically without user permission?

I want to use background service in android . 我想在android中使用后台服务。 For that i have used background service, foreground service and job scheduler as well. 为此,我使用了后台服务,前台服务和作业计划程序。 But my app doesn't work in background without auto start option enabled. 但是,如果未启用自动启动选项,我的应用程序将无法在后台运行。

I have added background , foreground services and job scheduler also. 我还添加了background,前台服务和Job Scheduler。 I have added code to redirect the user to autostart setting enable. 我添加了代码以将用户重定向到自动启动设置启用。 As i have seen in many apps they won't ask user for the permission to enable autostart (ex. whatsapp, flipkart). 正如我在许多应用程序中看到的那样,他们不会要求用户启用自动启动功能(例如whatsapp,flipkart)。

    private void scheduleJob() {
    ComponentName componentName = new ComponentName(this, MyJobService.class);
 JobInfo jobInfo = new JobInfo.Builder(123, componentName)
                    .setRequiredNetworkType(JobInfo.NETWORK_TYPE_NONE)
    //                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
                    .setPersisted(true) // job alive even if we reboot
    //                .setPeriodic(15 * 60 * 1000) // 15 mins
                    .setPeriodic(5 * 1000) // 5 secs
                    .build();
            JobScheduler jobScheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
            int resultCode = jobScheduler.schedule(jobInfo);

            if (resultCode == JobScheduler.RESULT_SUCCESS) {
                Log.e(TAG, "Job Scheduled");
            } else {
                Log.e(TAG, "Job Scheduling failed");
            }

My app doesn't work in background without auto start option enabled. 如果未启用自动启动选项,我的应用程序将无法在后台运行。 I want it enabled automatically. 我希望它自动启用。 Autostart enables automatically when you install app 安装应用程序时自动启动自动启动

Okay to implement that create a sticky service and register that in your main activity and on boot completed you should refresh your service whenever you need to restart the application just refresh your service and either create a notification or just refresh your service which this code: 可以实现创建粘性服务并在您的主要活动中进行注册,并在启动完成后进行注册,只要需要重新启动应用程序,就应该刷新服务,只需刷新服务并创建通知或刷新服务即可,此代码如下:

public static Boolean RestartApp1(Activity activity) {
    if (!GlobalData.checkAndRequestPermissions(activity)) {
        Intent i = activity.getBaseContext().getPackageManager().getLaunchIntentForPackage(activity.getBaseContext().getPackageName());
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.startActivity(i);

        return false;
    } else {
        return true;
    }
}


if (GlobalData.RestartApp1(activity)) {
        getSharedData();
        findViews();
        initViews();
        setActionBarSDK();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何自动启动系统应用程序? - How to autostart a system app automatically? 如何自动启动而不需要在Android中以编程方式自动启动 - How To AutoStart automatically without open setting in android programatically 在android中安装应用程序后如何自动启动应用程序? - How to autostart app after install app in android? 如何在没有 Google Play 或用户交互的情况下自动更新 Android 应用程序 - How to update android app automatically without Google Play or user interaction 如何自动打开应用程序,而无需用户采取行动就收到Android上的推送 - How to automatically Open the app without user action on receiving a push on Android 如何在flutter中自动更新android应用程序而无需用户交互 - How to update android app automatically without user interaction in flutter 如何允许自动启动权限,例如用于离子应用程序的whatapp应用程序 - how to allow autostart permission like whatapp app for ionic application 如何在 android studio 上以编程方式检查自动启动权限是启用还是禁用 - how to check Programmatically AutoStart Permission is Enable or disable on android studio 无需用户交互即可自动更新 APP ==> Permission Denial: not allowed to send broadcast android.intent.action.PACKAGE_ADDED - Update APP automatically without user interaction facing issue==> Permission Denial: not allowed to send broadcast android.intent.action.PACKAGE_ADDED Android应用自动启动 - Android app autostart
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM