最近在锁屏上研究,如果预置widget,研究了好久,终于找到方法了,先上代码:
private int getAppWidgetFromComName(ComponentName providerCom) { int appWidgetId; appWidgetId = mAppWidgetHost.allocateAppWidgetId(); try { mAppWidgetManager.bindAppWidgetId(appWidgetId, providerCom); } catch (IllegalArgumentException e) { Log.e(TAG, "Error when trying to bind default AppWidget from " + providerCom); mAppWidgetHost.deleteAppWidgetId(appWidgetId); appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; } return appWidgetId; }