检查第三方应用程序,如果未安装则打开

发布于 2024-11-25 01:22:50 字数 964 浏览 1 评论 0原文

我正在开发一个类,当用户选择该类时应该打开一个应用程序。如果该应用程序未安装,他们将单击“查找它”按钮并安装它。

这是我到目前为止所拥有的内容

public class calc extends Activity {
static final String MARKET_SEARCH_Q_PNAME_PROVIDER = "market://search?q=pname:com.packagename.package";



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.getpft);
    setTitle("Install Marine PFT?");

    ((Button) findViewById(R.id.Ok)).setOnClickListener(new Openpft());
    ((Button) findViewById(R.id.FindIt)).setOnClickListener(new FindZxingOnclickListener());
}

public class FindZxingOnclickListener implements OnClickListener {
    public void onClick(View v) {
        Intent marketLaunch = new Intent(Intent.ACTION_VIEW);
        marketLaunch.setData(Uri.parse(MARKET_SEARCH_Q_PNAME_PROVIDER));
        startActivity(marketLaunch);
    }}




    };

到目前为止,页面打开并且它正确搜索该应用程序。但是,现在应用程序已下载,我需要自动跳过此屏幕并仅打开该应用程序。这是怎么做到的?

I am working on a class that when selected by the user should open an application. If that application is not installed they will click the "Find it" button and install it.

Here is what I have so far

public class calc extends Activity {
static final String MARKET_SEARCH_Q_PNAME_PROVIDER = "market://search?q=pname:com.packagename.package";



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.getpft);
    setTitle("Install Marine PFT?");

    ((Button) findViewById(R.id.Ok)).setOnClickListener(new Openpft());
    ((Button) findViewById(R.id.FindIt)).setOnClickListener(new FindZxingOnclickListener());
}

public class FindZxingOnclickListener implements OnClickListener {
    public void onClick(View v) {
        Intent marketLaunch = new Intent(Intent.ACTION_VIEW);
        marketLaunch.setData(Uri.parse(MARKET_SEARCH_Q_PNAME_PROVIDER));
        startActivity(marketLaunch);
    }}




    };

So far the page opens up and it searches correctly for the app. However now that the app is downloaded I need to automatically skip this screen and just open that app. How is that done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁客 2024-12-02 01:22:50

不知何故,您正在启动该应用程序。据推测,您有一个 Intent 传递给 startActivity() 来执行此操作。如果是这样,您有两个选择:

  1. 只需调用 startActivity() 并路由到 ActivityNotFoundException catch 块中的上述代码 p>

  2. 使用 PackageManagerqueryIntentActivities() 查看是否有任何内容会响应您的 Intent,如果没有,则路由到您的上述代码,而不先调用 startActivity()< /p>

Somehow, you are launching that app. Presumably, you have an Intent that you are passing to startActivity() that does this. If so, you have two choices:

  1. Just call startActivity() and route to your above code in the ActivityNotFoundException catch block

  2. Use PackageManager and queryIntentActivities() to see if anything will respond to your Intent, and if not, route to your above code without calling startActivity() first

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文