Reputation: 57
I am developing an android application with one basic function, to allow the user to click a button and download the full app from the android market (a virtual preload type app similar to the apps which come pre-loaded on the phone, which you have to actually install first to use) .
In my Activity class I create a Button and call the setOnClickListener...
marketButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String urlToMarket = "market://search?q=<package.name>";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(urlToMarket));
startActivity(i);
}
});
i get an ActivityNotFoundException: No Activity found to handle intent.
How do I code a handler for this intent?
Upvotes: 1
Views: 1486
Reputation: 6392
Try this:
/**
* Opens Android Market to install an App
*
* @param context
* A Context to use
* @param appId
* The appId, eg "de.bulling.smstalk"
*/
public static void installFromMarket(Context context, String appId) {
try {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://details?id="+appId));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} catch (ActivityNotFoundException e) {
Toast.makeText(context, "Could not open Android Market.", Toast.LENGTH_SHORT).show();
}
}
Upvotes: 2