android.appwidget.AppWidgetManager.getAppWidgetIds()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(249)

本文整理了Java中android.appwidget.AppWidgetManager.getAppWidgetIds()方法的一些代码示例,展示了AppWidgetManager.getAppWidgetIds()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AppWidgetManager.getAppWidgetIds()方法的具体详情如下:
包路径:android.appwidget.AppWidgetManager
类名称:AppWidgetManager
方法名:getAppWidgetIds

AppWidgetManager.getAppWidgetIds介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

private void updateAllWidgets(){
  AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
  int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, MyWidget.class));
  if (appWidgetIds.length > 0) {
    new MyWidget().onUpdate(this, appWidgetManager, appWidgetIds);
  }
}

代码示例来源:origin: stackoverflow.com

public static void updateMyWidgets(Context context, Parcelable data) {
  AppWidgetManager man = AppWidgetManager.getInstance(context);
  int[] ids = man.getAppWidgetIds(
      new ComponentName(context,MyWidgetProvider.class));
  Intent updateIntent = new Intent();
  updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
  updateIntent.putExtra(MyWidgetProvider.WIDGET_ID_KEY, ids);
  updateIntent.putExtra(MyWidgetProvider.WIDGET_DATA_KEY, data);
  context.sendBroadcast(updateIntent);
}

代码示例来源:origin: k9mail/k-9

public static void triggerMessageListWidgetUpdate(Context context) {
  Context appContext = context.getApplicationContext();
  AppWidgetManager widgetManager = AppWidgetManager.getInstance(appContext);
  ComponentName widget = new ComponentName(appContext, MessageListWidgetProvider.class);
  int[] widgetIds = widgetManager.getAppWidgetIds(widget);
  Intent intent = new Intent(context, MessageListWidgetProvider.class);
  intent.setAction(ACTION_UPDATE_MESSAGE_LIST);
  intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
  context.sendBroadcast(intent);
}

代码示例来源:origin: stackoverflow.com

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int appWidgetIds[] = appWidgetManager.getAppWidgetIds(
              new ComponentName(context, WidgetProvider.class));
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listview);

代码示例来源:origin: naman14/Timber

@Override
public void onReceive(Context context, Intent intent) {
  String action = intent.getAction();
  if (action != null && action.startsWith("com.naman14.timber.")) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName thisAppWidget = new ComponentName(context.getPackageName(), this.getClass().getName());
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);
    onUpdate(context, appWidgetManager, appWidgetIds, intent.getExtras());
  } else {
    super.onReceive(context, intent);
  }
}

代码示例来源:origin: stackoverflow.com

public class WebWidgetProvider extends AppWidgetProvider {
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // We can't trust the appWidgetIds param here, as we're using
    // ACTION_APPWIDGET_UPDATE to trigger our own updates, and
    // Widgets might've been removed/added since the alarm was last set.
    final int[] currentIds = appWidgetManager.getAppWidgetIds(
      new ComponentName(context, WebWidgetProvider.class));

    if (currentIds.length < 1) {
      return;
    }

    // We attach the current Widget IDs to the alarm Intent to ensure its
    // broadcast is correctly routed to onUpdate() when our AppWidgetProvider
    // next receives it.
    Intent iWidget = new Intent(context, WebWidgetProvider.class)
      .setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
      .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, currentIds);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, iWidget, 0);

    ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE))
      .setExact(AlarmManager.RTC, System.currentTimeMillis() + 30000, pi);

    Intent iService = new Intent(context, WebShotService.class);
    context.startService(iService);
  }
}

代码示例来源:origin: stackoverflow.com

public class MyWidgetProvider extends AppWidgetProvider {
private static final String ACTION_CLICK = "ACTION_CLICK";  
  @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
 // Get all ids
 ComponentName thisWidget = new ComponentName(context,
   MyWidgetProvider.class);
 int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
 for (int widgetId : allWidgetIds) {
  // Create some random data
  int number = (new Random().nextInt(100));
  RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
    R.layout.widget_layout);
  Log.w("WidgetExample", String.valueOf(number));
  // Set the text
  remoteViews.setTextViewText(R.id.update, String.valueOf(number));
  // Register an onClickListener
  Intent intent = new Intent(context, MyWidgetProvider.class);
  intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
  intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
    0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);
  appWidgetManager.updateAppWidget(widgetId, remoteViews);
 }
}

代码示例来源:origin: ankidroid/Anki-Android

@Override
public void updateWidgetDimensions(Context context, RemoteViews updateViews, Class<?> cls) {
  AppWidgetManager manager = AppWidgetManager.getInstance(context);
  int[] ids = manager.getAppWidgetIds(new ComponentName(context, cls));
  for (int id : ids) {
    final float scale = context.getResources().getDisplayMetrics().density;

代码示例来源:origin: robolectric/robolectric

@Test
public void getAppWidgetIds() {
 int expectedWidgetId = shadowAppWidgetManager.createWidget(SpanishTestAppWidgetProvider.class, R.layout.main);
 int[] appWidgetIds = appWidgetManager.getAppWidgetIds(
   new ComponentName(
     SpanishTestAppWidgetProvider.class.getPackage().getName(),
     SpanishTestAppWidgetProvider.class.getName()));
 assertEquals(1, appWidgetIds.length);
 assertEquals(expectedWidgetId, appWidgetIds[0]);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void bindAppWidgetIdIfAllowed_shouldRecordTheBinding() throws Exception {
 ComponentName provider = new ComponentName("A", "B");
 appWidgetManager.bindAppWidgetIdIfAllowed(789, provider);
 assertArrayEquals(new int[]{789}, appWidgetManager.getAppWidgetIds(provider));
}

代码示例来源:origin: stackoverflow.com

final int[] ids = widgetManager.getAppWidgetIds(
  new ComponentName(this, WebWidgetProvider.class));

代码示例来源:origin: stackoverflow.com

AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
ComponentName widgetComponent = new ComponentName(context, YourWidget.class);
int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
Intent update = new Intent();
update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, widgetIds);
update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
context.sendBroadcast(update);

代码示例来源:origin: stackoverflow.com

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
AppWidgetHost appWidgetHost = new AppWidgetHost(context, 1); // for removing phantoms
SharedPreferences prefs = getSharedPreferences("widget_prefs", 0);
boolean hasWidget = false;

int[] appWidgetIDs = appWidgetManager.getAppWidgetIds(new ComponentName(context, Widget.class));
for (int i = 0; i < appWidgetIDs.length; i++) {
  int id = appWidgetIDs[i];
  String key = String.format("appwidget%d_configured", id);
  if (prefs.getBoolean(key, false)) {
    hasWidget = true;
  } else {
    // delete the phantom appwidget
    appWidgetHost.deleteAppWidgetId(id);
  }
}

if (hasWidget) {
  // proceed
} else {
  // turn off alarms
}

代码示例来源:origin: stackoverflow.com

int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);

代码示例来源:origin: ukanth/afwall

final boolean firewallEnabled = extras.getBoolean(Api.STATUS_EXTRA);
final AppWidgetManager manager = AppWidgetManager.getInstance(context);
final int[] widgetIds = manager.getAppWidgetIds(new ComponentName(context, StatusWidget.class));
showWidget(context, manager, widgetIds, firewallEnabled);

代码示例来源:origin: vanilla-music/vanilla

/**
 * Check if there are any instances of this widget placed.
 */
public static void checkEnabled(Context context, AppWidgetManager manager)
{
  sEnabled = manager.getAppWidgetIds(new ComponentName(context, WidgetE.class)).length != 0;
}

代码示例来源:origin: vanilla-music/vanilla

/**
 * Check if there are any instances of this widget placed.
 */
public static void checkEnabled(Context context, AppWidgetManager manager)
{
  sEnabled = manager.getAppWidgetIds(new ComponentName(context, WidgetD.class)).length != 0;
}

代码示例来源:origin: vanilla-music/vanilla

/**
 * Check if there are any instances of this widget placed.
 */
public static void checkEnabled(Context context, AppWidgetManager manager)
{
  sEnabled = manager.getAppWidgetIds(new ComponentName(context, OneCellWidget.class)).length != 0;
}

代码示例来源:origin: vanilla-music/vanilla

/**
 * Check if there are any instances of this widget placed.
 */
public static void checkEnabled(Context context, AppWidgetManager manager)
{
  sEnabled = manager.getAppWidgetIds(new ComponentName(context, FourWhiteWidget.class)).length != 0;
}

代码示例来源:origin: stackoverflow.com

else if (intent.getAction().equals(
     AppWidgetManager.ACTION_APPWIDGET_UPDATE)) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
     ComponentName thisAppWidget = new ComponentName(context.getPackageName(), MyWidgetProvider.class.getName());
     int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);
      appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds,  R.id.listviewnew);
     Log.e("finally after a whole day", "working :");  
 }

相关文章