WEB开发网
开发学院手机开发Android 开发 让自己的Android应用支持appwidget 阅读

让自己的Android应用支持appwidget

 2010-12-18 08:04:06 来源:WEB开发网   
核心提示:// Clean up the appWidgetId if we canceledint appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);if (appWidgetId != -1) {mAppWidgetHost.del

// 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">附件下载

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:自己 Android 应用

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接