Android和Facebook共享意图我正在开发一个Android应用程序,我想知道如何使用Android的共享意图从应用程序内部更新应用程序用户的状态。在浏览了Facebook的SDK之后,看起来这很容易做到,但是我很想让用户通过常规的共享意图弹出窗口来做这件事?见此:我已经尝试了通常的共享意图代码,但这似乎不再适用于Facebook。public void invokeShare(Activity activity, String quote, String credit) {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, activity.getString(R.string.share_subject));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Example text");
activity.startActivity(Intent.createChooser(shareIntent, activity.getString(R.string.share_title)));}更新:在做了更多的调查之后,它看起来像是Facebook应用程序中的一个尚未解决的bug!Facebook bug)同时,看起来我不得不忍受负面的“分享不起作用!”评论。干杯Facebook:*(
3 回答
慕容森
TA贡献1853条经验 获得超18个赞
通常的方式
Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "The status update text"); startActivity(Intent.createChooser(intent, "Dialog title text"));
另一种方法(也许)
try { Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); String[] recipients = new String[]{"e-mail address"}; emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "E-mail subject"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "E-mail text"); emailIntent.setType("plain/text"); // This is incorrect MIME, but Gmail is one of the only apps that responds to it - this might need to be replaced with text/plain for Facebook final PackageManager pm = getPackageManager(); final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0); ResolveInfo best = null; for (final ResolveInfo info : matches) if (info.activityInfo.packageName.endsWith(".gm") || info.activityInfo.name.toLowerCase().contains("gmail")) best = info; if (best != null) emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name); startActivity(emailIntent); } catch (Exception e) { Toast.makeText(this, "Application not found", Toast.LENGTH_SHORT).show(); }
- 3 回答
- 0 关注
- 333 浏览
添加回答
举报
0/150
提交
取消