让自己的Android应用支持appwidget
2010-12-18 08:04:06 来源:WEB开发网new ArrayList();
AppWidgetProviderInfo info = new AppWidgetProviderInfo();
info.provider = new ComponentName(getPackageName(), "XXX.YYY");
info.label = "Search";
info.icon = R.drawable.ic_search_widget;
customInfo.add(info);
pickIntent.putParcelableArrayListExtra(
AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
ArrayList customExtras = new ArrayList();
Bundle b = new Bundle();
b.putString(EXTRA_CUSTOM_WIDGET, "search_widget");
customExtras.add(b);
pickIntent.putParcelableArrayListExtra(
AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras);
// start the pick activity
startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
}
/**
* 添加widget
* @param data
*/
private void completeAddAppWidget(Intent data) {
Bundle extras = data.getExtras();
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
d("completeAddAppWidget", "dumping extras content="+extras.toString());
d("completeAddAppWidget", "appWidgetId:"+ appWidgetId);
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
View hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
layout.addInScreen(hostView, appWidgetInfo.minWidth, appWidgetInfo.minHeight);
}
}
package chroya.demo.widget;
import static android.util.Log.d;
import java.util.ArrayList;
import android.app.Activity;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Intent;
点击下载:php?id=1365" rel="nofollow">附件下载
更多精彩
赞助商链接