Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy isn't my app on the list of apps to open txt file?
    primarykey
    data
    text
    <p>I have an text reader app that is designed to receive intent from Android system when I click on a text file to open it. But my app isn't on the list popped up by the system. Below are my codes:</p> <p>Manifest</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.broadcastreceivertest1" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:label="@string/app_name" android:name=".BroadcastReceiverTest1Activity" &gt; &lt;intent-filter &gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;receiver android:name="MyBroadcastReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.ACTION_VIEW" /&gt; &lt;action android:name="android.intent.action.ACTION_EDIT" /&gt; &lt;action android:name="android.intent.action.ACTION_PICK" /&gt; &lt;data android:scheme="file" /&gt; &lt;data android:mimeType="*/*" /&gt; &lt;data android:pathPattern=".*\\.txt" /&gt; &lt;data android:host="*" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>My extended BroadcastReceiver</p> <pre><code>public final class MyBroadcastReceiver extends BroadcastReceiver { private String TAG = "MyBroadcastReceiver"; @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Intent i = new Intent(context, BroadcastReceiverTest1Activity.class); i.putExtra("URI", intent.getData()); context.startActivity(i); Log.d(TAG, "Leaving onReceived..."); } } </code></pre> <p>My activity to be opened by the broadcast receiver</p> <pre><code>public class BroadcastReceiverTest1Activity extends Activity { private String uri =""; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final Intent intent = getIntent(); final String action = intent.getAction(); if(Intent.ACTION_VIEW.equals(action)){ uri = intent.getStringExtra("URI"); TextView textView = (TextView)findViewById(R.id.textView); textView.setText(uri); } } } </code></pre> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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