Java Android ShareActionProvider从gallery中选择图像并共享?

Java Android ShareActionProvider从gallery中选择图像并共享?,java,android,android-intent,sharing,shareactionprovider,Java,Android,Android Intent,Sharing,Shareactionprovider,因此,我花了两天时间试图弄明白如何使用ShareActionProvider通过android应用程序实现共享功能 public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_analyze, menu); MenuI

因此,我花了两天时间试图弄明白如何使用ShareActionProvider通过android应用程序实现共享功能

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_analyze, menu);
    MenuItem item = menu.findItem(R.id.action_share);
    // Fetch and store ShareActionProvider
    myShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
    // Set share Intent.
    // Note: You can set the share Intent afterwords if you don't want to set it right now.
    myShareActionProvider.setShareIntent(getDefaultShareIntent());
    return true;
}
假设我想共享一个以png结尾的文件格式的图像,下面是我应该使用的代码

private Intent getDefaultShareIntent(){
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);

sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
}
其中Uri.parse(path)中的路径是图像文件名

但是问题来了,我有一个单独的图片库,里面满是图片,文件夹名如下

String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/FolderName/" 
问题就在这里,我想让用户在/foldername/中选择一个图像,然后将文件名取出来,这样我就可以在Uri.parse(path)中解析它以进行共享

任何帮助都将不胜感激,谢谢。:)


干杯。

那么你需要一个文件选择器活动来从你的自定义位置拾取图像吗?嗨@Prerak Sola,我需要用户只在单击“共享操作”按钮时启用文件选择器活动,如果我要在OnCreateOptions菜单中创建活动,则默认情况下不启用此选项。因此,您需要一个文件选取器活动来从自定义位置选取图像?Hi@Prerak Sola,我需要用户仅在单击共享操作按钮时启用文件选取器活动,如果我要在OnCreateOptions菜单中创建活动,则在默认情况下启用该选项时不会出现。