Open third party app

前端 未结 3 1750
太阳男子
太阳男子 2021-01-16 00:27

I am developing an app that uses packagenames to start a Third Party App. I have done some research and found out that all apps can be started from a launcher intent. Are th

3条回答
  •  野的像风
    2021-01-16 00:54

    For above accepted answer, if the third party app is not installed on your emulator, you should gracefully handle it also. Here is a complete code for the same:

    public void openThirdPartyApp() {   
    
            Intent intent = new Intent("com.thirdparty.package");
                intent.setPackage("com.thirdparty.package");
    
                try {
                    ((Activity) context).startActivityForResult(intent, REQUEST_CODE);
                } catch (ActivityNotFoundException e) {
                    downloadIt();
                }
            }
    
        private void downloadIt() {
    
        Uri uri = Uri.parse("market://search?q=pname:" + "com.thirdparty.package");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    
                    try {
                        context.startActivity(intent);
                    } catch (ActivityNotFoundException e) {
        //creates a small window to notify there is no app available 
                    }   
    
                }
            }
    
        }
    

提交回复
热议问题