通过ComponentName获取相应的Widget

最近在锁屏上研究,如果预置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;

    }

 

你可能感兴趣的:(component)