繁体   English   中英

我的实体电话华硕未收到BOOT_COMPLETED

[英]BOOT_COMPLETED isn't received by my physical phone Asus

我测试了一个BroadcastReceiver ,它在模拟器中运行JobIntentService ,并且运行成功。

但是当我测试我的物理电话华硕ZE551ML的代码时,它失败了。

清单文件:

<?xml version="1.0" encoding="utf-8"?>

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
  <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
  </activity>

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

  <service android:name=".MyJobIntentService"
        android:permission="android.permission.BIND_JOB_SERVICE"

        android:exported="false"/>
</application>

BroadcastReceiver类:

package com.packt.backgroundservicedemo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // Write Code..

        if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            Intent i = new Intent(context, MyJobIntentService.class);
            i.putExtra("sleepTime", 12);
            MyJobIntentService.enqueueWork(context,i);
//            context.startService(i);

        }


    }
}

JobIntentService类别:

package com.packt.backgroundservicedemo;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.app.JobIntentService;
import android.util.Log;
import android.widget.Toast;


public class MyJobIntentService extends JobIntentService {

    static final int JOB_ID = 15;


    static void enqueueWork(Context context,Intent intent){
        enqueueWork(context,MyJobIntentService.class,JOB_ID,intent);
    }

    private static final String TAG = MyJobIntentService.class.getSimpleName();

    @Override
    public void onCreate() {
        super.onCreate();
        Toast.makeText(this,"Task Execution Started",Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onHandleWork(@NonNull Intent intent) {

        // Write code here..
        Log.i(TAG,"onHandleWork(), Thread name:" + Thread.currentThread().getName());

        int duration = intent.getIntExtra("sleepTime",-1);
        int ctr = 1;
        //Dummy long operation
        while (ctr<=duration){
            Log.i(TAG,"Time elapsed " + ctr + " secs");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            ctr++;
        }

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Toast.makeText(this,"Task Execution Finished",Toast.LENGTH_SHORT).show();



    }
}

重复:代码在仿真器设备,Oreo之前的设备和Oreo设备上运行良好。

该日志不包含针对我的应用程序显示的任何相关的boot_completed reveiced

谢谢。

我敢打赌-您的仿真器没有密码锁,而您的真实设备却没有。 仅在使用密码解锁BOOT_COMPLETED广播BOOT_COMPLETED ,并且您将不得不等待其他BroadcastReceiver接收此事件(已注册该事件的其他应用),具体取决于您在系统队列中的位置。

有一个自动启动管理器应用程序,该应用程序拒绝我的应用程序在启动时运行。

华硕自动启动管理器

现在,我的应用程序在开始时运行良好。

感谢@Arseny Levin的提示。

暂无
暂无

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

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