Example usage for android.appwidget AppWidgetManager EXTRA_APPWIDGET_PROVIDER_PROFILE

List of usage examples for android.appwidget AppWidgetManager EXTRA_APPWIDGET_PROVIDER_PROFILE

Introduction

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

Prototype

String EXTRA_APPWIDGET_PROVIDER_PROFILE

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

Click Source Link

Document

An intent extra that contains the user handle of the profile under which an AppWidget provider is registered.

Usage

From source file:com.appsimobile.appsii.module.home.appwidget.WidgetChooserActivity.java

@Override
public void onClick(View v) {
    int viewId = v.getId();
    if (viewId == R.id.ok_button) {
        if (mSelectedAppWidgetProviderInfo != null) {

            AppWidgetProviderInfo info = mSelectedAppWidgetProviderInfo;

            // In this case, we either need to start an activity to get permission to bind
            // the widget, or we need to start an activity to configure the widget, or both.
            mPendingAddWidgetId = mAppWidgetHost.allocateAppWidgetId();
            boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(mPendingAddWidgetId, info, null);
            if (success) {
                onAppWidgetSelected(mPendingAddWidgetId, info);
            } else {
                Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mPendingAddWidgetId);
                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.provider);

                mAppWidgetManager.getUser(mSelectedAppWidgetProviderInfo).addToIntent(intent,
                        AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
                // TODO: we need to make sure that this accounts for the options bundle.
                //                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS,
                // (Parcelable) null);
                startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
            }//from  w  w  w .ja v  a 2 s  .  c  o  m
        }

    } else if (viewId == R.id.cancel) {
        finish();
    }
}

From source file:com.launcher.silverfish.HomeScreenFragment.java

private void loadWidget() {
    ComponentName cn = sqlHelper.getWidgetContentName();

    Log.d("Widget creation", "Loaded from db: " + cn.getClassName() + " - " + cn.getPackageName());
    // Check that there actually is a widget in the database
    if (cn.getPackageName().isEmpty() && cn.getClassName().isEmpty()) {
        Log.d("Widget creation", "DB was empty");
        return;//from   w  w  w.j  av a  2s .co  m
    }
    Log.d("Widget creation", "DB was not empty");

    final List<AppWidgetProviderInfo> infos = mAppWidgetManager.getInstalledProviders();

    // Get AppWidgetProviderInfo
    AppWidgetProviderInfo appWidgetInfo = null;
    // Just in case you want to see all package and class names of installed widget providers,
    // this code is useful
    for (final AppWidgetProviderInfo info : infos) {
        Log.d("AD3", info.provider.getPackageName() + " / " + info.provider.getClassName());
    }
    // Iterate through all infos, trying to find the desired one
    for (final AppWidgetProviderInfo info : infos) {
        if (info.provider.getClassName().equals(cn.getClassName())
                && info.provider.getPackageName().equals(cn.getPackageName())) {
            // We found it!
            appWidgetInfo = info;
            break;
        }
    }
    if (appWidgetInfo == null) {
        Log.d("Widget creation", "app info was null");
        return; // Stop here
    }

    // Allocate the hosted widget id
    int appWidgetId = mAppWidgetHost.allocateAppWidgetId();

    boolean allowed_to_bind = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn);

    // Ask the user to allow this app to have access to their widgets
    if (!allowed_to_bind) {
        Log.d("Widget creation", "asking for permission");
        Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
        Bundle args = new Bundle();
        args.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, cn);
        if (Build.VERSION.SDK_INT >= 21) {
            args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE, null);
        }
        i.putExtras(args);
        startActivityForResult(i, REQUEST_BIND_APPWIDGET);
        return;
    } else {

        Log.d("Widget creation", "Allowed to bind");
        Log.d("Widget creation", "creating widget");
        //Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
        //createWidgetFromId(appWidgetId);
    }
    // Create the host view
    AppWidgetHostView hostView = mAppWidgetHost.createView(getActivity().getBaseContext(), appWidgetId,
            appWidgetInfo);

    // Set the desired widget
    hostView.setAppWidget(appWidgetId, appWidgetInfo);

    placeWidget(hostView);
}

From source file:com.launcher.silverfish.launcher.homescreen.HomeScreenFragment.java

private void loadWidget() {
    ComponentName cn = settings.getWidget();

    Log.d("Widget creation", "Loaded from db: " + cn.getClassName() + " - " + cn.getPackageName());
    // Check that there actually is a widget in the database
    if (cn.getPackageName().isEmpty() && cn.getClassName().isEmpty()) {
        Log.d("Widget creation", "DB was empty");
        return;//from  ww  w  . j a va2  s  . c om
    }
    Log.d("Widget creation", "DB was not empty");

    final List<AppWidgetProviderInfo> infos = mAppWidgetManager.getInstalledProviders();

    // Get AppWidgetProviderInfo
    AppWidgetProviderInfo appWidgetInfo = null;
    // Just in case you want to see all package and class names of installed widget providers,
    // this code is useful
    for (final AppWidgetProviderInfo info : infos) {
        Log.d("AD3", info.provider.getPackageName() + " / " + info.provider.getClassName());
    }
    // Iterate through all infos, trying to find the desired one
    for (final AppWidgetProviderInfo info : infos) {
        if (info.provider.getClassName().equals(cn.getClassName())
                && info.provider.getPackageName().equals(cn.getPackageName())) {
            // We found it!
            appWidgetInfo = info;
            break;
        }
    }
    if (appWidgetInfo == null) {
        Log.d("Widget creation", "app info was null");
        return; // Stop here
    }

    // Allocate the hosted widget id
    int appWidgetId = mAppWidgetHost.allocateAppWidgetId();

    boolean allowed_to_bind = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn);

    // Ask the user to allow this app to have access to their widgets
    if (!allowed_to_bind) {
        Log.d("Widget creation", "asking for permission");
        Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
        Bundle args = new Bundle();
        args.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, cn);
        if (Build.VERSION.SDK_INT >= 21) {
            args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE, null);
        }
        i.putExtras(args);
        startActivityForResult(i, REQUEST_BIND_APPWIDGET);
        return;
    } else {

        Log.d("Widget creation", "Allowed to bind");
        Log.d("Widget creation", "creating widget");
        //Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
        //createWidgetFromId(appWidgetId);
    }
    // Create the host view
    AppWidgetHostView hostView = mAppWidgetHost.createView(getActivity().getBaseContext(), appWidgetId,
            appWidgetInfo);

    // Set the desired widget
    hostView.setAppWidget(appWidgetId, appWidgetInfo);

    placeWidget(hostView);
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

/**
 * Process a widget drop.//from w w  w  . j av  a  2  s. co m
 *
 * @param info The PendingAppWidgetInfo of the widget being added.
 * @param cell The cell it should be added to, optional
 */
void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int[] cell, int[] span, int[] loc) {
    resetAddInfo();
    mPendingAddInfo.container = info.container = container;
    mPendingAddInfo.dropPos = loc;
    mPendingAddInfo.minSpanX = info.minSpanX;
    mPendingAddInfo.minSpanY = info.minSpanY;

    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }
    if (span != null) {
        mPendingAddInfo.spanX = span[0];
        mPendingAddInfo.spanY = span[1];
    }

    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetImpl(appWidgetId, info, hostView, info.info);
    } else {
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;

        boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.info, options);
        if (success) {
            addAppWidgetImpl(appWidgetId, info, null, info.info);
        } else {
            mPendingAddWidgetInfo = info.info;
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            mAppWidgetManager.getUser(mPendingAddWidgetInfo).addToIntent(intent,
                    AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
            // TODO: we need to make sure that this accounts for the options bundle.
            // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

/**
 * Process a widget drop.//from   w  w w.j av  a2  s .c  o m
 *
 * @param info The PendingAppWidgetInfo of the widget being added.
 * @param screenId The ID of the screen where it should be added
 * @param cell The cell it should be added to, optional
 */
private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, int[] cell,
        int[] span) {
    resetAddInfo();
    mPendingAddInfo.container = info.container = container;
    mPendingAddInfo.screenId = info.screenId = screenId;
    mPendingAddInfo.dropPos = null;
    mPendingAddInfo.minSpanX = info.minSpanX;
    mPendingAddInfo.minSpanY = info.minSpanY;

    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }
    if (span != null) {
        mPendingAddInfo.spanX = span[0];
        mPendingAddInfo.spanY = span[1];
    }

    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetImpl(appWidgetId, info, hostView, info.info);

        // Clear the boundWidget so that it doesn't get destroyed.
        info.boundWidget = null;
    } else {
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;

        boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.info, options);
        if (success) {
            addAppWidgetImpl(appWidgetId, info, null, info.info);
        } else {
            mPendingAddWidgetInfo = info.info;
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            mAppWidgetManager.getUser(mPendingAddWidgetInfo).addToIntent(intent,
                    AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
            // TODO: we need to make sure that this accounts for the options bundle.
            // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

/**
 * Process a widget drop.//from   w  w w.  j av a2s  .c  om
 *
 * @param info The PendingAppWidgetInfo of the widget being added.
 * @param screenId The ID of the screen where it should be added
 * @param cell The cell it should be added to, optional
 */
private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, int[] cell,
        int[] span) {
    resetAddInfo();
    mPendingAddInfo.container = info.container = container;
    mPendingAddInfo.screenId = info.screenId = screenId;
    mPendingAddInfo.dropPos = null;
    mPendingAddInfo.minSpanX = info.minSpanX;
    mPendingAddInfo.minSpanY = info.minSpanY;

    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }
    if (span != null) {
        mPendingAddInfo.spanX = span[0];
        mPendingAddInfo.spanY = span[1];
    }

    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        // In the case where we've prebound the widget, we remove it from the DragLayer
        if (LOGD) {
            Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
        }
        getDragLayer().removeView(hostView);

        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);

        // Clear the boundWidget so that it doesn't get destroyed.
        info.boundWidget = null;
    } else {
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;

        boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.info, options);
        if (success) {
            addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
        } else {
            mPendingAddWidgetInfo = info.info;
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            mAppWidgetManager.getUser(mPendingAddWidgetInfo).addToIntent(intent,
                    AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
            // TODO: we need to make sure that this accounts for the options bundle.
            // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}

From source file:com.android.launcher3.Launcher.java

/**
 * Process a widget drop.//from   w  w  w  . j a v a2 s.c om
 */
private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        // In the case where we've prebound the widget, we remove it from the DragLayer
        if (LOGD) {
            Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
        }
        getDragLayer().removeView(hostView);

        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetFromDropImpl(appWidgetId, info, hostView, info.info);

        // Clear the boundWidget so that it doesn't get destroyed.
        info.boundWidget = null;
    } else {
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;

        boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.info, options);
        if (success) {
            addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
        } else {
            setWaitingForResult(PendingRequestArgs.forWidgetInfo(appWidgetId, info.info, info));
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            mAppWidgetManager.getUser(info.info).addToIntent(intent,
                    AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
            // TODO: we need to make sure that this accounts for the options bundle.
            // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}

From source file:g7.bluesky.launcher3.Launcher.java

/**
 * Process a widget drop./*from   w w w  .  jav a  2s  . co  m*/
 *
 * @param info The PendingAppWidgetInfo of the widget being added.
 * @param screenId The ID of the screen where it should be added
 * @param cell The cell it should be added to, optional
 * @param position The location on the screen where it was dropped, optional
 */
void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, int[] cell, int[] span,
        int[] loc) {
    resetAddInfo();
    mPendingAddInfo.container = info.container = container;
    mPendingAddInfo.screenId = info.screenId = screenId;
    mPendingAddInfo.dropPos = loc;
    mPendingAddInfo.minSpanX = info.minSpanX;
    mPendingAddInfo.minSpanY = info.minSpanY;

    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }
    if (span != null) {
        mPendingAddInfo.spanX = span[0];
        mPendingAddInfo.spanY = span[1];
    }

    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetImpl(appWidgetId, info, hostView, info.info);
    } else {
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;

        boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.info, options);
        if (success) {
            addAppWidgetImpl(appWidgetId, info, null, info.info);
        } else {
            mPendingAddWidgetInfo = info.info;
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            mAppWidgetManager.getUser(mPendingAddWidgetInfo).addToIntent(intent,
                    AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
            // TODO: we need to make sure that this accounts for the options bundle.
            // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}

From source file:com.android.launcher3.Launcher.java

/**
 * Event handler for the app widget view which has not fully restored.
 *//*from  w ww . ja v  a  2s  .com*/
public void onClickPendingWidget(final PendingAppWidgetHostView v) {
    if (mIsSafeModeEnabled) {
        Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
        return;
    }

    final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
    if (v.isReadyForClickSetup()) {
        if (info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
            if (!info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
                // This should not happen, as we make sure that an Id is allocated during bind.
                return;
            }
            LauncherAppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.findProvider(info.providerName,
                    info.user);
            if (appWidgetInfo != null) {
                setWaitingForResult(PendingRequestArgs.forWidgetInfo(info.appWidgetId, appWidgetInfo, info));

                Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, info.appWidgetId);
                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, appWidgetInfo.provider);
                mAppWidgetManager.getUser(appWidgetInfo).addToIntent(intent,
                        AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
                startActivityForResult(intent, REQUEST_BIND_PENDING_APPWIDGET);
            }
        } else {
            LauncherAppWidgetProviderInfo appWidgetInfo = mAppWidgetManager
                    .getLauncherAppWidgetInfo(info.appWidgetId);
            if (appWidgetInfo != null) {
                startRestoredWidgetReconfigActivity(appWidgetInfo, info);
            }
        }
    } else if (info.installProgress < 0) {
        // The install has not been queued
        final String packageName = info.providerName.getPackageName();
        showBrokenAppInstallDialog(packageName, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
            }
        });
    } else {
        // Download has started.
        final String packageName = info.providerName.getPackageName();
        startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
    }
}