ACTION_SEND를 통해 Android 앱에서 Facebook에 텍스트 공유
Android 앱이 있으며 다른 앱을 통한 문자 전송을 지원합니다. 따라서 ACTION_SEND 인 텐트와 EXTRA_TEXT 필드를 사용합니다. 선택기는 그러한 의도를 처리 할 수있는 모든 앱을 제공합니다. Twitter, EMail, ... 및 Facebook입니다. 하지만 Facebook을 선택하면 브라우저가 열리고 다음 페이지로 이동합니다.
http://m.facebook.com/sharer.php?u=mytext
내 텍스트와 제출 버튼이 표시됩니다. 그러나 제출 버튼을 눌렀을 때 아무 일도 일어나지 않았습니다. 페이지가 다시로드됩니다. Facebook 앱을 통해서만 URL을 보낼 수 있다고 생각합니다. 그럴 수 있습니까?
Facebook Android 앱을 통해 ACTION_SEND를 통해 문자를 보낼 수있는 사람이 있습니까?
편집 됨 : Android 용 공식 Facebook 앱의 새 릴리스 (2011 년 7 월 14 일) IT WORKS !!!
OLD : 위의 예는 사용자가 공유를 위해 Facebook 앱을 선택한 경우 작동하지 않지만 사용자가 Facebook에 게시하기 위해 Seesmic 앱을 선택하면 작동합니다. 나는 Seesmic이 Facebook보다 Facebook API를 더 잘 구현했다고 생각합니다!
공유가 페이스 북 앱에서 작동하게하려면 최소한 하나의 링크 만 있으면됩니다.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Wonderful search engine http://www.google.fr/");
startActivity(Intent.createChooser(intent, "Share with"));
올바른 공유 창이 표시되지만 공유를 클릭하면 아무 일도 일어나지 않습니다 (공식 Twitter 앱에서도 시도했지만 작동하지 않습니다).
Facebook 앱 공유가 작동하도록하는 유일한 방법은 텍스트없이 링크 만 공유하는 것입니다.
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "http://www.google.fr/");
startActivity(Intent.createChooser(intent, "Share with"));
다음 창이 표시되고 공유 버튼이 작동합니다.
분명히 공유를 채우기 위해 링크에서 이미지와 텍스트를 자동으로 가져옵니다.
If you want to share only text, you will have to use the facebook api: https://github.com/facebook/facebook-android-sdk
06/2013 :
- This is a bug from Facebook, not your code
- Facebook will NOT fix this bug, they say it is "by design" that they broke the Android share system : https://developers.facebook.com/bugs/332619626816423
- use the SDK or share only URL.
- Tips: you could cheat a little using the web page title as text for the post.
First you need query Intent to handler sharing option. Then use package name to filter Intent then we will have only one Intent that handler sharing option!
Share via Facebook
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Content to share");
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains("facebook")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
Bonus - Share via Twitter
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Content to share");
PackageManager pm = v.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
v.getContext().startActivity(shareIntent);
break;
}
}
And if you want to find how to share via another sharing application, find it there Tép Blog - Advance share via Android
So I have a work around, but it assumes you have control over the page you're sharing...
If you format your EXTRA_TEXT like so...
String myText = "Hey!\nThis is a neat pic!";
String extraText = "http://www.example.com/myPicPage.html?extraText=\n\n" + myText;
... then on non-Facebook apps, your text should appear something like this:
http://www.example.com/myPicPage.html?extraText=
Hey!
This is a neat pic!
Now if you update your website such that requests with the extraText query parameter return the contents of extraText in the page's meta data.
<!-- Make sure to sanitize your inputs! e.g. http://xkcd.com/327/ -->
<meta name="title" content="Hey! this is a neat pic!">
Then when Facebook escapes that url to generate the dialog, it'll read the title meta data and embed it into your share dialog.
I realize this is a pretty yuck solution, so take with a grain of salt...
It appears that the Facebook app handles this intent incorrectly. The most reliable way seems to be to use the Facebook API for Android.
The SDK is at this link: http://github.com/facebook/facebook-android-sdk
Under 'usage', there is this:
Display a Facebook dialog.
The SDK supports several WebView html dialogs for user interactions, such as creating a wall post. This is intended to provided quick Facebook functionality without having to implement a native Android UI and pass data to facebook directly though the APIs.
This seems like the best way to do it -- display a dialog that will post to the wall. The only issue is that they may have to log in first
Check this out : By this we can check activity results also....
// Open all sharing option for user
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, ShortDesc+" from "+BusinessName);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, ShortDesc+" "+ShareURL);
sharingIntent.putExtra(Intent.EXTRA_TITLE, ShortDesc+" "+ShareURL);
startActivityForResult(Intent.createChooser(sharingIntent, "Share via"),1000);
/**
* Get the result when we share any data to another activity
* */
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case 1000:
if(resultCode == RESULT_OK)
Toast.makeText(getApplicationContext(), "Activity 1 returned OK", Toast.LENGTH_LONG).show();
else
Toast.makeText(getApplicationContext(), "Activity 1 returned NOT OK", Toast.LENGTH_LONG).show();
break;
case 1002:
if(resultCode == RESULT_OK)
Toast.makeText(getApplicationContext(), "Activity 2 returned OK", Toast.LENGTH_LONG).show();
break;
}// end switch
}// end onActivityResult
ShareDialog shareDialog = new ShareDialog(this);
if(ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder().setContentTitle(strTitle).setContentDescription(strDescription)
.setContentUrl(Uri.parse(strNewsHtmlUrl))
.build();
shareDialog.show(linkContent);
}
It appears that it's a bug in the Facebook app that was reported in April 2011 and has still yet to be fixed by the Android Facebook developers.
The only work around for the moment is to use their SDK.
텍스트를 표시 하려면 원하는 메시지를 구걸 할 때 # 을 입력하세요. Hashtag로 공유합니다.
참고 URL : https://stackoverflow.com/questions/3515198/share-text-on-facebook-from-android-app-via-action-send
'development' 카테고리의 다른 글
if 문-단락 평가 대 가독성 (0) | 2020.09.04 |
---|---|
부트 스트랩에는 여전히 외부 지원이 필요합니다. (0) | 2020.09.03 |
mongodb 여러 배열 항목으로 찾기 (0) | 2020.09.03 |
Git Bash가 내 PATH를 보지 못함 (0) | 2020.09.03 |
자바 스크립트는 어떻게 Blob을 업로드 할 수 있나요? (0) | 2020.09.03 |