我是关于编程android的新手,我在共享内容时遇到了一些问题。 我做了一个涉及测试的Android应用程序。在上一个活动中,我想通过shareintent提供分享用户结果的机会,这里是代码框架:
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墙上发布图像和文本,但我无法给出可绘制文件夹上图像的确切路径。 感谢您的所有建议。
答案 0 :(得分:0)
首先在SD卡中存储图像,然后在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);
}
答案 1 :(得分:0)