views:

23

answers:

1

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?

+1  A: 

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.

Ankit Jain