title: Android - How to open email attachment with Titanium 2.1.3?
body: <p>I'm working on Titanium SDK 2.1.3 and deploying for Android, I followed <a href="https://wiki.appcelerator.org/display/guides/Android+Intent+Filters" rel="nofollow">this article</a> to include my app in the list of applications that can open mime types like application/*, image/* and audio/*. It made my Android Manifest to look like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="nenvo.com.desktop" android:versionCode="1"
      android:versionName="1"&gt;
      &lt;uses-sdk android:minSdkVersion="8" /&gt;
  
      &lt;!-- TI_MANIFEST --&gt;
  
      &lt;application android:icon="@drawable/appicon"
          android:label="Desktop Lite" android:name="DesktopLiteApplication"
          android:debuggable="false"&gt;
  
          &lt;!-- TI_APPLICATION --&gt;
  
          &lt;activity android:name=".DesktopLiteActivity"
              android:label="Desktop Lite" android:theme="@style/Theme.Titanium"
              android:configChanges="keyboardHidden|orientation"&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;intent-filter&gt;
                  &lt;data android:scheme="content" /&gt;
                  &lt;action android:name="android.intent.action.VIEW" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
                  &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
                  &lt;!-- open any mime type file --&gt;
                  &lt;data android:mimeType="application/*" /&gt;
                  &lt;data android:mimeType="audio/*" /&gt;
                  &lt;data android:mimeType="image/*" /&gt;
                  &lt;data android:mimeType="text/*" /&gt;
                  &lt;data android:mimeType="video/*" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
  
  
          &lt;activity android:name="org.appcelerator.titanium.TiActivity"
              android:configChanges="keyboardHidden|orientation" /&gt;
          &lt;activity android:name="org.appcelerator.titanium.TiTranslucentActivity"
              android:configChanges="keyboardHidden|orientation"
              android:theme="@android:style/Theme.Translucent" /&gt;
          &lt;activity android:name="org.appcelerator.titanium.TiModalActivity"
              android:configChanges="keyboardHidden|orientation"
              android:theme="@android:style/Theme.Translucent" /&gt;
          &lt;activity android:name="ti.modules.titanium.ui.TiTabActivity"
              android:configChanges="keyboardHidden|orientation" /&gt;
          &lt;activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity" /&gt;
  
          &lt;service android:name="org.appcelerator.titanium.analytics.TiAnalyticsService"
              android:exported="false" /&gt;
  
  
      &lt;/application&gt;
  
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.VIBRATE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
  
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Now my app is launched when an email attachment is trying to be opened, the problem is that I don't know how to retrieve the file I'm trying to open, I tried the following on my start and resume events for my Android application:</p>
  
  <pre><code>activity.addEventListener('start', function() {
      Ti.API.log('*** Start Event Called ***');
      var args = activity.getIntent().getData(); // this is null
      functions.handleFunction(args); 
  });
  
  activity.addEventListener('resume', function() {
      Ti.API.log('*** Resume Event Called ***');
      var args = activity.getIntent().getData(); //this is also null
      functions.handleFunction(args);
  });
  </code></pre>
  
  <p>When I tried to retrieve the data for the intent, I got null as a result. When I display the Intent object, I get the following: </p>
  
  <p><code>{"flags":0,"type":null,"data":null,"action":null}</code></p>
  
  <p>Why am I not receiving any data on the Intent? Am I doing something wrong?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I noticed that when I opened my app from the list of apps that could open an specific file, my app would start as if it was closed before (even if it had been opened previously). I tried to get the Intent during this loading on my app.js file and to my surprise I got the data of the intent, which is the following:</p>
  
  <p><code>content://com.android.email.attachmentprovider/1/2/RAW</code></p>
  
  <p>How do I open that? How do I retrieve the file from that address so I can save it into my application directory?</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>I tried to get the file from that address like this:</p>
  
  <p><code>var tmpFile = Ti.Filesystem.getFile(String(currentActivity.getIntent().getData()));</code></p>
  
  <p>But what I got was an File object that looked like this:</p>
  
  <pre><code>{
      "writable": false,
      "symbolicLink": false,
      "parent": null,
      "readonly": true,
      "nativePath": "content://com.android.email.attachmentprovider/1/2/RAW",
      "executable": false,
      "name": "api-eventos.txt",
      "directoryListing": null,
      "hidden": false,
      "size": 0
  }
  </code></pre>
  
  <p>It does show the name of the original file, but the size is 0 and there doesn't seem like it contains any information of the original file, I tried to read it and got null as a result. How can I get the file from the attachment address?</p>