Alexander_Kolmachikhin
@Alexander_Kolmachikhin
Android Programming

Как программно узнать перезагружалось ли устройство или нет?

Мне нужно чтобы в моем BroadcastReceiver'е происходила проверка - был ли перезагружен телефон или нет. В зависимости от этого назначался бы AlarmManager.
Я тестировал свой код на андроид 5 и все работало, а вот на андроид 7 нет.
Что нужно еще добавить чтобы работало везде?

Моя проверка в BroadcastReceiver:
if (intent.getAction().equals(Intent.ACTION_LOCKED_BOOT_COMPLETED)
                || intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
// тут я заново назначаю алармы если устройво было перезагружено
        }


Мой манифест:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="kolmachikhin.alexander.todolist">

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

    <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/Theme.AppCompat.Light.DarkActionBar"
        tools:ignore="GoogleAppIndexingWarning">
        <activity.../>
        <activity.../>
        <activity.../>
        <activity.../>
<receiver android:name=".Notification.AlertReceiver"/>

        <receiver
            android:name=".Notification.RebootAlertReceiver"
            android:directBootAware="true"
            android:enabled="true"
            android:exported="false"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED"/>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </receiver>

    </application>

</manifest>
  • Вопрос задан
  • 186 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы