2014-11-06 5 views
0

으로 의도에서 텍스트를 공유하지 않습니다. Gmail, WhatsApp 등에서는 Facebook에서는 작동하지 않지만 괜찮습니다.ShareActionProvider 내가 간단한 텍스트를 공유 할 ShareActionProvider (android.widget.ShareActionProvider)를 사용하고 페이스 북

Intent에 첨부 된 텍스트를 공유하지 않고 대신 사용자에게 새 게시물을 작성하도록 요청합니다.

해결 방법?

여기 내 코드입니다 :

XML :

<?xml version="1.0" encoding="utf-8"?> 
<menu xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<item android:id="@+id/action_share" 
    android:title="@string/action_share" 
    android:showAsAction="always" 
    android:actionProviderClass="android.widget.ShareActionProvider" /> 
</menu> 

자바 :

@Override 
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     inflater.inflate(R.menu.detailfragment, menu); 

     // Retrieve the share menu item 
     MenuItem share = menu.findItem(R.id.action_share); 
     // Get the provider and hold onto it to set/change the share intent. 
     mShareActionProvider = (ShareActionProvider) share.getActionProvider(); 

     // Attach an intent to this ShareActionProvider. You can update this at any time, 
     // like when the user selects a new piece of data they might like to share. 
     if (mShareActionProvider != null && mForecastStr != null) { 
      mShareActionProvider.setShareIntent(createShareIntent()); 
      Log.v(LOG_TAG, "mForecast: " + mForecastStr); 
      Log.v(LOG_TAG, "Intent: " + mShareActionProvider); 
     } else { 
      Log.d(LOG_TAG, "Share Action Provider is null?"); 
     } 
    } 


    public Intent createShareIntent() { 
     Intent shareIntent = new Intent(Intent.ACTION_SEND); 
     shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); 
     shareIntent.setType("text/plain"); 
     shareIntent.putExtra(Intent.EXTRA_TEXT, mForecastStr); 

     return shareIntent; 
    } 

감사합니다!

+0

"페이스 북에서 작동하지 않는 것"을 완전하고 정확하게 설명하십시오. – CommonsWare

+0

죄송합니다. 죄송합니다. 고마워!! – Makoto

답변

1

아쉽게도 해결할 수 없습니다. Facebook은 EXTRA_TEXT 필드를 처리하지 않습니다. this bug report page을 확인할 수 있습니다.

0

중간 해결 방법이 있습니다. 사실 FB는 텍스트를 공유하지 않습니다. 그들은 사용자의 표현의 자유에 대한 공격이라고 말합니다. 그러나 해결책이 있습니다. 링크를 전달할 수 있습니다. 그런 다음 FB는 "의도"를 이미지와 링크로 변환하고 향후 응답에 추가합니다. 하지만 공백으로 사용자 쓰기 공간을 남깁니다. 예를 들어보십시오 :

shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");