user1209575
user1209575

Reputation: 57

How to code an android application update from the Android Market

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

Answers (2)

Relsell
Relsell

Reputation: 771

I think you need market app to be installed to handle the uri.

Upvotes: 1

Force
Force

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

Related Questions