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?