Can't Get Easy Share Action for Android
So I'm trying to add a simple action with share, but clicking on the share action doesn't show that the pop should appear.
It should look like this.
I am using appcompatv7 and toolbar instead of action bar
Here is my code
MENU-XML
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_item_share"
android:orderInCategory="100"
app:showAsAction="always"
android:icon="@drawable/ic_social_share"
android:title="Share"
android:actionProviderClass="android.widget.ShareActionProvider" />
<item
android:title="Add"
android:id="@+id/action_add_new_alarm"
android:orderInCategory="101"
android:icon="@android:drawable/ic_menu_add"
app:showAsAction="always"/>
ONCREATE, ONCREATEOPTIONS and OPTIONS SELECTED-JAVA
//all about the toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.view);
// Set an OnMenuItemClickListener to handle menu item clicks
toolbar.setOnMenuItemClickListener(
new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// Handle the menu item
switch (item.getItemId()) {
case R.id.action_add_new_alarm: {
startAlarmDetailsActivity(-1);
break;
}
}
return true;
}
});
// Inflate a menu to be displayed in the toolbar
toolbar.inflateMenu(R.menu.alarm_list);
toolbar.setTitle("MY APP");
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate menu resource file.
getMenuInflater().inflate(R.menu.alarm_list, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_new_alarm: {
startAlarmDetailsActivity(-1);
Log.i(TAG, "add button clicked");
return true;
}
case R.id.menu_item_share: {
Log.i(TAG, "share button clicked");
actionShare();
return true;
}
default:
return super.onOptionsItemSelected(item);
}
}
private void actionShare(){
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "my string");
i.putExtra(Intent.EXTRA_TEXT, "another string");
startActivity(i);
//Or like above will always display the chooser
//startActivity(Intent.createChooser(i, getResources().getText(R.string.share)));
}
Even Logcat doesn't show that I pressed the button
+3
source to share