来自小部件提供商的发布意图操作
我想构建一个搜索小部件。单击小部件应在我的应用程序内打开搜索活动。这是来自小部件提供商的 onUpdate() 的代码。
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
/* as their may be many widget instances for this widget. we get an array. */
for(int i=0;i< appWidgetIds.length; i++)
{
Intent intent = new Intent(context, SearchActivity.class);
intent.setAction("android.intent.action.SEARCH");
PendingIntent pdIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews view = new RemoteViews(context.getPackageName(), myPackage.R.layout.search_appwidget);
view.setOnClickPendingIntent(R.id.search_widget_textbox,pdIntent );
appWidgetManager.updateAppWidget(appWidgetIds[i], view);
}
}
在我的 SearchActivity.onCreate() 中,我正在检查意图操作 Intent.ACTION_SEARCH.equals( this.getIntent().getAction())
。但是,当通过小部件提供程序使用 PendingIntent 发布意图时,this.getIntent().getAction()
返回 null。当通过 SearchManager 调用 SearchActivity(应用程序的默认 SearchManager 处理程序)时,它会获取有效的操作,如 android.intent.action.SEARCH
。
我对待定意图做错了什么?
I want to build a search widget. Clicking on the widget should open search activity inside my app. Here is the code from widget provider's onUpdate().
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
/* as their may be many widget instances for this widget. we get an array. */
for(int i=0;i< appWidgetIds.length; i++)
{
Intent intent = new Intent(context, SearchActivity.class);
intent.setAction("android.intent.action.SEARCH");
PendingIntent pdIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews view = new RemoteViews(context.getPackageName(), myPackage.R.layout.search_appwidget);
view.setOnClickPendingIntent(R.id.search_widget_textbox,pdIntent );
appWidgetManager.updateAppWidget(appWidgetIds[i], view);
}
}
Inside my SearchActivity.onCreate(), I am checking for intent action as Intent.ACTION_SEARCH.equals( this.getIntent().getAction())
. However, when an intent is posted using PendingIntent via widget provider the this.getIntent().getAction()
returns null. When SearchActivity (which is a default SearchManager handler for the app) is invoked via SearchManager it gets valid action as android.intent.action.SEARCH
.
What am I doing wrong with pending intent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里得到了答案。
因为它表明该操作已在 SearchActivity.OnReceive() 中发布。此外,该操作适用于 text_box(不适用于 Activity),因此
SearchActivity.getIntent().getAction()
为 null。I got my answer here.
As it indicates the action is posted in SearchActivity.OnReceive(). Also the action is for text_box (not for activity) and hence
SearchActivity.getIntent().getAction()
is null.