如何共享语境中的操作栏使用ShareActionProvider多个文件? [英] How to share multiple files using ShareActionProvider in Contextual Action Bar?

查看:224
本文介绍了如何共享语境中的操作栏使用ShareActionProvider多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的活动一个ListView。在该列表视图中长preSS,我有上下文操作栏打开。它有一个共享选项共享通过Gmail / WhatsApp的列表中选定的项目(多可以选择项)/等。

<项目
        机器人:ID =@ + ID / menu_share
        机器人:标题=分享
        机器人:图标=@机器人:可绘制/ ic_menu_share
        机器人:actionProviderClass =android.widget.ShareActionProvider
        应用:showAsAction =ifRoom/>

这是菜单布局文件分享我的选择。

我有一个类实现ActionMode.Callback处理上下文操作栏和图标。

我初始化重写 onCreateActionMode(ActionMode模式,菜单菜单)内的ShareActionProvider对象共享菜单项。

  mShareActionProvider =(ShareActionProvider)menuItem.getActionProvider();

我的列表视图中包含文件名。
我的要求是,如果用户选择列表视图(第一长preSS再正常preSS为连续选择)多个项目,我应该能够分享所有这些文件。

我用的是下面这样一个意图(对应于列表视图中的文件名的所有文件的音频 - AMR文件)。

 意图shareIntent =新意图(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,uriList);
shareIntent.setType(音频/ AMR);

下面,uriList是尤里斯的ArrayList。现在我应该在哪里调用的方法 mShareActionProvider.setShareIntent(意向);

我不能把它在 onCreateActionMode(ActionMode模式,菜单菜单),因为用户可以在第一长$ P后,在列表中选择一些项目$ PSS。

如果我直接在 onActionItemClicked(ActionMode模式,菜单项项)称之为,我的分享图标似乎无效。

如果我把它在这两个 onCreateActionMode(ActionMode模式,菜单菜单) onActionItemClicked(ActionMode模式,菜单项的项目),共享意图似乎并没有被更新。请帮助..


解决方案

  

我不能把它在onCreateActionMode(ActionMode模式,菜单菜单),因为,用户可以第一长preSS后,在列表中选择一些更多的项目。


尝试调用它在那里,但也叫它的再次的在 onItemCheckedStateChanged(),当检查的项目变化的组合,提供了一个新的意图有更新的附加功能。

I am having a ListView in my Activity. On long press of that list view, I have the contextual action bar opened. It has a Share option to share the selected items in the list (multiple items can be selected) through gmail/whatsapp/etc.

<item android:id="@+id/menu_share" android:title="Share" android:icon="@android:drawable/ic_menu_share" android:actionProviderClass="android.widget.ShareActionProvider" app:showAsAction="ifRoom" />

this is my Share option in the menu layout file.

I have a class implementing ActionMode.Callback to handle the contextual action bar and its icons.

I initialized a ShareActionProvider object inside the overriden onCreateActionMode(ActionMode mode, Menu menu) for the Share menu item.

mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider();

My list view consists of filenames. My requirement is that, if the user selects multiple items in the list view (first long press and then normal press for successive selection) I should be able to share all those files.

I am using the below for such an intent (all files corresponding to the filenames in the listview are audio - amr files).

Intent shareIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,uriList);
shareIntent.setType("audio/AMR");

Here, uriList is an ArrayList of Uris. Now where should I call the method mShareActionProvider.setShareIntent(intent); ?

I can't call it in the onCreateActionMode(ActionMode mode, Menu menu) because, the user may select some more items in the list after the first long press.

If I call it directly in the onActionItemClicked(ActionMode mode, MenuItem item) , my Share icon seems to be inactive.

If I call it in both onCreateActionMode(ActionMode mode, Menu menu) and onActionItemClicked(ActionMode mode, MenuItem item) using the same intent, the share intent doesn't seem to be updated. Kindly help..

解决方案

I can't call it in the onCreateActionMode(ActionMode mode, Menu menu) because, the user may select some more items in the list after the first long press.

Try calling it there, but also call it again in onItemCheckedStateChanged(), when the mix of checked items changes, providing a new Intent that has the updated extras.

这篇关于如何共享语境中的操作栏使用ShareActionProvider多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆