2017-11-05 9 views
0

こんにちは私は、メニューの共有ボタンがonOptionsItemSelectedで選択されたときに呼び出すことができる共有インテントを作成しようとしています。共有ボタンを押すと、onOptionsItemSelectedが呼び出されますが、共有オプションは表示されません。ここで何がエラーか分かりますか?実装する方法は複数ありますが、なぜこれが機能していないのかを知りたいです。ここでメニューからインテントを共有

コードです:あなたが貼りスニペットで

public boolean onCreateOptionsMenu(Menu menu) { 
    /* Use AppCompatActivity's method getMenuInflater to get a handle on the menu inflater */ 
    MenuInflater inflater = getMenuInflater(); 
    /* Use the inflater's inflate method to inflate our menu layout to this menu */ 
    inflater.inflate(R.menu.detail, menu); 
    /* Return true so that the menu is displayed in the Toolbar */ 
    //MenuItem menuItem = menu.findItem(R.id.action_share); 
    //menuItem.setIntent(createShareForecastIntent()); 

    return true; 
} 


@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    int id = item.getItemId(); 

    String message = "Yes I am here"; 


    // TODO (2) Launch the map when the map menu item is clicked 
    if(id == R.id.action_share) { 
     Toast.makeText(this, message, Toast.LENGTH_LONG).show(); 

     item.setIntent(createShareForecastIntent()); 
     return true; 
    } 


    return super.onOptionsItemSelected(item); 
} 

private Intent createShareForecastIntent() { 
    Intent shareIntent = ShareCompat.IntentBuilder.from(this) 
      .setType("text/plain") 
      .setText(mForecast + FORECAST_SHARE_HASHTAG) 
      .getIntent(); 
    return shareIntent; 
} 

} 

答えて

0

、あなたは私がitem.setIntent(createShareForecastIntent())の後にonOptionsItemSelectedメソッドで追加する必要があり

mShareActionProvider.setShareIntent(shareIntent); 
+0

をcall-ことを忘れ?それは意図を作った後、私はそれを呼んでいますか? – sinay

関連する問題