.getMake(); を呼び出すと、クラスに問題があります。常に null を返すため、文字列「No Data」を取得します。uripath を使用して毎回最初の Toast を取得するため、Uri が null ではないことはわかっています。また、画像に「TAG_MAKE」というタグが付いていることも知っています(確認しました)。他のすべてのタグでも機能しませんでした。
何を変更すればよいですか?
public class ExifE { private Uri uri;
private ExifInterface exifI;
private Context context;
public ExifE(Context con) {
context = con;
SharedPreferences prefs = context.getSharedPreferences("prefs", context.MODE_PRIVATE);
uri = Uri.parse(myPrefs.getString("currentImageUri", "fail"));
Toast.makeText(context, uri.getPath(), Toast.LENGTH_SHORT).show();
try {
this.createExifI(uri.getPath());
} catch (IOException e) {
e.printStackTrace();
}
}
public void createExifI(String filePath) throws IOException {
this.exifI = new ExifInterface(filePath);
}
public String getMake() {
String make;
if (exifI.getAttribute(ExifInterface.TAG_MAKE) != null) {
make = exifI.getAttribute(ExifInterface.TAG_MAKE);
} else {
make = "No Data";
}
return make;
}
解決
ExifInterface の作成に問題がありました。を使用できませんuri.getPath();
。これを呼び出して、MediaStore パスではなく実際のファイルパスを取得する必要があります。
private String getRealPathFromURI(Uri contentURI, Activity activity) {
Cursor cursor = activity.getContentResolver().query(contentURI, null, null, null, null);
if (cursor == null) { // Source is Dropbox or other similar local file
// path
return contentURI.getPath();
} else {
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
}
}