开发者

Starting activity from Android app: view a text file

I'm working with an Android app that generates a text file and stores it on the sdcard. I would like to open the file in a text editor. The one开发者_开发问答 I have installed is Office Suite Professional.

I have the following code:

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setData(Uri.parse
    ("file:///sdcard/report.txt"));
startActivity(intent);

When I run this snippet of code, I get the following error:

Sorry! The application XXXX () has stopped unexpectedly. Please try again.

How can I get my app to load OfficeSuite Pro with a specific file?

Thanks Mike


First, you will want to use adb logcat, DDMS, or the DDMS perspective in Eclipse to examine LogCat and look at the stack trace associated with your error.

Had you done that, you would have seen an exception indicating that it could not find an activity to match your Intent.

In this case, you have one definite problem and one possible problem.

The definite problem is that you do not have a MIME type. Use setDataAndType() rather than setData(), with "text/plain" as the 2nd parameter.

The possible problem is that "OfficeSuite Pro" (whatever that is) may or may not know how to view text files.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜