Example usage for android.appwidget AppWidgetManager ACTION_APPWIDGET_ENABLED

List of usage examples for android.appwidget AppWidgetManager ACTION_APPWIDGET_ENABLED

Introduction

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

Prototype

String ACTION_APPWIDGET_ENABLED

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

Click Source Link

Document

Sent when an instance of an AppWidget is added to a host for the first time.

Usage

From source file:com.google.android.apps.mytracks.widgets.TrackWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);
    String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)
            || AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)
            || context.getString(R.string.track_paused_broadcast_action).equals(action)
            || context.getString(R.string.track_resumed_broadcast_action).equals(action)
            || context.getString(R.string.track_started_broadcast_action).equals(action)
            || context.getString(R.string.track_stopped_broadcast_action).equals(action)
            || context.getString(R.string.track_update_broadcast_action).equals(action)) {
        long trackId = intent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L);
        update(context, trackId);//w  ww. j  av a2  s  . c om
    }
}

From source file:com.ravi.apps.android.newsbytes.widget.NewsWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    // Get the intent action.
    String action = intent.getAction();
    Log.d(LOG_TAG, context.getString(R.string.log_on_receive) + action);

    // If the widget was enabled, start the sync adapter for immediate sync.
    if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
        // Initialize the sync adapter and trigger an immediate sync.
        NewsSyncAdapter.initializeSyncAdapter(context);
        NewsSyncAdapter.syncImmediately(context);
    }// w  ww.j  av  a 2 s  .  c om

    // If the underlying data has been updated, notify the widgets to refresh their views
    if (context.getString(R.string.action_data_updated).equals(action)) {
        // Get the app widget manager.
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

        // Get app widget ids from the app widget manager.
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, getClass()));

        // Notify the app widget manager that the underlying widget data has changed.
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_list_view);
    }
}

From source file:com.nogago.android.tracks.widgets.TrackWidgetProvider.java

@Override
public void onReceive(Context aContext, Intent intent) {
    super.onReceive(aContext, intent);
    initialize(aContext);/* w  w  w  .  j a  va2 s . c om*/

    selectedTrackId = intent.getLongExtra(context.getString(R.string.track_id_broadcast_extra),
            selectedTrackId);
    String action = intent.getAction();

    if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)
            || AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)
            || trackStartedBroadcastAction.equals(action) || trackStoppedBroadcastAction.equals(action)) {
        updateTrack(action);
    }
}