简体   繁体   中英

Start Android Market from App

I'm developing a lite version for an app on the Android. How can I start an Intent to open the Android Market, preferably with the full version of my app displayed? This is difficult to test on an emulator (which is the closest thing to a device I have), as there seems to be no legal way of installing the Market on it.

That query above works, but when I tried it, it looked like it was bringing up search results based on the name.

If you use something like

intent.setData(Uri.parse("market://details?id=com.wolinlabs.SuperScorepad")); 

instead, it will go right to the Android Market page for your app.

I think that's more what you wanted (?)

Found answer in the end:

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setData(Uri.parse("market://search?q=pname:MyApp")); 
startActivity(intent);

No way of testing on emulator, though.

Hi I was trying the achieve the same but with one small difference

I DIDN'T WANT TO OPEN IT EMBEDDED ON MY APP

public void start(JSONArray args, CallbackContext callback) {

    Intent launchIntent;
    String packageName;
    String activity;
    String uri;
    ComponentName comp;

    try {
        packageName = args.getString(0); //com.android.vending
        activity    = args.getString(1); //com.google.android.finsky.activities.LaunchUrlHandlerActivity
        uri         = args.getString(2); //'market://details?id=com.triplingo.enterprise'

        launchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage(packageName);
        comp = new ComponentName(packageName, activity);
        launchIntent.setComponent(comp);
        launchIntent.setData(Uri.parse(uri));

        this.cordova.getActivity().startActivity(launchIntent);
        callback.success();
    } catch (Exception e) {
        callback.error(e.toString());
    }
}

THE BIG DIFFERENCE HERE IS THAT YOU START A NEW APP NOT JUST SHOW GOOGLE PLAY IN YOUR APP

This code is part of a Cordova plugin but is pretty obvious what you need to do to use it natively.

THE IMPORTANT LINES

launchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage(packageName);
comp = new ComponentName(packageName, activity);
launchIntent.setComponent(comp);
launchIntent.setData(Uri.parse(uri));

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM