I have following code for opening files programatically:
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, type);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
But now I need to set MIME-type of file, and it isn’t universal method for all files. Is there any mean for opening file through Intent without defining type?
Sure, just use
intent.setData(), instead ofintent.setDataAndType(). Although, the result may not be as desirable as when the type is defined.You can also use a convenience
Intentconstructor, and remove the “setData” call, like so: