Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent for editing plain text file with the installed file editor (if any)

I want my app to open a plain text file with any of the file editors installed on my terminal, but I keep getting this exception:

ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT dat=file:///sdcard/folder/file.txt } 

First I thought that I have no File editor installed, but if I use ASTRO file manager, I can get to open the file both with "File Editor" and "QuickOffice", so I think the problem is that I'm not using the right code...

Here is the code

Intent intent = new Intent(Intent.ACTION_EDIT); 
Uri uri = Uri.parse("file:///sdcard/folder/file.txt"); 
intent.setDataAndType(uri, "plain/text"); 
startActivity(intent);

What is more surprising is that if I use the path of a file that doesn't exist, it keeps raising the same exception...

Thanks

like image 608
Pedriyoo Avatar asked Dec 27 '10 15:12

Pedriyoo


People also ask

Which command will open the text editor to create or edit a file in Linux?

Create a File with Touch Command The easiest way to create a new file in Linux is by using the touch command. The ls command lists the contents of the current directory. Since no other directory was specified, the touch command created the file in the current directory.

How do you create a plain text file?

In a Windows Microsoft Word document, click the Save As button from the File menu. Select Save As Type from the drop-down list then select Plain Text (*. txt). Click the Save button and a File Conversion window will open.

How do I create a plain text file in Windows?

Windows 10 Microsoft provides a way of creating a new, blank text file using the right-click menu in File Explorer. Open File Explorer and navigate to the folder where you want to create the text file. Right-click in the folder and go to New > Text Document. The text file is given a default name, New Text Document.


1 Answers

The MIME type is text/plain.

like image 105
CommonsWare Avatar answered Nov 15 '22 15:11

CommonsWare