2014-07-12 71 views
0

我是新的android系统,我在分享内容时遇到了一些问题。 我做了一个涉及测试的android应用程序。在过去的活动,我想提供共享通过shareintent用户结果的机会,这里的代码框架:在Facebook上分享文字/图像

display= (TextView) findViewById (R.id.tvDisplay); 
    display.setText("Well Done, your score is" + score); //score is an int 
    sharebutton= (Button)findViewById(R.id.sharebutton); 
    sharebutton.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      results = display.getText().toString(); 
      Intent shareIntent = new Intent(Intent.ACTION_SEND); 
      shareIntent.setType("text/plain"); 
      shareIntent.putExtra(Intent.EXTRA_TEXT,"My score in the test is" + results); 
      shareIntent.putExtra(Intent.EXTRA_SUBJECT, "TEST"); 
      startActivity(Intent.createChooser(shareIntent, "Share..")); 
     } 
    }); 

的问题是,当我按一下按钮,我可以分享的确切所有共享工具(电子邮件,wapp等)中的文本,但不通过Facebook。为什么? 我试图允许发布图像和文字在FB墙上,但我无法给出可绘制文件夹上的图像的确切路径。 谢谢你的所有建议。在SD卡,然后共享图像

+0

看看这个:http://stackoverflow.com/questions/24709929/share-image-is-not-working-via-action-send/24710176#24710176 –

+0

嗨,我试过你的尝试,但它doesn'吨工作。当我点击FB图标时,我只能在我的FB墙上张贴一些东西,而不张贴图像。我写了File myFile = new File(Environment.getExternalStorageDirectory()+“/ ic_launcher.png”); - 我试图张贴启动器图标来测试它。 – Lordiron

回答

0

第一店面形象在Facebook上

File filePath = new File(Environment 
        .getExternalStorageDirectory(), 
        "/foldername/imagename.jpg"); 
      // share("facebook", filePath.toString()); 
      System.out.println(filePath); 
      List<Intent> targetedShareIntents = new ArrayList<Intent>(); 
      Intent share = new Intent(android.content.Intent.ACTION_SEND); 
      share.setType("image/jpeg"); 
      List<ResolveInfo> resInfo = getActivity().getPackageManager() 
        .queryIntentActivities(share, 0); 
      if (!resInfo.isEmpty()) { 
       for (ResolveInfo info : resInfo) { 
        Intent targetedShare = new Intent(
          android.content.Intent.ACTION_SEND); 
        targetedShare.setType("image/jpeg"); // put here your 
                  // mime 
        // type 
        if (info.activityInfo.packageName.toLowerCase() 
          .contains("facebook") 
          || info.activityInfo.name.toLowerCase() 
            .contains("facebook")) { 
         targetedShare.putExtra(Intent.EXTRA_SUBJECT, 
           "Sample Photo"); 
         targetedShare.putExtra(Intent.EXTRA_TEXT, 
           "This photo is created by App Name"); 
         targetedShare.putExtra(Intent.EXTRA_STREAM, 
           Uri.fromFile(filePath)); 
         targetedShare 
           .setPackage(info.activityInfo.packageName); 
         targetedShareIntents.add(targetedShare); 
        } 
       } 
       Intent chooserIntent = Intent.createChooser(
         targetedShareIntents.remove(0), 
         "Select app to share"); 
       chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, 
         targetedShareIntents.toArray(new Parcelable[] {})); 
       startActivity(chooserIntent); 
      } 
+0

它不起作用。有类似的问题。按一下按钮,我可以在FB墙上写字,但我无法分享图像或文字。 – Lordiron

0

这取决于Facebook的应用程序是否正在接受文本或不通过的意图,我知道他们接受的图像和位图文件,但文本他们不”接受它。我已经在我自己的项目之前尝试过了,但无法通过意向提供文本。

The Facebook application does not handle either the EXTRA_SUBJECT or EXTRA_TEXT fields. 

我已经回答了这个问题here。可能是你可以按照这个link的情况下,你需要参考。

+0

也许我不理解你的答案,但你告诉我,不可能通过FB共享文本或图像? – Lordiron

+0

它可以共享图像但不是文本 – Pankaj