开发者

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 n开发者_JAVA百科o 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜