How to remove Messenger Icon from Action Bar - android

I Action Bar i am using ShareActionProvider, but facing small issue, i am also getting Messenger Icon along with Share Icon, and i don't want to show Messenger Icon in my Action Bar.
So how can i remove Messenger Icon from Action Bar, see my code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_item_share).getActionProvider();
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(getDefaultShareIntent());
}
return super.onCreateOptionsMenu(menu);
}
private Intent getDefaultShareIntent(){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "SUBJECT");
intent.putExtra(Intent.EXTRA_TEXT, "TEXT");
return intent;
}
I just want to show Share Icon in my Action Bar not Messenger Icon...
see screen shot:

You are welcome to try setShareHistoryFileName(null) and see if that blocks the second icon along with the history.
Otherwise, you will need to write your own action provider as a replacement for ShareActionProvider. Or, you will need to attempt to fork ShareActionProvider to block this second icon.

Create a menu in layout in this way:
<item
android:showAsAction="always"
android:icon="#drawable/share_icon"/>
When you click on it you can show the default sharing sources.

Related

Android: SharingActionView on swipe from bottom

I would like to share data with other Apps, but I don't want the standard popup which appears bottom tool bar; I want this kind of view:
I followed the official document: https://developer.android.com/training/sharing/shareaction.html
So is there a native component to do that in Android SDK? Or is there any library to do that?
thank for your help guys!
You can do it like this :
First create a menu item :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.rashish.myapplication.MainActivity">
<item
android:id="#+id/action_share"
android:orderInCategory="100"
android:title="#string/action_settings"
android:icon="#android:drawable/ic_menu_share"
app:showAsAction="always" />
</menu>
Then create a method to show the Intent chooser dialog, like this :
private void share() {
String textToShare = "hello";
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
// set the type here i.e, text/image/ etc.
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(Intent.EXTRA_TEXT, textToShare);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
Then in the onOptionsItemSelected method, call this function when the menu item is clicked :
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here.
int id = item.getItemId();
if (id == R.id.action_share) {
share();
return true;
}
return super.onOptionsItemSelected(item);
}
Also make sure you've overriden onCreateOptionsMenu in your Activity like this :
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
Here's the output :
screenshot from an android device
In Android OS Lollipop google has change their share intent design. So to get this design you should have lollipop version and above.
Update:
private void setShareIntent(Intent shareIntent) {
if (mShareActionProvider != null) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
File photoFile = new File(getFilesDir(), "foo.jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
mShareActionProvider.setShareIntent(shareIntent);
}
}
try like this.

ShareActionProvider from support.v7 not clicking

I am trying to get a working "share" button on the title bar. Initially, I followed the advice on developers.android.com for this, but got an exception saying that I needed to use MenuItemCompat. I am doing so, but now my share button won't even "click".
My relevant code is:
public boolean onCreateOptionsMenu(Menu menu) {
Log.d("CYCLE:","onCreateOptionsMenu()");
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_to_do_list, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.action_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
setShareIntent();
mShareActionProvider.setShareHistoryFileName("my_share_history.xml");
return true;
}
public void setShareIntent(){
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "some text to share");
mShareActionProvider.setShareIntent(shareIntent);
}
and my menu item in XML is:
<item android:id="#+id/action_share"
android:title="Share"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
am I missing something to make this button be clickable? (I am not even talking about functionality yet. Simply the ability to be clicked (you know, like with the clicking/tapping animation).
thanks.
Have you set share Intent? Without the share Intent, Android would not know what exactly need to be shared by the provider.

ShareActionProvider doesn't share text from Intent with Facebook

I'm using a ShareActionProvider(android.widget.ShareActionProvider) to share simple text.
It works fine with Gmail, WhatsApp etc but not with Facebook...
It doesn't share the text attached to the Intent, instead it just ask the user to write a new post.
How to solve this?
Here is my code:
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>
Java:
#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;
}
Thanks!!
Unfortunately, you can't solve it. Facebook does not handle the EXTRA_TEXT field. You can check this bug report page.
There is a middle solution. It is true FB doesn't share TEXTS. They say that it is an attack to the freedom of expression of the User. But, you have a solution. You may pass a link. Then FB translate the "Intent" to a image and a link, and it added to the future response. But it leave blank the User writing space...
For example try:
shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");

Adding a "share" button to share the app on social networks

I have an app, and I'd like to add a share button to it. Once the button is clicked, I'd like it to open the following window:
Then the user will choose where to share it and it will display the following default message:
"Just found this great app! Find it here: https://play.google.com/store/apps/details?id=com.ideashower.readitlater.pro"
Solution 1: Launch ACTION_SEND Intent
When launching a SEND intent, you should usually wrap it in a chooser (through createChooser(Intent, CharSequence)), which will give the proper interface for the user to pick how to send your data and allow you to specify a prompt indicating what they are doing.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
# change the type of data you need to share,
# for image use "image/*"
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, URL_TO_SHARE);
startActivity(Intent.createChooser(intent, "Share"));
Solution 2: Use ShareActionProvider
If you are just looking to add a Share button in Overflow Menu, also have a look at ShareActionProvider.
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.share, menu);
MenuItem item = menu.findItem(R.id.share_item);
actionProvider = (ShareActionProvider) item.getActionProvider();
// Create the share Intent
String shareText = URL_TO_SHARE;
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType("text/plain").setText(shareText).getIntent();
actionProvider.setShareIntent(shareIntent);
return true;
}
Hope this helps. :)
As explained on Android Developers on this link: http://developer.android.com/training/sharing/shareaction.html
you have to add this menu item:
<item
android:id="#+id/menu_item_share"
android:showAsAction="ifRoom"
android:title="Share"
android:actionProviderClass=
"android.widget.ShareActionProvider" />
Then add the following code in Activity:
private ShareActionProvider mShareActionProvider;
...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate menu resource file.
getMenuInflater().inflate(R.menu.share_menu, menu);
// Locate MenuItem with ShareActionProvider
MenuItem item = menu.findItem(R.id.menu_item_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
// Return true to display menu
return true;
}
// Call to update the share intent
private void setShareIntent(Intent shareIntent) {
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(shareIntent);
}
}

Action bar sherlock : two bars ? (menu at bottom / search bar on top)

In my application, I have created a class Base_Activity extending SherlockFragmentActivity in which I have defined an action bar this way (it is a menu bar with three different items):
public class Base_Activity extends SherlockFragmentActivity {
private ActionBar mActionBar;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getSupportMenuInflater().inflate(R.menu.main, menu);
mActionBar = getSupportActionBar();
mActionBar.setDisplayUseLogoEnabled(false);
mActionBar.setDisplayShowCustomEnabled(true);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
Intent i = new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
return true;
case R.id.map:
Intent ii = new Intent(this, MainActivity.class);
ii.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(ii);
return true;
case R.id.favorites:
Intent iii = new Intent(this, FavoritesListView.class);
iii.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(iii);
return true;
default:
return super.onOptionsItemSelected(item);
}
} }
Then I have added this line to set this bar in the bottom of my application :
android:uiOptions="splitActionBarWhenNarrow"
It's working well, so far I don't have any problems : I have my bottom action bar with listener for every button.
I now want to add a top action bar, with a SearchBar (or SearchWidget) and a item opening a submenu in the up-right corner.
My problem is now : at the top of every activity, instead of the useless bar with the name of each activity, I want to have another top bar with :
1/ A search bar
2/ An icon opening a sub-menu in the up-right corner.
Unfortunately, I often read that it's not really possible but many application do use this. I am really having a hard time finding how to add my search bar, which doesn't make sense : I know how to write my query method, I have my databaseAdapter and Helper class, so basically it's just about displaying a simple search bar on the top, putting a listener and sending my query to the database and then display a list view.
Does anyone know something which can do the trick to keep an action bar on the bottom and have a search bar also on the top ? Thanks !
See my question. I think will answer for your first question. Second is very similar to this what I need.

Categories

Resources