Action bar share button not working after upload on playstore - android

App share button on action bar is not working after i upload the app update on the play store as it works on the testing devices and also works on emulator.. ?
thank you in advance .
Circled part is not working after uploading on play store
Activity:
public class RecommendetableActivity extends AppCompatActivity {
Button button;
Intent ShareIntent;
ShareActionProvider mShareActionProvider;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.recommended_table);
ShareIntent = new Intent();
ShareIntent.setAction(Intent.ACTION_SEND);
ShareIntent.setType("text/plain");
ShareIntent.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/............app name ");
button = (Button)findViewById(R.id.close_button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
overridePendingTransition(R.anim.backfadein, R.anim.backfadeout);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.popup_menu, menu);
MenuItem item = menu.findItem(R.id.menu_item_share);
// Get its ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
// Connect the dots: give the ShareActionProvider its Share Intent
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(ShareIntent);
}
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
overridePendingTransition(R.anim.backfadein, R.anim.backfadeout);
return true;
}
return false;
}
#Override
public void onBackPressed() {
finish();
overridePendingTransition(R.anim.backfadein, R.anim.backfadeout);
super.onBackPressed();
}
}
popup_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<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:title=""
app:showAsAction="always"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
/>
</menu>

I had this issue as well once and after some digging inside the Logcat of Play store ready APK, I found the problem; it might apply to you as well.
The Issue was NoClassDefFoundError exception on ShareActionProvider !
Solution is to add this rule to your ProGuard file such as proguard-rules.pro and that's it!
-keep class android.support.v7.widget.ShareActionProvider { *; }

Related

open a menu from OnClickListener

I want to open a menu from a OnClickListener
without using the method onCreateOptionsMenu
My code:
toolbar.setNavigationIcon(R.drawable.week); //your icon
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v ) {
}
});
Thanks in advance!
I think you want to show/hide a menu item based on actions from users. To do that you must use onCreateOptionsMenu and whenever you want to show/hide the menu item, then call invalidateOptionsMenu (this method will call onCreateOptionsMenu again).
boolean mShowMenu = false;
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.your_menu, menu);
MenuItem item = menu.findItem(R.id.your_menu_item);
item.setVisible(showMenu);
return true;
}
And in your code, when you want to show menu item.
toolbar.setNavigationIcon(R.drawable.week); //your icon
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v ) {
mShowMenu = true;
invalidateOptionsMenu();
}
});
And give it a try.
You should need to create menu Interface in xml File Like this
<item
android:id="#+id/settings"
android:title="Setting"
app:showAsAction="never" />
<item
android:id="#+id/my_activity"
android:title="My Activity"
app:showAsAction="always"
android:icon="#android:drawable/btn_radio"/>
After that in the Java code of a particular class You need to create the code like this;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.my_activity) {
Intent intent1 = new Intent(this,MyActivity.class);
this.startActivity(intent1);
return true;
}
if (id == R.id.settings) {
Toast.makeText(this, "Setting", Toast.LENGTH_LONG).show();
return true;
}
return super.onOptionsItemSelected(item);
}
Hopefully this may resolve your problem

Android not showing menu

I'm a new one in Android. I have some problems with showing menu. I don't see three dots in right corner in my screen. Please, help me to understand my mistake. THANK YOU A LOT!
Activity:
public class MainActivity extends AppCompatActivity {
private EditText numb1;
private EditText numb2;
private Button btn_sum;
private Button btn_extr;
private Button btn_mult;
private Button btn_div;
private TextView result;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*some code*/
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.reset:
numb1.setText("");
numb2.setText("");
break;
case R.id.exit:
fileList();
break;
}
return super.onOptionsItemSelected(item);
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/reset"
android:title="#string/reset"
app:showAsAction="never"/>
<item android:id="#+id/exit"
android:title="#string/exit"
app:showAsAction="never"/>
</menu>
Menu Items are not showing on Action Bar
Check this answer
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:title="#string/action_option1"/>
<item
android:id="#+id/action_settings34"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:title="#string/action_option2"/>
<item
android:id="#+id/action_settings3"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
android:title="#string/action_option3"/>
</menu>
Use this code in your activity, but you should have action bar in it.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.your_menu, menu);
return true;
}
if you run your application on oldest version of samsung or other the three DOTS is not appear on ActionBar
so try to click on Option Key on mobile
The solution to appear Three DOTS
call this method in your application class' onCreate method
private void makeActionOverflowMenuShown() {
//devices with hardware menu button (e.g. Samsung Note) don't show action overflow menu
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if (menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
Log.d(TAG, e.getLocalizedMessage());
}
}
i am also new to android i guess u wrote onCreateOptionsMenu(Menu menu) inside on create
try this
public class MainActivity extends AppCompatActivity {
private EditText numb1;
private EditText numb2;
private Button btn_sum;
private Button btn_extr;
private Button btn_mult;
private Button btn_div;
private TextView result;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*some code*/
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.reset:
numb1.setText("");
numb2.setText("");
break;
case R.id.exit:
fileList();
break;
}
return super.onOptionsItemSelected(item);
}
}
You have done the minor mistake while creating the option menu .you should call the onCreateOptionsMenu() and onOptionsItemSelected() method outside the onCreate(Bundle savedInstanceState) method. you may check the following example :
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.reset:
break;
case R.id.exit:
fileList();
break;
}
return super.onOptionsItemSelected(item);
} }
Help me to understand my mistake - Sure
The Main culprit is in your menu XML file app:showAsAction="never" this line replace this line with app:showAsAction="ifRoom"
here showAsAction is set to never means you tell that don't show my menu in action bar if you replace with "ifRoom" means you said show my all menu in action bar and if there is space for all my menus

share button in android app is not working when showAsAction is always or ifroom

I am working on an android webview app, i have added share action on action bar which works fine when showAsAction is 'never, but stop working as soon as i change it to 'always' or 'ifRoom'`
my code is:
private ShareActionProvider mShareActionProvider;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public final boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_share:
shareURL();
}
return super.onOptionsItemSelected(item);
}
private void shareURL() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
startActivity(Intent.createChooser(shareIntent, "Share This!"));
}
if someone could help, thank you.
Remove the android:actionProviderClass="android.widget.ShareActionProvider" and add the android:icon="#drawable/image-name"
Are you sure you actually have space to display it?
You could try disabling the title to see is that created enough room:
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Update:
Can you try using:
public void setOnMenuItemClickListener (Toolbar.OnMenuItemClickListener listener)
I believe the toolbar has a separate listener than the dropdown menu.
The code could look something like:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar tb = (Toolbar) findViewById(R.id.toolbar_id);
tb.inflateMenu(R.menu.menu);
tb.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
// Menu item should be returned here (the one you tap on the toolbar)
return false;
}
});
}

OptionMenu suddenly closes new activity on Android 4.1.1

Good morning,
i've an apps with a MainActivity with optionMenu that opens another activity ( A simple About page):
All works well on Android 4.2.1 (ASUS TF700T), selecting About open the Page with About Informations.
i've this strange behaviour on my Apps with Android 4.1.1 (ICONIA A210):
When i select the optionMenu, the new activity Opens, i see the about page, but suddenly closes and return on the Main Activity.
Anyone can help me to solve this strange problem: Here is the MainActivity code:
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.menu,menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id=item.getItemId();
switch(id)
{
case R.id.MENU_2:
Intent intent2 = new Intent(MainActivity.this, About.class);
startActivity(intent2);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
Here is the simple About Code:
public class About extends Activity {
Button backButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_main);
backButton = (Button) findViewById(R.id.button1);
backButton.setOnClickListener(new View.OnClickListener() {
// #Override
public void onClick(View v) {
About.super.onBackPressed();
}
});
}
Here is menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/MENU_2"
android:title="#string/about"
android:orderInCategory="110"
android:showAsAction="never"/>
</menu>
Anyone can help me to solve this problem ?
Why you are using: About.super.onBackPressed();?
instead of that just use: About.this.finish();

Adding settings to android app

This is definitely a noob question. I've followed the instructions here http://developer.android.com/guide/topics/ui/settings.html#Activity and when I click on settings, nothing happens.
Here's what I have in MainActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
}
Then I have a new java file called PrefsActivity.java
public class PrefsActivity extends PreferenceActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
} }
Then I have res/xml/preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="face_up"
android:title="#string/face_up"
android:summary="#string/face_up_desc"
android:defaultValue="false" />
</PreferenceScreen>
I am trying to make it compatible with minsdk 7 if possible. What am I missing?
You need to open your activity when you click on your settings button. If your using an action bar, use something like this:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
In your main Activity
// Ensure the right menu is setup
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
// Start your settings activity when a menu item is selected
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_settings) {
Intent settingsIntent = new Intent(this, PrefsActivity.class);
startActivity(settingsIntent);
}
return super.onOptionsItemSelected(item);
}

Categories

Resources