我正在尝试在应用程序上实现共享图标以及我的溢出菜单。但是共享图标是灰色的,我无法单击它。
我的菜单 XML:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menu_item_share"
android:showAsAction="ifRoom"
android:title="Share"
android:icon="@drawable/ic_action_share"
android:actionProviderClass="android.widget.ShareActionProvider" />
<item
android:id="@+id/action_about"
android:orderInCategory="100"
android:showAsAction="never"
android:title="About"/>
<item
android:id="@+id/action_help"
android:orderInCategory="200"
android:showAsAction="never"
android:title="Help"/>
<item
android:id="@+id/action_rate"
android:orderInCategory="300"
android:showAsAction="never"
android:title="Rate"/>
</menu>
我的菜单 Java 代码:
@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);
MenuItem item = menu.findItem(R.id.menu_item_share);
mShareActionProvider = (ShareActionProvider) item.getActionProvider();
String strMsg = "Blood Pressure is: \t\t" + tvSVal.getText().toString() + "/" + tvDVal.getText().toString();
Intent myIntent5 = new Intent();
myIntent5.setAction(Intent.ACTION_SEND);
myIntent5.putExtra(Intent.EXTRA_TEXT, strMsg);
myIntent5.setType("text/plain");
mShareActionProvider.setShareIntent(myIntent5);
return true;
}
private void setShareIntent(Intent shareIntent) {
if (mShareActionProvider != null) {
mShareActionProvider.setShareIntent(shareIntent);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_help:
//display the help activity
Intent myIntent2 = new Intent(getApplicationContext(), HelpFile.class);
startActivityForResult(myIntent2, 0);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_out);
return true;
case R.id.action_about:
//display the about window
Log.i("Opening About Activity", "ABOUT");
Intent myIntent = new Intent(MainActivity.this, AboutApp.class);
startActivityForResult(myIntent, 0);
overridePendingTransition(R.anim.right_slide_in, R.anim.right_slide_out);
return true;
case R.id.action_rate:
//Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_VIEW);
//Try Google play
intent.setData(Uri.parse("market://details?id=com.test.testing"));
if (MyStartActivity(intent) == false) {
//Market (Google play) app seems not installed, let's try to open a web browser
intent.setData(Uri.parse("https://play.google.com/store/apps/details?com.test.testing"));
if (MyStartActivity(intent) == false) {
//Well if this also fails, we have run out of options, inform the user.
//let the user know nothing was successful
}
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private boolean MyStartActivity(Intent aIntent) {
try
{
startActivity(aIntent);
return true;
}
catch (ActivityNotFoundException e)
{
return false;
}
}
我收到以下警告:The method setShareIntent(Intent) from the type MainActivity is never used locally
请帮我解决它。