简体   繁体   English

Android BOOT_COMPLETED事件无法启动服务

[英]Android BOOT_COMPLETED event not starting service

I am writing a small android application which starts my service upon device boot. 我正在编写一个小的Android应用程序,它在设备启动时启动我的服务。 Application is working fine on all the mobiles with Android versions 4.4.2 (Mi Note 4G, have to enable permissions in their security app), 5.0 (Lenovo K3 Note), 5.1 (One Plus One), 6 (Nexus 5) except on one mobile running Android 5.0 (Lenovo A1000, Launcher is similar to MiUI). 应用程序在Android版本4.4.2(Mi Note 4G,必须在其安全应用程序中启用权限),5.0(联想K3 Note),5.1(One Plus One),6(Nexus 5)的所有手机上运行良好,除了一款手机运行Android 5.0(联想A1000,Launcher类似于MiUI)。 Application installs on interal storage only. 应用程序仅安装在内部存储上。 Used/Launched the app once before the device reboot. 在设备重启之前使用/启动应用程序一次。 Here are the excerpts from the manifest and broadcast receiver files 以下是清单和广播接收器文件的摘录

manifest.xml: manifest.xml文件:

 <receiver android:name="com.company.Broadcast"
     android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
       
        <intent-filter>
    
            <action android:name="android.intent.action.BOOT_COMPLETED" />
    
            <category android:name="android.intent.category.LAUNCHER" />
    
        </intent-filter>
    
    </receiver>
    
    <service android:enabled="true" android:exported="false" android:name="com.company.service" />

broadcast receiver: 广播接收者:

    public class Broadcast extends BroadcastReceiver {
    
        private static final String TAG = “BroadcastReceiver";
    
        @Override
    
        public void onReceive(Context context, Intent intent) {
    
            Log.d(TAG, "onReceive");
    
            Intent service = new Intent(context, Service.class);
    
            service.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    
            context.startService(service);
        
    }
    
    
    }

Some the pre-installed apps start fine on boot and some are skipped. 一些预先安装的应用程序在启动时启动,有些被跳过。 My app happened to be on the skipped apps list. 我的应用程序恰好位于跳过的应用列表中。

Here are some lines from logcat when the device boots, 以下是设备启动时来自logcat的一些行,

01-18 17:02:58.933 504-560/? I/PackageManager: Package com.android.deskclock checking android.permission.RECEIVE_BOOT_COMPLETED: BasePermission{183dc63c android.permission.RECEIVE_BOOT_COMPLETED}
01-18 17:02:58.933 504-560/? I/PackageManager: Package com.android.deskclock granting android.permission.RECEIVE_BOOT_COMPLETED
01-18 17:02:58.933 504-560/? I/PackageManager: Package com.android.mms.service checking android.permission.RECEIVE_BOOT_COMPLETED: BasePermission{183dc63c android.permission.RECEIVE_BOOT_COMPLETED}
01-18 17:02:58.933 504-560/? I/PackageManager: Package com.android.mms.service granting android.permission.RECEIVE_BOOT_COMPLETED

Skipped package comments: 跳过包评论:

01-18 17:03:06.235 504-529/? D/ActivityManager: send broadcast: android.intent.action.BOOT_COMPLETED, skip package: com.google.android.gm
01-18 17:03:06.235 504-529/? D/ActivityManager: send broadcast: 

> android.intent.action.BOOT_COMPLETED, skip package: com.company

01-18 17:03:06.235 504-529/? D/ActivityManager: send broadcast: android.intent.action.BOOT_COMPLETED, skip package: com.frozendevs.cache.cleaner

I might have missed out some bit of code to make it work. 我可能错过了一些代码来使它工作。 Any Comments/suggestions would help a lot for me to proceed furhter. 任何评论/建议对我来说都有很大的帮助。

The problem is with the device. 问题出在设备上。 some devices only allow internal apps to receive this action. 某些设备仅允许内部应用程序接收此操作。

you can add this to your intent filter as work around 您可以将其添加到您的意图过滤器中作为解决方法

<action android:name="android.intent.action.USER_PRESENT" />

This is triggered after the user unlocks the device. 用户解锁设备后会触发此操作。

After a long research i got the solution even the lenovo 1000 mobile too . 经过长时间的研究,我得到了解决方案,即使是联想1000手机也是如此。

 <action android:name="android.intent.action.USER_PRESENT" />

its working fine for me.if its lenovo mobile u should wait atleast 2 minuts then it will open automaticaly 它的工作正常。如果它的联想移动你应该等待至少2分钟然后它将自动打开

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM