android broadcast intent
Android之Broadcast, BroadcastReceiver:
http://www.cnblogs.com/shanshan520/archive/2012/03/02.html
http://android.blog.51cto.com/268543/521784
androidmanifest.xml:
http://blog.csdn.net/fireofstar/article/details/7583047
context:
http://blog.csdn.net/ihrthk/article/details/7321309
content, activity, service, intent详细:
http://blog.csdn.net/blogercn/article/details/7430258
http://www.apkbus.com/android-14223-1-1.html
更改了一下android应用杨版例子9-7使之支持broadcastreceiver:
<action android:name="android.intent.action.TIME_SET" /> --> ACTION_TIME_CHANGED
//activity01:
View.OnClickListener mOnClickListener = new View.OnClickListener()
{
public void onClick(View v)
{
final Context context = Activity01.this;
String titlePrefix = mAppWidgetPrefix.getText().toString();
saveTitlePref(context, mAppWidgetId, titlePrefix);
//ȡ��AppWidgetManagerʵ��
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
//����AppWidget
//ExampleAppWidgetProvider.updateAppWidget(context, appWidgetManager, mAppWidgetId, titlePrefix);
Intent resultValue = new Intent();//(Intent.ACTION_TIME_CHANGED);
resultValue.setAction(Intent.ACTION_TIME_CHANGED);
//resultValue.setAction();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
context.sendBroadcast(resultValue);
finish();
}
};
static void loadAllTitlePrefs(Context context, Intent intent, ArrayList<Integer> appWidgetIds, ArrayList<String> texts)
{
Bundle extras = null;
if (intent != null ) {
Log.i("BRUCE WD", "loadAllTitlePrefs, intent not null");
extras = intent.getExtras();
}
else {
Log.i("BRUCE WD", "loadAllTitlePrefs, intent is null");
}
if (extras != null) {
Log.i("BRUCE WD", "loadAllTitlePrefs, before get id");
int AppWidgetIdint = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
Log.i("BRUCE WD", "loadAllTitlePrefs, after get id = " + AppWidgetIdint);
appWidgetIds.add(AppWidgetIdint);
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
String prefix = prefs.getString(PREF_PREFIX_KEY + AppWidgetIdint, null);
if (prefix != null)
{
Log.i("BRUCE WD", "loadAllTitlePrefs load prep = " + prefix);
texts.add(prefix);
}
else
{
Log.i("BRUCE WD", "loadAllTitlePrefs loadpref default");
texts.add(context.getString(R.string.appwidget_prefix_default));
}
/*
int[] appWidgetIdint = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
//for () {
//}
//appWidgetIds.();//addAll(appWidgetIdint);
//appWidgetIds=Arrays.asList(<appWidgetIdint);
Log.i("BRUCE WD", "loadAllTitlePrefs, appWidgetIdint" + appWidgetIdint.length);
if (appWidgetIdint.length > 0) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
for (int i = 0; i < appWidgetIdint.length; i++) {
appWidgetIds.add(appWidgetIdint[i]);
String prefix = prefs.getString(PREF_PREFIX_KEY + appWidgetIdint[i], null);
if (prefix != null)
{
Log.i("BRUCE WD", "loadAllTitlePrefs load prep = " + prefix);
texts.add(prefix);
}
else
{
Log.i("BRUCE WD", "loadAllTitlePrefs loadpref default");
texts.add(context.getString(R.string.appwidget_prefix_default));
}
}
}
*/
}
else {
Log.i("BRUCE WD", "loadAllTitlePrefs, extras = null");
}
}
//broadcastreceiver:
public void onReceive(Context context, Intent intent)
{
Log.i("BRUCE WD", "onreveive 1");
//ͨ��BroadcastReceiver4����AppWidget
String action = intent.getAction();
if (action.equals(Intent.ACTION_TIMEZONE_CHANGED) || action.equals(Intent.ACTION_TIME_CHANGED))
{
AppWidgetManager gm = AppWidgetManager.getInstance(context);
ArrayList<Integer> appWidgetIds = new ArrayList<Integer>();
ArrayList<String> texts = new ArrayList<String>();
Log.i("BRUCE WD", "onreveive 2.0");
Activity01.loadAllTitlePrefs(context, intent, appWidgetIds, texts);
Log.i("BRUCE WD", "onreveive 2");
//��������AppWidget
final int N = appWidgetIds.size();
Log.i("BRUCE WD", "onreveive 3 number n = " + N);
for (int i = 0; i < N; i++)
{
Log.i("BRUCE WD", "onreveive 4");
ExampleAppWidgetProvider.updateAppWidget(context, gm, appWidgetIds.get(i), texts.get(i));
}
}
}
更多相关文章
- Android Bluetooth蓝牙开发\蓝牙协议\蓝牙通信例子_Android支
- android仿京东商城例子
- Android IDL 小例子
- android ExpandableListView简单例子
- android之sql例子
- Android请求获取Java后端数据,登录界面例子