Code example for AppWidgetManager

Methods: getAppWidgetInfo

0
    } 
 
    private void configureWidget(Intent data) {
        Bundle extras = data.getExtras();
        int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
        AppWidgetProviderInfo appWidgetInfo =
                mAppWidgetManager.getAppWidgetInfo(appWidgetId);
        if (appWidgetInfo.configure != null) {
            Intent intent =
                    new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
            intent.setComponent(appWidgetInfo.configure);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
        } else { 
            saveWidget(data);
        } 
    } 
 
    private void saveWidget(Intent data) {
        Bundle extras = data.getExtras();
        int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
 
        Intent send = new Intent();
        send.setAction(ACTION_SEND_ID);
        send.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        send.putExtra("summary", getWidgetSummary(appWidgetId));
        sendBroadcast(send);
        Log.i(TAG, "ACTION_SEND_ID sent ID:"+ appWidgetId + " Label:"+getWidgetSummary(appWidgetId) );
        finish();
 
    } 
 
    private String getWidgetSummary(int appWidgetId) {
        if (appWidgetId == -1) {
            return "None"; 
        } else { 
            AppWidgetProviderInfo appWPI = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
            if (appWPI == null) {
                return "Problem:" + appWidgetId;
            } else { 
                return appWPI.label;
            } 
Stop searching for code, let great code find you!  Add Codota to your java IDE