我可以通过以下代码将路径传递给另一个类
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作为返回值
答案 0 :(得分:1)
我将getPath更改为
String path = FileUtils.getPath(getActivity(), imageUri);