安卓分享选项菜单中开启时自动运行的应用程序第一次 [英] Android: Share option menu open automatically while app run first time
本文介绍了安卓分享选项菜单中开启时自动运行的应用程序第一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在绘图应用程序。在我有我把设施共享绘画图像。我的问题是,当我开始我的应用程序第一次份额菜单会自动打开,而不clickin上的菜单按钮。我想打开,当我上的菜单按钮,然后单击。
下面是我的code为menu.xml文件
<菜单的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目
机器人:ID =@ + ID / menu_item_share
机器人:showAsAction =ifRoom
机器人:标题=分享
机器人:actionProviderClass =
android.widget.ShareActionProvider/>
以下是一个code的Java文件。
公共布尔onCreateOptionsMenu(菜单菜单){
/ **充气当前活动的菜单与RES /菜单/ items.xml * /
。getMenuInflater()膨胀(R.menu.share_menu,菜单); / **掌握其ID的菜单项关联的actionprovider的份额* /
mShareActionProvider =(ShareActionProvider)menu.findItem(R.id.menu_item_share).getActionProvider(); / **设置一个共享意图* /
mShareActionProvider.setShareIntent(getDefaultShareIntent()); 返回super.onCreateOptionsMenu(菜单);
}私人意图getDefaultShareIntent(){
位图的位图= drawView.getDrawingCache();
字符串路径= Environment.getExternalStorageDirectory()getAbsolutePath()+ UUID.randomUUID()的toString()+PNG。。 的System.out.println(路径=+路径);
意图sharingIntent =新意图(Intent.ACTION_SEND);
乌里screenshotUri = Uri.parse(路径);
//乌里screenshotUri = Uri.fromFile(文件); sharingIntent.setType(图像/ PNG);
sharingIntent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
startActivity(Intent.createChooser(sharingIntent,分享图像使用));
返回sharingIntent;
}
解决方案
startActivity(Intent.createChooser(sharingIntent,分享图像使用));
注释此行
I am making drawing app. In my have i put the facility to share the drawing image. my problem is when i start my app first time share menu will open automatically without clickin on the menu button. I want to open when i click on the menu button.
Here is my code for menu.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:actionProviderClass=
"android.widget.ShareActionProvider"/>
Following is a code for java file.
public boolean onCreateOptionsMenu(Menu menu) {
/** Inflating the current activity's menu with res/menu/items.xml */
getMenuInflater().inflate(R.menu.share_menu, menu);
/** Getting the actionprovider associated with the menu item whose id is share */
mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_item_share).getActionProvider();
/** Setting a share intent */
mShareActionProvider.setShareIntent(getDefaultShareIntent());
return super.onCreateOptionsMenu(menu);
}
private Intent getDefaultShareIntent(){
Bitmap bitmap = drawView.getDrawingCache();
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + UUID.randomUUID().toString()+".png";
System.out.println("path="+path);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
//Uri screenshotUri = Uri.fromFile(file);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
return sharingIntent;
}
解决方案
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
comment this line
这篇关于安卓分享选项菜单中开启时自动运行的应用程序第一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文