我可以通过以下代码将路径传递给另一个类
private void sendImageFromCameraIntent() {
Intent intent = getActivity().getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type.startsWith("image/")) {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
String path = imageUri.getPath();
Toast.makeText(getContext(), path, Toast.LENGTH_SHORT).show();
imageShared = true;
inputPanel.sendImage(path);
}
}
}
但在另一个类中,以下检查失败
public int sendImage(String path) {
if (path != null && new File(path).isFile()) {
// code to send image - works fine when adding an attachment
return 1;
}
else return -1
路径显示在 toast 中,但我得到一个 -1 作为返回值
最佳答案
我将 getPath 更改为
String path = FileUtils.getPath(getActivity(), imageUri);
关于android - 无法正确获取 "android.intent.action.SEND" Intent 的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26137128/