gpt4 book ai didi

java - 从 RemoteViewsFactory 启动 Activity

转载 作者:行者123 更新时间:2023-11-29 21:04:48 28 4
gpt4 key购买 nike

我在应用程序小部件中有一个应用程序启动器。我想从 RemoteViewsFactory 开始 Activity 。但它没有用。

这是我在 RemoteViewsFactory 中的代码:

@Override
public RemoteViews getViewAt(int position) {

RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.app_item);

ResolveInfo info = mApps.get(position);
Bundle extras = new Bundle();

extras.putString(TheWidgetProvider.APP_ID, info.getClass().getName());
Intent fillInIntent = new Intent();
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(R.id.app_name, fillInIntent);

return rv;

}

这是我从 TheWidgetProvider 获得的代码:

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


Intent AppsServiceIntent = new Intent(context, AppsService.class);
AppsServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
AppsServiceIntent.setData(Uri.parse(AppsServiceIntent.toUri(Intent.URI_INTENT_SCHEME)));
views.setRemoteAdapter(R.id.GridViewApps, AppsServiceIntent);

Intent appsIntent = new Intent(context, TheWidgetProvider.class);
appsIntent.setAction(TheWidgetProvider.EVENT_SHOW_APP);
appsIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
appsIntent.setData(Uri.parse(updateServiceIntent.toUri(Intent.URI_INTENT_SCHEME)));
PendingIntent appsPendingIntent = PendingIntent.getBroadcast(context, 0, appsIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
views.setPendingIntentTemplate(R.id.GridViewApps, appsPendingIntent);

appWidgetManager.updateAppWidget(appWidgetId, views);
}
}

有没有人知道为什么它不起作用?

最佳答案

错误在这里:

PendingIntent appsPendingIntent = PendingIntent.getBroadcast(context, 0, appsIntent, PendingIntent.FLAG_UPDATE_CURRENT);

PendingIntent.getBroadcast(...) 创建广播,您需要像这样使用 PendingIntent.getActivity(...):

PendingIntent appsPendingIntent = PendingIntent.getActivity(context, 0, appsIntent, PendingIntent.FLAG_UPDATE_CURRENT);

关于java - 从 RemoteViewsFactory 启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24912544/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com