如果可以的话,我正在尝试弄清楚如何将意图发送到主屏幕以向其添加小部件。有任何想法吗?这是我一直在玩弄的一些代码,至少可以提示“添加小部件”选择。
AppWidgetManager mAppWidgetManager;
AppWidgetHost mAppWidgetHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
selectWidget();
mAppWidgetManager = AppWidgetManager.getInstance(this);
mAppWidgetHost = new AppWidgetHost(this, R.id.APPWIDGET_HOST_ID);
}
void selectWidget() {
int appWidgetId = this.mAppWidgetHost.allocateAppWidgetId();
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
startActivityForResult(pickIntent, R.id.REQUEST_PICK_APPWIDGET);
}
感谢任何做出贡献的人。