Example usage for android.appwidget AppWidgetManager EXTRA_APPWIDGET_IDS

List of usage examples for android.appwidget AppWidgetManager EXTRA_APPWIDGET_IDS

Introduction

In this page you can find the example usage for android.appwidget AppWidgetManager EXTRA_APPWIDGET_IDS.

Prototype

String EXTRA_APPWIDGET_IDS

To view the source code for android.appwidget AppWidgetManager EXTRA_APPWIDGET_IDS.

Click Source Link

Document

An intent extra that contains multiple appWidgetIds.

Usage

From source file:eu.power_switch.widget.provider.ReceiverWidgetProvider.java

/**
 * Forces an Update of all Receiver Widgets
 *
 * @param context any suitable context/*w w w . ja va 2s.c  o  m*/
 */
public static void forceWidgetUpdate(Context context) {
    // update receiver widgets
    Intent intent = new Intent(context, ReceiverWidgetProvider.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    int ids[] = AppWidgetManager.getInstance(context.getApplicationContext())
            .getAppWidgetIds(new ComponentName(context.getApplicationContext(), ReceiverWidgetProvider.class));
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
    context.sendBroadcast(intent);
}

From source file:net.sourceforge.servestream.service.AppWidgetOneProvider.java

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    defaultAppWidget(context, appWidgetIds);

    // Send broadcast intent to any running MediaPlaybackService so it can
    // wrap around with an immediate update.
    Intent updateIntent = new Intent(MediaPlaybackService.SERVICECMD);
    updateIntent.putExtra(MediaPlaybackService.CMDNAME, AppWidgetOneProvider.CMDAPPWIDGETUPDATE);
    updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
    context.sendBroadcast(updateIntent);
}

From source file:com.gaba.alex.trafficincidents.Utility.java

public static void updateWidget(Context context) {
    Intent intent = new Intent(context, IncidentsWidgetProvider.class);
    intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
    ComponentName name = new ComponentName(context, IncidentsWidgetProvider.class);
    int[] ids = AppWidgetManager.getInstance(context).getAppWidgetIds(name);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
    context.sendBroadcast(intent);/*from ww w  . j  a v a2  s  .c om*/
}

From source file:com.todotxt.todotxttouch.widget.ListWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    if (action.equals(REFRESH_ACTION)) {
        Log.d(TAG, "Widget Refresh button pressed");

        Intent i = new Intent(Constants.INTENT_START_SYNC_WITH_REMOTE);
        context.sendBroadcast(i);//www .  j  a  v  a2  s  .c o m
        Bundle extras = intent.getExtras();

        if (extras != null) {
            int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
            RemoteViews rv = buildLayout(context, appWidgetId, true);
            appWidgetManager.partiallyUpdateAppWidget(appWidgetId, rv);
        }
    } else if (action.equals(Constants.INTENT_WIDGET_UPDATE)) {
        Log.d(TAG, "Update widget intent received ");

        int[] appWidgetIds = null;
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        Bundle extras = intent.getExtras();

        if (extras != null) {
            appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        }

        if (appWidgetIds == null) {
            appWidgetIds = appWidgetManager
                    .getAppWidgetIds(new ComponentName(context, ListWidgetProvider.class.getName()));
        }

        if (appWidgetIds != null && appWidgetIds.length > 0) {
            this.onUpdate(context, appWidgetManager, appWidgetIds);
        }
    }

    super.onReceive(context, intent);
}

From source file:com.dpcsoftware.mn.Widget1Config.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.item1:
        //Save Widget Preferences
        SharedPreferences.Editor pEditor = wPrefs.edit();
        int idSelected = ((RadioGroup) findViewById(R.id.radioGroup1)).getCheckedRadioButtonId();
        boolean byMonth = false;
        if (idSelected == R.id.radio0)
            byMonth = true;/*www .java2s  . co m*/
        pEditor.putBoolean(wId + "_BYMONTH", byMonth);
        pEditor.putLong(wId + "_GROUPID", sp.getSelectedItemId());
        pEditor.commit();

        //Update widget
        Intent updateIntent = new Intent(this, Widget1.class);
        updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { wId });
        try {
            PendingIntent.getBroadcast(this, 0, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT).send();
        } catch (PendingIntent.CanceledException e) {
            e.printStackTrace();
        }

        setResult(RESULT_OK, resultIntent);
        finish();
        break;
    }
    return true;
}

From source file:de.Maxr1998.xposed.maxlock.ui.MasterSwitchShortcutActivity.java

public void fireIntentAndFinish() {
    Intent intent = new Intent(this, MasterSwitchWidget.class);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    int[] ids = AppWidgetManager.getInstance(getApplication())
            .getAppWidgetIds(new ComponentName(getApplication(), MasterSwitchWidget.class));
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
    sendBroadcast(intent);/*from w ww.j  a  va2  s. c o m*/
    finish();
}

From source file:org.opensilk.fuzzyclock.FuzzyWidgetService.java

@DebugLog
@Override/*from   w  w  w.j  a v a 2s.  c o  m*/
public int onStartCommand(Intent intent, int flags, int startId) {
    // No action means we want to reinit everything
    if (intent == null || intent.getAction() == null) {
        mHandler.sendEmptyMessage(UPDATE_SETTINGS);
        mHandler.sendMessage(mHandler.obtainMessage(UPDATE_ALL_WIDGETS, startId));
        // Update the specified widget
    } else if (intent.getAction().startsWith("scheduled_update")) {
        final int id = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        if (!sWidgetSettings.containsKey((Integer) id)) {
            mHandler.sendEmptyMessage(UPDATE_SETTINGS);
        }
        if (id != AppWidgetManager.INVALID_APPWIDGET_ID) {
            mHandler.sendMessage(mHandler.obtainMessage(UPDATE_SINGLE_WIDGET, id, startId));
        }
        // A widget was deleted, remove it from our settings map
    } else if (intent.getAction().equals(AppWidgetManager.ACTION_APPWIDGET_DELETED)) {
        int[] ids = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        if (ids != null) {
            for (int id : ids) {
                cancelUpdate(id);
                new FuzzyPrefs(mContext, id).remove();
                if (sWidgetSettings.containsKey((Integer) id)) {
                    sWidgetSettings.remove((Integer) id);
                }
            }
        }
        mHandler.sendMessage(mHandler.obtainMessage(UPDATE_ALL_WIDGETS, startId));
    }
    return START_STICKY;
}

From source file:com.dpcsoftware.mn.App.java

public void setFlag(int tableId) {
    switch (tableId) {
    case 1:// w w  w . j av  a 2 s  . c o m
        mnUpdateList = true;

        //Update widgets if anyone is being used
        AppWidgetManager wManager = AppWidgetManager.getInstance(this);
        ComponentName cWidgetProvider = new ComponentName(this, Widget1.class);
        int wIds[] = wManager.getAppWidgetIds(cWidgetProvider);
        if (wIds.length != 0) {
            Intent updateIntent = new Intent(this, Widget1.class);
            updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
            updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, wIds);
            try {
                PendingIntent.getBroadcast(this, 0, updateIntent, PendingIntent.FLAG_UPDATE_CURRENT).send();
            } catch (PendingIntent.CanceledException e) {
                e.printStackTrace();
            }
        }
        break;
    case 2:
        mnUpdateList = true;
        break;
    case 3:
        mnUpdateMenu = true;
        break;
    }
}

From source file:org.isoron.uhabits.MainActivity.java

private static void updateWidgets(Context context, Class providerClass) {
    ComponentName provider = new ComponentName(context, providerClass);
    Intent intent = new Intent(context, providerClass);
    intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    int ids[] = AppWidgetManager.getInstance(context).getAppWidgetIds(provider);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
    context.sendBroadcast(intent);//from   w  w w. j  a v a  2  s  .  c om
}

From source file:net.niyonkuru.koodroid.appwidget.WidgetConfigureActivity.java

@Override
public void onPause() {
    super.onPause();

    mAlertDialog.dismiss(); // avoid leaking window

    String action = getIntent().getAction();
    if (mResultCode == RESULT_CANCELED
            && (action != null && action.equals(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE))) {
        /* avoid phantom widgets */
        AppWidgetHost host = new AppWidgetHost(this, 1);
        host.deleteAppWidgetId(mAppWidgetId);
    } else {//from  w w  w .jav  a2s.c  o m
        Intent intent = IntentUtils.createWidgetIntent(this, AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetId });

        sendBroadcast(intent);
    }
}