Neufman Neufman - 9 days ago 7
Android Question

Launching an intent for file : "Unable to find item"

I wish I could open any file type using mobile applications.

Here is the code :

File mFile = new File( file.getLocalPath() + file.getFileName() );
Log.i("path", file.getLocalPath() + file.getFileName());

if( mFile.exists() )
{
MimeTypeMap map = MimeTypeMap.getSingleton();
String ext = MimeTypeMap.getFileExtensionFromUrl(mFile.getName());
String type = map.getMimeTypeFromExtension(ext);

if (type == null)
type = "*/*";

Log.i("type", type);

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri data = Uri.fromFile(mFile);
Log.i("uri", data.toString());
intent.setDataAndType( data, type );

try {
startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
}
}


Logs :


  • Path :
    /data/data/com.package.name/files/sbx/523/filename.jpg

  • Type :
    image/jpeg

  • Uri :
    file:///data/data/com.package.name/files/sbx/523/filename.jpg



All logs are displayed therefore the file exists.
However, during the opening of the gallery, I get an
"Unable to find item"
.

Where is the problem ? Are there other solutions ?

Answer

The problem is that you are trying to open file which is in android private area thats why during the opening of the gallery, you get an "Unable to find item". You have to put your file in local. If you want to open a file of android private area you should be rooted.