2012-06-01 12 views
5

Jeśli wysyłam tylko tekst, opcja wyboru intencji udostępniania NIE daje Facebooka/Twittera jako opcji.Android Share Intent Chooser - Udostępnianie TEKSTU z Facebookiem/Twitterem Social Media itp.

Tylko opcje Gmail, Skype i Evernote są opcjami.

Oto mój kod

Intent shareIntent = new Intent(Intent.ACTION_SEND); 

shareIntent.setType("plain/text"); 
shareIntent.putExtra(Intent.EXTRA_TEXT, text) 
startActivity(Intent.createChooser(shareIntent, "Share using")); 

Próbowałem różnych kombinacji setType() bez radości w tym "text/*", "text/html" i przechodzącej tekst HTML w putExtra następująco:

shareIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<p>This is the text that will be shared.</p>")); 

Kiedy używam "text/plain", Facebook pojawia się jako opcja, ale tekst nie ładuje się podczas wybierania. Ale tekst ładuje się na Twitterze, e-maile, SMS-y.

Czy ktoś jeszcze napotkał ten problem?

Po udostępnieniu obrazu nie ma problemu, a na liście znajdują się Facebook i inne aplikacje społecznościowe.

+0

Odpowiedź znaleźć tutaj http://stackoverflow.com/questions/3515198/share-text-on-facebook-from-android-app-via-action-send – tiptopjat

Odpowiedz

3

zależy to od tego, jakie filtry intencji są zdefiniowane przez każdą z tych aplikacji.
Na przykład jeśli dodam intent-filtr android.intent.action.send

Jeśli wybiorę jeden obraz z galerii moja aplikacja pojawi się na liście. Jeśli jednak zdecyduję się na wielokrotność, moja aplikacja nie pojawi się, ponieważ nie dodałem pliku intent-filer do android.intent.action.send_multiple

Zależy więc od tego, do jakich celów filtrowany jest facebook. Musisz zobaczyć informacje o wydaniu lub pomoc lub strony dla programistów.

+1

Znalazłem stronę, która dokładnie to omawia. Uwzględniając adres URL w moim tekście ciągu. NA PRZYKŁAD. "Cześć, sprawdź http://www.bbc.co.uk Facebook rozpoznaje ciąg znaków. O dziwo, tylko część adresu URL z napisem: Twitter rozpoznaje cały ciąg wraz z adresem URL: http://stackoverflow.com/questions/ 3515198/share-tekst-na-facebook-z-android-app-via-action-wysłać – tiptopjat

+0

bo takie są zamiary ich filtrowanie !!! – Orlymee

7

Również powinno być "tekst/zwykły", a nie "zwykły/tekst" zgodnie z dokumentacją.

+0

to, co było przyczyną problemu tutaj. Dzięki – jfcartier

2

Facebook kwestią jest ograniczenie uprawnień Facebooku. Użyj facebook API

1

Udostępnij przez Twitter:

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
shareIntent.setType("text/plain"); 

shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String)v.getTag(R.string.app_name)); 

shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String)v.getTag(R.drawable.ic_launcher)); 

// dla znalezienia nazwy pakietu twitter ---- >>

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; 
      } 
     } 

Share via Facebook

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
    shareIntent.setType("text/plain"); 
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,String)v.getTag(R.string.app_name)); 

    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, (String) 

v.getTag(R.drawable.ic_launcher)); 

// finding facebook package name 

    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; 
     } 
     } 

Podziel pośrednictwem Gmaila

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 

    shareIntent.setType("text/plain");   

shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT(String)v.getTag(R.string.app_name)); 

shareIntent.putExtra(android.content.Intent.EXTRA_TEXT(String)v.getTag(R.drawable.ic_launcher)); 

// finding gmail package name --- 

    PackageManager pm = v.getContext().getPackageManager(); 

    List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); 

     for (final ResolveInfo app : activityList) 
     { 
      if ((app.activityInfo.name).contains("gmail")) 
      { 
      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; 
      } 
     } 
Powiązane problemy