Intent to open Instagram user profile on Android

后端 未结 6 1622
清歌不尽
清歌不尽 2020-12-02 10:38

I\'m developing a social networking app and our users can connect their Instagram account to our service. I\'d like to open Instagram profiles directly in their official And

6条回答
  •  难免孤独
    2020-12-02 11:09

    Although @jhondge's solution works and is correct. This is a more cleaner way to do this:

    Uri uri = Uri.parse("http://instagram.com/_u/xxx");
        Intent insta = new Intent(Intent.ACTION_VIEW, uri);
        insta.setPackage("com.instagram.android");
    
        if (isIntentAvailable(mContext, insta)){
            startActivity(insta);
        } else{
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://instagram.com/xxx")));
        }
    
    private boolean isIntentAvailable(Context ctx, Intent intent) {
        final PackageManager packageManager = ctx.getPackageManager();
        List list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    }
    

提交回复
热议问题