Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I am correct, this will be what you want in your manifest:</p> <pre><code>&lt;activity android:name=".NameOfYourActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.VIEW" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;data android:mimeType="text/plain" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; </code></pre> <p>For more information, read <a href="http://developer.android.com/guide/components/intents-filters.html" rel="nofollow">Intents and Intent Filters</a> from the developer website.</p> <p>Also, here is a sample of an activity you could use to display a file.</p> <pre><code>public class MIMEsActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Get the intent that has the information about the file. Intent sender = getIntent(); //In this example I'm simply displaying the file's contents //in a TextView. TextView view = (TextView) findViewById(R.id.textview); //Check to see if there was an intent sent. if(sender != null) { //Get the file. File file = new File(sender.getData().getPath()); /* DO STUFF HERE WITH THE FILE I load the text of the file and send it to the TextView. */ StringBuilder text = new StringBuilder(); try { BufferedReader br = new BufferedReader(new FileReader(file)); String line; while ((line = br.readLine()) != null) { text.append(line); text.append('\n'); } } catch (IOException e) { //You'll need to add proper error handling here } view.setText("PATH: " + sender.getData().getPath() + "\n\n" + text); //Done doing stuff. } //If an intent was not sent, do something else. else { view.setText("You did not get a file!"); } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload