3
I wanted the item called also to appear on your side your image:
The result I would expect would be this:
Activity code with help from @Alexandre Strevenski:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.ShareActionProvider;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends Activity {
private ShareActionProvider mShareActionProvider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity_actions, menu);
MenuItem shareItem = menu.findItem(R.id.acao4);
mShareActionProvider = (ShareActionProvider)
MenuItemCompat.getActionProvider(shareItem);
mShareActionProvider.setShareIntent(getDefaultIntent());
return super.onCreateOptionsMenu(menu);
}
private Intent getDefaultIntent() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
return intent;
}
}
main_activity_actions.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/acao1"
android:icon="@android:drawable/ic_menu_delete"
android:showAsAction="ifRoom|withText"
android:title="deletar"/>
<item
android:id="@+id/acao2"
android:icon="@android:drawable/ic_menu_add"
android:showAsAction="ifRoom|withText"
android:title="adicionar"/>
<item
android:id="@+id/acao3"
android:icon="@android:drawable/ic_menu_camera"
android:showAsAction="ifRoom|withText"
android:title="camera"/>
<item
android:id="@+id/acao4"
android:icon="@android:drawable/ic_menu_call"
android:showAsAction="ifRoom|withText"
android:title="chamada"
yourapp:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
</menu>
Note: I already used android:actionProviderClass="android.support.v7.widget.Shareactionprovider" and also not sure.
Error log:
You’re talking specifically about
ShareActionProvider
or item/sub whatever you are doing?– Paulo Rodrigues