让自己的Android应用支持appwidget
2010-12-18 08:04:06 来源:WEB开发网// Clean up the appWidgetId if we canceled
int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
if (appWidgetId != -1) {
mAppWidgetHost.deleteAppWidgetId(appWidgetId);
}
}
}
/**
* 选中了某个widget之后,根据是否有配置来决定直接添加还是弹出配置activity
* @param data
*/
private void addAppWidget(Intent data) {
int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET);
d("addAppWidget", "data:"+ customWidget);
if ("search_widget".equals(customWidget)) {
//这里直接将search_widget删掉了
mAppWidgetHost.deleteAppWidgetId(appWidgetId);
} else {
AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
d("addAppWidget", "configure:"+ appWidget.configure);
if (appWidget.configure != null) {
//有配置,弹出配置
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
intent.setComponent(appWidget.configure);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
} else {
//没有配置,直接添加
onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
}
}
}
/**
* 请求添加一个新的widget
*/
private void addWidget() {
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
// add the search widget
ArrayList customInfo =
点击下载:php?id=1365" rel="nofollow">附件下载
更多精彩
赞助商链接