【问题标题】:Sharing photo on facebook using intent Android?使用 Intent Android 在 Facebook 上分享照片?
【发布时间】:2014-07-05 18:59:09
【问题描述】:

我想使用意图发送照片 我已经尝试过这段代码,但我的问题是,如果我使用这段代码进行共享,而不是打开所有与共享相关的应用程序,我只想打开 FACEBOOK 和 TWITTER APP 进行共享

Intent sharefacebook = new Intent(Intent.ACTION_SEND); 
            sharefacebook.setType("image/*");
            sharefacebook.putExtra(Intent.EXTRA_TEXT, "From Android");              
            sharefacebook.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+filepath.toString()));
            startActivity(Intent.createChooser(sharefacebook, "Sharing"));

它打开电子邮件、skype、gmail 一切我只想打开 facebook 和 twitter 这是可能的

【问题讨论】:

    标签: android facebook image android-intent twitter


    【解决方案1】:

    您可以查询客户端应用程序(活动)并仅在它是这样的 fb/twitter 客户端时启动活动:

       final PackageManager pm = getPackageManager();
                        final List<ResolveInfo> matches = pm.queryIntentActivities(shareIntent, 0);
                for (final ResolveInfo info : matches){
                    if (info.activityInfo.name.toLowerCase().contains("facebook") || info.activityInfo.name.toLowerCase().contains("twitter")){ 
            Intent sharefacebook = new Intent(Intent.ACTION_SEND); 
                        sharefacebook.setType("image/*");
                        sharefacebook.putExtra(Intent.EXTRA_TEXT, "From Android");              
                        sharefacebook.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+filepath.toString()));                              
                       startActivity(Intent.createChooser(sharefacebook, "Sharing"));   
                }else{
                                    Toast.makeText(getApplicationContext(), "FB or twitter client not installed", Toast.LENGTH_SHORT).show();
    
                }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-19
      • 2013-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多