开发者

Opening a recently written file using Intents

We are downloading a file from a server a开发者_高级运维nd writing it to folder on sdcard. As soon as the write finishes, we perform a Media Scan on that folder. When the user tries to open the file for viewing, we try to leverage upon the Intent mechanism of Android and raise an Intent as follows:

Intent myIntent = new Intent(Intent.ACTION_VIEW,Uri.fromFile(tempFile));
// MIME_TYPE could be either of: image/*, video/*, audio/*, text/*
myIntent.setType(MIME_TYPE);
startActivity(Intent.createChooser(myIntent, "Open file using..."));

On emulator, the camera Application is launched for this Intent but the application crashes with NPE. And on MOTOROLA Milestone, we are getting a Toast which says: "No image to show". Note that the photo is actually displayed in Media Gallery of both emulator and phone as soon as the scan finishes.

Not sure what has been missed here; please help.


strangely, changing from

Intent myIntent = new Intent(Intent.ACTION_VIEW,Uri.fromFile(tempFile));
// MIME_TYPE could be either of: image/*, video/*, audio/*, text/*
myIntent.setType(MIME_TYPE);

to

Intent myIntent = new Intent(Intent.ACTION_VIEW);
// MIME_TYPE could be either of: image/*, video/*, audio/*, text/*
myIntent.setDataAndType(Uri.fromFile(tempFile), MIME_TYPE);

worked!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜