Opening attached text File from email

What I want to do seems simple, but I am missing something somewhere. My goal is to create an application that can open a text file attached to an email. I sent myself an email with a text file attached to it with the TRE file extension. I created an Android application with the intention specified in the manifest that will launch the application. He does it well. I have code in the OnCreate function to read data from an intent to get a file name. It’s strange here. When I open the letter, it retains the binding to temp-10.tre. However, when the application opens, it says the file name is / 4/4731 / RAW. Of course, when I try to open this file, it says that it cannot open it. I suspect this file name is incorrect.

The following is the manifest code:

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".TREViewerActivity"
        android:label="@string/app_name" android:screenOrientation="landscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter> 
            <action android:name="android.intent.action.VIEW" /> 
            <category android:name="android.intent.category.DEFAULT" /> 
            <data android:mimeType="*/*" /> 
            <data android:pathPattern=".*\\.tre" />     
        </intent-filter> 

    </activity>
</application>

Below is the code that I use to get the file name:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    strFilename = "Not set";
    Intent intent = getIntent();
    if(intent != null)
    {
        Uri uri = intent.getData();
        if(uri != null)
        {
            strFilename = intent.getData().getPath();
            readFile();             
        }
    }

, :

private void readFile()
{
    try
    {
        FileInputStream inFile = new FileInputStream(strFilename);
        inFile.close();
        Toast.makeText(getApplicationContext(),"File opened ok",Toast.LENGTH_SHORT).show();         
    }
    catch(Exception e)
    {
        Toast.makeText(getApplicationContext(),e.toString() +   e.getMessage(),Toast.LENGTH_SHORT).show();          
    }

}

, ?

+3

All Articles