Я исследовал, чтобы выяснить, как заставить мое приложение что-то делать при загрузке устройства.Я пытался сделать то же самое, но это не похоже на работу.Я пробовал несколькими способами, но я обнаружил некоторые неожиданные проблемы.Вот мой манифест:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ignacio.dailynotification">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- Keeps the processor from sleeping when a message is received. -->
<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>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<receiver
android:name=".BootCompletedReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>
А вот мой широковещательный приемник BootCompletedReceiver:
public class BootCompletedReceiver extends BroadcastReceiver {
private static final String LOG_TAG = BootCompletedReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
String message = "BootCompletedReceiver onReceive, action is " + action;
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
Log.d(LOG_TAG, action);
if(Intent.ACTION_BOOT_COMPLETED.equals(action))
{
Toast.makeText(context, "phone restarted", Toast.LENGTH_SHORT).show();
Log.d(LOG_TAG,"phone restarted");
}
}
}
Теперь я получаю этот вывод в моем logcat при поиске 'bootcompleted ':
2019-09-20 07:52:56.776 1867-2017/? I/keyguard: AsusSlideshowManager:queryLocalList cursor null mBootCompleted:false mRetryQuery:0
2019-09-20 07:52:57.291 1867-2017/? I/keyguard: AsusSlideshowManager:queryLocalList cursor null mBootCompleted:false mRetryQuery:0
2019-09-20 07:52:58.303 1867-2017/? I/keyguard: AsusSlideshowManager:queryLocalList cursor null mBootCompleted:false mRetryQuery:0
2019-09-20 07:53:00.491 1867-1867/? I/keyguard: AsusWeatherDataMonitor: :onBootCompleted
2019-09-20 07:53:16.910 2144-2144/? E/VvmBootCompletedRcvr: phone account ComponentInfo{com.android.phone/com.android.services.telephony.TelephonyConnectionService}, [e0184adedf913b076626646d3f52c3b49c39ad6d], UserHandle{0} has invalid subId -1
2019-09-20 07:53:17.326 1435-2416/? I/ActivityManager: Start proc 4147:com.android.vending/u0a47 for broadcast com.android.vending/com.google.android.finsky.boothandler.BootCompletedReceiver duration: 14
2019-09-20 07:53:19.716 1435-2027/? I/ActivityManager: Start proc 4313:com.asus.dm/1000 for broadcast com.asus.dm/.BootCompletedReceiver duration: 21
2019-09-20 07:53:19.836 4313-4313/? D/DMC->BootCompletedReceiver: ===== BCReceiver: Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 cmp=com.asus.dm/.BootCompletedReceiver (has extras) }
2019-09-20 07:53:19.935 4313-4313/? D/DMC->BootCompletedReceiver: check fota update status.
2019-09-20 07:53:19.935 4313-4313/? D/DMC->BootCompletedReceiver: check unfinished dm session.
2019-09-20 07:53:19.935 4313-4313/? D/DMC->BootCompletedReceiver: check is need resume DL.
2019-09-20 07:53:19.935 4313-4313/? D/DMC->BootCompletedReceiver: ===== over 18 month, no fota polling @receiveBootComplete()
2019-09-20 07:53:19.936 4313-4313/? D/DMC->BootCompletedReceiver: NextPollingInterval: Long.MAX_VALUE
2019-09-20 07:53:19.936 4313-4313/? D/DMC->BootCompletedReceiver: **NOT** Start DM Service
2019-09-20 07:53:19.937 4313-4313/? D/DMC->BootCompletedReceiver: exit onReceive
2019-09-20 07:53:19.938 4313-4313/? I/ActivityThread: Performing receive of Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 cmp=com.asus.dm/.BootCompletedReceiver (has extras) }: app=com.asus.dm.DMApp@a04c4e4, appName=com.asus.dm, pkg=com.asus.dm, comp={com.asus.dm/com.asus.dm.BootCompletedReceiver}, dir=/system/app/DMClient/DMClient.apk, duration=102
2019-09-20 07:53:21.696 4423-4423/? D/FirmwareManager: Booted - onBootCompleted, check for PAD EC and Camera ISP
2019-09-20 07:53:24.792 1435-2706/? I/ActivityManager: Start proc 4686:com.asus.userfeedback/u0a108 for broadcast com.asus.userfeedback/.BootCompletedBroadcastReceiver duration: 18
2019-09-20 07:53:25.721 1435-1435/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1357 android.content.ContextWrapper.startService:620 android.content.ContextWrapper.startService:620 com.dsi.ant.server.AntService.startService:129 com.dsi.ant.server.startup.BootCompletedReceiver.onReceive:41
2019-09-20 07:53:26.169 1435-2416/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 (has extras) } to com.google.android.apps.docs/com.google.android.libraries.internal.growth.growthkit.inject.GrowthKitBootCompletedBroadcastReceiver requires android.permission.RECEIVE_BOOT_COMPLETED due to sender null (uid 1000)
2019-09-20 07:53:34.828 5190-5190/? W/GrowthKit: Failed to get GrowthKitJobScheduler in GrowthKitBootCompletedBroadcastReceiver So GrowthKit failed to schedule jobs after package replaced / boot completed.
java.lang.NullPointerException: Unable to get GrowthKit Component from host app.
at com.google.android.libraries.internal.growth.growthkit.inject.GrowthKit.get(GrowthKit.java:43)
at com.google.android.libraries.internal.growth.growthkit.inject.GrowthKitBootCompletedBroadcastReceiver.onReceive(GrowthKitBootCompletedBroadcastReceiver.java:29)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3044)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1561)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:159)
at android.app.ActivityThread.main(ActivityThread.java:6139)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
2019-09-20 07:53:40.272 2820-5535/? I/constellation: [intent_handler] Received onBootCompleted intent
2019-09-20 07:53:43.700 2254-5354/? I/NetRec: [145] BootCompletedOrAppUpdatedIntentOperation.onHandleIntent: onBootCompleted()
2019-09-20 07:53:43.948 2254-5354/? I/NetRec: [145] BootCompletedOrAppUpdatedIntentOperation.onHandleIntent: Scheduling CleanupDatabaseTask
2019-09-20 07:53:46.769 1435-1453/? I/ActivityManager: Start proc 5946:org.simalliance.openmobileapi.service/1000 for broadcast org.simalliance.openmobileapi.service/.SmartcardServiceBootCompletedBroadcastReceiver duration: 17
Я думаю, может быть, я получаю трансляцию правильно, но мое приложение не может делать ничего, кроме этого, или это так.
Заранее спасибо за помощь.Заранее благодарим за помощь.