samedi 16 mai 2015

Can't get Easy Share Action to work Android

So im trying to add an easy share action, but clicking on the share action doesn't show the pop supposed to appear.

It's kinda sort of supposed to look like this.

I'm using appcompatv7 and a tool bar instead of action bar

how its supposed to look like

Here is my code

MENU-XML

<menu xmlns:android="http://ift.tt/nIICcg"
xmlns:app="http://ift.tt/GEGVYd">

<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 a button

Aucun commentaire:

Enregistrer un commentaire