gpt4 book ai didi

android - 时区示例在模拟器中不起作用

转载 作者:行者123 更新时间:2023-11-29 16:26:07 26 4
gpt4 key购买 nike

<receiver android:name=".ExampleBroadCastReceiver" 
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.ACTION_TIMEZONE_CHANGED"/>
</intent-filter>
</receiver>
package com.broadcastreceiver;

import java.util.ArrayList;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ExampleBroadCastReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
// TODO Auto-generated method stub

Log.d("ExmampleBroadcastReceiver", "intent=" + intent);
Intent intent1 = new Intent(context,Login.class);
context.startActivity(intent1);
}
}

我运行上面的代码更改设置中的时区而不调用其他 Activity 。谁能告诉我问题出在哪里?

最佳答案

我遇到了同样的问题,这个线程帮助我使 TimeZone 更新正常工作,但是我仍然没有收到日期/时间更改的通知。我终于发现您在 list 文件中指定的内容与您的广播接收器在过滤 Intent 时使用的内容有所不同。虽然它记录在 Android Intent 引用中,但很容易被忽视!

在您的 AndroidManifest.xml 文件中,使用以下内容:

  <receiver android:name=".MyReceiver">
<intent-filter>
<!-- NOTE: action.TIME_SET maps to an Intent.TIME_CHANGED broadcast message -->
<action android:name="android.intent.action.TIME_SET" />
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

在你的接收器类中:

public class MyReceiver extends BroadcastReceiver {
private static final String TAG = "MyReceiver";
private static boolean DEBUG = true;

@Override
public void onReceive(Context context, Intent intent) {
final String PROC = "onReceive";

if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
if (DEBUG) { Log.v(TAG, PROC + ": ACTION_BOOT_COMPLETED received"); }
}
// NOTE: this was triggered by action.TIME_SET in the manifest file!
else if (intent.getAction().equals(Intent.ACTION_TIME_CHANGED)) {
if (DEBUG) { Log.v(TAG, PROC + ": ACTION_TIME_CHANGED received"); }
}
else if (intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) {
if (DEBUG) { Log.v(TAG, PROC + ": ACTION_TIMEZONE_CHANGED received"); }
}
}

}

关于android - 时区示例在模拟器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3618267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com