システム日付が変更されたとき、またはユーザーが手動でシステム日付を変更したときにカウントダウンタイマーを開始しようとしています。私はthisブロードキャストアクションを使用して、システムの日付が変更されたが動作していないかどうかを検出しました。この問題には多くのスレッドがあります。一部のユーザーは、ユーザーが設定から手動で日付を変更し、日付が自動的に変更されるか、またはユーザーが設定から手動で変更するという両方の方法で機能すると言うユーザーがいる場合にのみ機能すると言います。しかし、私の場合は、両方のケースで動作していません。一部のユーザーは、このブロードキャストアクションの代わりにAlarm Managerを使用することを提案しています。つまり、「android.intent.action.DATE_CHANGED」です。続きシステム日付が変更されたかどうかを自動的に検出
は、放送の私の実装です:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.byteshaft.a1440time">
<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"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".receivers.OnDateChangeReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED"/>
</intent-filter>
</receiver>
</application>
</manifest>
マイ放送受信機クラス:アラームマネージャが唯一の解決策は、その後で
public class OnDateChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_DATE_CHANGED)){
System.out.println("Changed");
}
}
}
場合に、それを実装する方法上の任意のガイドがあります適切な方法?
経由で登録することができます。 –
@Dominik 'android.intent.action.TIME_SET'はホワイトリストに登録されたインテントで、https://developer.android.com/guide/components/broadcast-exceptions.htmlに従ってAPI 26でもマニフェストで設定できます – lionscribe