Example usage for android.appwidget AppWidgetManager getInstalledProviders

List of usage examples for android.appwidget AppWidgetManager getInstalledProviders

Introduction

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

Prototype

public List<AppWidgetProviderInfo> getInstalledProviders() 

Source Link

Document

Return a list of the AppWidget providers that are currently installed.

Usage

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

/**
 * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
 * provided by the same package which is set to be global search activity.
 * If widgetCategory is not supported, or no such widget is found, returns the first widget
 * provided by the package.//  ww w. jav a  2 s.  c o  m
 */
public static AppWidgetProviderInfo getSearchWidgetProvider(Context context) {
    SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    ComponentName searchComponent = searchManager.getGlobalSearchActivity();
    if (searchComponent == null)
        return null;
    String providerPkg = searchComponent.getPackageName();

    AppWidgetProviderInfo defaultWidgetForSearchPackage = null;

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
        if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) {
            if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
                return info;
            } else if (defaultWidgetForSearchPackage == null) {
                defaultWidgetForSearchPackage = info;
            }
        }
    }
    return defaultWidgetForSearchPackage;
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

/**
 * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
 * provided by the same package which is set to be global search activity.
 * If widgetCategory is not supported, or no such widget is found, returns the first widget
 * provided by the package.//ww  w.  j a va 2s. c o m
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static AppWidgetProviderInfo getSearchWidgetProvider(Context context) {
    SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    ComponentName searchComponent = searchManager.getGlobalSearchActivity();
    if (searchComponent == null)
        return null;
    String providerPkg = searchComponent.getPackageName();

    AppWidgetProviderInfo defaultWidgetForSearchPackage = null;

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
        if (info.provider.getPackageName().equals(providerPkg)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
                    return info;
                } else if (defaultWidgetForSearchPackage == null) {
                    defaultWidgetForSearchPackage = info;
                }
            } else {
                return info;
            }
        }
    }
    return defaultWidgetForSearchPackage;
}

From source file:piuk.blockchain.android.WalletApplication.java

public void notifyWidgets() {
    final Context context = getApplicationContext();

    // notify widgets
    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (final AppWidgetProviderInfo providerInfo : appWidgetManager.getInstalledProviders()) {
        // limit to own widgets
        if (providerInfo.provider.getPackageName().equals(context.getPackageName())) {
            final Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,
                    appWidgetManager.getAppWidgetIds(providerInfo.provider));
            context.sendBroadcast(intent);
        }//  w w w . ja  v a  2  s  .c o m
    }
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

private void updateWidgets() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] a = appWidgetManager
            .getAppWidgetIds(new ComponentName(this.getPackageName(), CheckItemsWidget.class.getName()));
    List<AppWidgetProviderInfo> b = appWidgetManager.getInstalledProviders();
    for (AppWidgetProviderInfo i : b) {
        if (i.provider.getPackageName().equals(this.getPackageName())) {
            a = appWidgetManager.getAppWidgetIds(i.provider);
            new CheckItemsWidget().onUpdate(this, appWidgetManager, a);
        }/*from  w  w  w . j a v  a2s.  co m*/
    }
}