简体   繁体   English

从App启动Android Market

[英]Start Android Market from App

I'm developing a lite version for an app on the Android. 我正在为Android上的应用开发精简版。 How can I start an Intent to open the Android Market, preferably with the full version of my app displayed? 如何启动Intent以打开Android Market,最好显示我的应用程序的完整版本? 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. 相反,它将直接进入您的应用的Android Market页面。

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 这里的不同之处是你开始一个新的应用程序不仅仅是在你的应用程序中显示GOOGLE

This code is part of a Cordova plugin but is pretty obvious what you need to do to use it natively. 这段代码是Cordova插件的一部分,但是你需要做的就是本机使用它。

THE IMPORTANT LINES 重要的线索

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

Regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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