正如标题所暗示的,我想在 android 中通过 facebook/twitter 分享一些东西。如果安装了 facebook/twitter,我想通过 fb/twitter 应用程序分享帖子,否则我想将用户定向到浏览器. 我可以将用户引导至浏览器,这很容易,但我如何通过 fb/twitter 应用程序分享帖子?
谢谢..
(已编辑)我尝试过这样做,检查了 developers.facebook.com ,但是他们通过片段进行此操作。我想用默认活动来做。我已经尝试了下面的代码,但是我收到了类似的错误
W/dalvikvm(16093): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
W/dalvikvm(16093): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
W/dalvikvm(16093): VFY: unable to resolve static method 367: Landroid/support/v4/content/LocalBroadcastManager;.getInstance (Landroid/content/Context;)Landroid/support/v4/content/LocalBroadcastManager;
我在默认活动中使用的代码是:
private void publishStory() {
Session currentSession = Session.getActiveSession();
if (currentSession != null){
Bundle postParams = new Bundle();
postParams.putString("name", Commons.campaignname);
postParams.putString("display", "touch");
postParams.putString("link", Commons.campaignlink");
postParams.putString("picture",Commons.campaignimage);
Request.Callback callback= new Request.Callback() {
public void onCompleted(Response response) {
JSONObject graphResponse = response
.getGraphObject()
.getInnerJSONObject();
String postId = null;
try {
postId = graphResponse.getString("id");
} catch (JSONException e) {
Log.i("TAG",
"JSON error "+ e.getMessage());
}
FacebookRequestError error = response.getError();
if (error != null) {
Toast.makeText(getApplicationContext(),
error.getErrorMessage(),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
postId,
Toast.LENGTH_LONG).show();
}
}
};
Request request = new Request(currentSession, "me/feed", postParams,
HttpMethod.POST, callback);
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
}
private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
for (String string : subset) {
if (!superset.contains(string)) {
return false;
}
}
return true;
}