有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android ShareActionProvider从图库中选择图像并共享?

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

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中解析它。解析(路径)以进行共享

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

干杯


共 (0) 个答案