简体   繁体   English

如何检查 zoom.us 和 Slack 应用程序是否安装在 Android 上?

[英]How to check if zoom.us and Slack apps are installed on Android?

I'm trying to create an app in Android where a user can install zoom.us and Slack apps and run them but I need to check before installation if the app is already installed or not.我正在尝试在 Android 中创建一个应用程序,用户可以在其中安装 zoom.us 和 Slack 应用程序并运行它们,但我需要在安装前检查该应用程序是否已安装。 The problem is I don't know the names of the packages so I can check against them, What would be the name of packages for zoom.us and slack and How would I run them by click of zoom and slack buttons?问题是我不知道包的名称,所以我可以检查它们,zoom.us 和 slack 的包的名称是什么,我将如何通过单击缩放和松弛按钮来运行它们?

public class MainActivity extends AppCompatActivity {

        ImageButton zoom, slack;
        Button installZoom, installSlack;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            // Install zoom
            installZoom = (Button) findViewById(R.id.inst_zoom);
            if (isZoomClientInstalled(getApplicationContext())) {
                installZoom.setEnabled(false);
            } else {
                installZoom.setEnabled(true);

                installZoom.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.addCategory(Intent.CATEGORY_BROWSABLE);
                        intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=us.zoom.videomeetings"));
                        startActivity(intent);
                    }
                });
            }
            // Run zoom
            zoom = (ImageButton) findViewById(R.id.app_zoom);
            zoom.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {               
                    Toast.makeText(getApplicationContext(), "About to run zoom", Toast.LENGTH_SHORT).show();
                }
            });

            // Install Slack
            installSlack = (Button) findViewById(R.id.inst_slack);
            if (isSlckClientInstalled(getApplicationContext())) {
                installSlack.setEnabled(false);
            } else {
                installSlack.setEnabled(true);

                installSlack.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_VIEW);
                        intent.addCategory(Intent.CATEGORY_BROWSABLE);
                        intent.setData(Uri.parse("https://slack.com/downloads/android"));
                        startActivity(intent);
                    }
                });
            }

            // Run Slack
            slack = (ImageButton) findViewById(R.id.app_slack);
            slack.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getApplicationContext(), "About to run Slack", Toast.LENGTH_SHORT).show();
                }
            });

        }// End of Create();

        // Determine whether the zoom for Android client is installed on this device.
        public boolean isZoomClientInstalled(Context myContext) {
            PackageManager myPackageMgr = myContext.getPackageManager();
            try {
                myPackageMgr.getPackageInfo("???.???.??", PackageManager.GET_ACTIVITIES);
            } catch (PackageManager.NameNotFoundException e) {
                return (false);
            }
            return (true);
        }

        // Determine whether the Slack for Android client is installed on this device.
        public boolean isSlackClientInstalled(Context myContext) {
            PackageManager myPackageMgr = myContext.getPackageManager();
            try {
                myPackageMgr.getPackageInfo("???.???.??", PackageManager.GET_ACTIVITIES);
            } catch (PackageManager.NameNotFoundException e) {
                return (false);
            }
            return (true);
        }

}// End of class

you may find app package by looking into Google Play link您可以通过查看 Google Play 链接找到应用程序包

https://play.google.com/store/apps/details?id=com.Slack

com.Slack is package name here. com.Slack 是这里的包名。 us.zoom.videomeetings for Zoom.用于 Zoom 的 us.zoom.videomeetings。 Then you just start it with Intent.然后你只需用 Intent 启动它。 Try it.尝试一下。

If you know the package name for the app, then you can check that if that app is installed on the device or not.如果您知道应用程序的包名称,那么您可以检查该应用程序是否安装在设备上。

PACKAGE NAMES:包名:

Zoom.Us : us.zoom.videomeetings Slack : com.Slack Zoom.Us:us.zoom.videomeetings懈怠:com.Slack

You know the code for it as stated in the comments.您知道注释中所述的代码。 By running it you will know if the app is installed on the device or not.通过运行它,您将知道该应用程序是否安装在设备上。

To check if app is installed or not, you need to know the package name of the app you want to check.要检查是否安装了应用程序,您需要知道要检查的应用程序的包名称。 You can find the package name of the app from Google play store, focus on URL.您可以在 Google Play 商店中找到应用程序的包名称,重点是 URL。 Id in URL is the package name. URL 中的 ID 是包名称。

For Example for Zoom.us it is: us.zoom.videomeetings例如 Zoom.us 是: us.zoom.videomeetings

在此处输入图片说明

Since both apps are well established, it is highly unlikely they will update the package name.由于这两个应用程序都已完善,因此它们不太可能更新包名称。

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

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