I am trying to tag files on an android device to display later on a list based on user defined tags (e.g. Category , Description , Owner). I have used the widely recommended java NIO code for UserDefinedFileAttributes
The file path is found and is reported as valid , however
final UserDefinedFileAttributeView view = getFileAttributeView (path,
UserDefinedFileAttributeView.class);
always returns 'view' = null
What am I missing?
Perhaps UserDefinedFileAttributeView is not supported on all platforms / devices? I have tried this code on Android Studio emulator for Nexus 6 (API 28)
String MEDIA_PATH = Environment.getExternalStorageDirectory().getPath()
+ File.separator + "myEMR" + File.separator +
"Imported_Documents" ;
String uNewFileName = "MyFile";
public void setLocalFileAttributes() throws Exception {
Path path = Paths.get(MEDIA_PATH, uNewFileName);
final UserDefinedFileAttributeView view = getFileAttributeView(path,
UserDefinedFileAttributeView.class);
// The file attribute
final String category = "Category";
final String value = "UnCategorised";
final byte[] bytes = value.getBytes("UTF-8");
final ByteBuffer writeBuffer =
ByteBuffer.allocate(bytes.length);
writeBuffer.put(bytes);
writeBuffer.flip();
view.write(category, writeBuffer);
}