시스템 날짜가 변경되거나 사용자가 시스템 날짜를 수동으로 변경할 때마다 카운트 다운 타이머를 시작하려고합니다. 나는 this 브로드 캐스트 조치를 사용하여 시스템 날짜가 변경되었지만 작동하지 않는지 여부를 감지했습니다. 이 문제에는 많은 스레드가 있습니다. 일부 사용자는 사용자가 설정에서 수동으로 날짜를 변경할 때만 작동하고 일부 사용자는 날짜가 자동으로 변경되거나 사용자가 설정에서 수동으로 변경되는 등 두 가지 방식으로 모두 작동한다고 말하고 있습니다. 하지만 제 경우에는 두 경우 모두에서 작동하지 않습니다. 일부 사용자는이 브로드 캐스트 액션 대신 알람 관리자를 사용하도록 제안하고 있습니다 (예 : '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에서도 Manifest에서 설정할 수 있습니다. – lionscribe