Im still new to this android stuff but I am trying to write a widget. I got all the code I needed working in a stand alone app but am now trying to get it to function as a widget. But I am having some problem starting the contact picker intent.
Basically, what I would like to do is launch the contact picker intent when a widget is created, but that simple code is not working for me and Im not sure what is wrong with it. Here is the slice of code…
public class WidgetProvider extends AppWidgetProvider
{
....
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{ //User is creating a new widget.
//Select a contact.
int contact_pick = 1;
//Contact Picker
Intent PickContact = new Intent(
Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI
);
startActivityForResult(PickContact, contact_pick);
}
....
}
eclipse just gives the following message for the startactivity line: The method startActivityForResult(Intent, int) is undefined for the type
WidgetProvider
Any ideas what I am doing wrong here?
startActivityForResult()is only available onActivity. You cannot pick a contact from anAppWidgetProvider. However, you can start a regularActivity, usingstartActivity(), and it can then usestartActivityForResult()to pick a contact.