我正在尝试使用以下工具与其他应用程序(例如Telegram、Whatapp等)共享文件:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("text/plain");
startActivity(sendIntent);如果uri来自ACTION_GET_CONTENT活动,它就会起作用。但是我只有一个要共享的文件的路径,如果我设置了:
uri = Uri.fromFile(new File(path))看起来一切正常,但是在最后一步没有发送文件。
如何从文件路径中获取有效的uri?
发布于 2021-02-17 16:10:38
希望这段代码能对你有所帮助!
ApplicationInfo api = getApplicationContext().getApplicationInfo();
String apkPath = api.sourceDir;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("application/vnd.android.package-archive");
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(apkPath)));
startActivity(Intent.createChooser(share, "Share Via"));https://stackoverflow.com/questions/65556548
复制相似问题