gpt4 book ai didi

Android ShareActionProvider 图片问题

转载 作者:行者123 更新时间:2023-11-29 01:51:04 28 4
gpt4 key购买 nike

我正在尝试从我正在开发的应用程序发送图像,我有以下代码,但不知道如何从我的/drawable 文件夹中的文件创建 Uri,有什么想法吗? (此时很困惑)

@Override
public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.second, menu);
MenuItem shareitem = menu.findItem(R.id.menu_item_share);
myShareActionProvider = (ShareActionProvider) shareitem.getActionProvider();
myShareActionProvider.setShareIntent(createShareIntent());

ActionBar actionBar = getActionBar();
actionBar.show();
return true;

}

public Intent createShareIntent() {
image = ???
Uri uri = Uri.fromFile(image);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("image/png");
return shareIntent;
}

最佳答案

private Intent createShareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
Uri uri = Uri.parse("android.resource://your.package.name/" + R.drawable.image);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
return shareIntent;
}

关于Android ShareActionProvider 图片问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18038530/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com