2

I am developing an android application.

My AIM:

If the user open the pdf, doc, ppt or xls files in any folder inside the SDCard (or) dropbox (or) email etc..., they must navigate into my app(In my app, I will do some process based on the files they selected).

What I did:

If the user click on the PDF file, I can get the filepath and they are navigate into my app. For this I have done the following code.

Code snippet:

In the AndroidManifest.xml, I have added the following code:

        <activity android:name="com.openwith.OpenwithActivity" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="file" />
                <data android:mimeType="*/*" />
                <data android:scheme="http" android:host="*" android:pathPattern=".*\\.pdf" />
                <data android:scheme="https" android:host="*" android:pathPattern=".*\\.pdf" />
                <data android:scheme="content" android:host="*" android:pathPattern=".*\\.pdf" />
                <data android:scheme="file" android:host="*" android:pathPattern=".*\\.pdf" />
            </intent-filter>
        </activity>

In OpenwithActivity.java

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;

public class OpenwithActivity extends Activity {

        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_openwith);

            Intent intent = getIntent();
            Uri data = intent.getData();
            if (data != null) {
                  String filePath = data.getPath();
            } 
        }

}

What I Need:

I am getting only the pdf file's path. If I want get doc, ppt and xls file's path, what I need to add in the AndroidManifest.xml?

I have searched in the internet. But I didn't get any clear documents (or) tutorials. Can anyone hep me to do this?

SKK
  • 1,705
  • 3
  • 28
  • 50

1 Answers1

2

Add the same intent-filter entries for the other file types as you did for the pdf.

<data android:scheme="http" android:host="*" android:pathPattern=".*\\.ppt" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.ppt" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.ppt" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.ppt" />
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.xls" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.xls" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.xls" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.xls" />
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.doc" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.doc" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.doc" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.doc" />

And for the images, this should do:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:mimeType="image/*" android:scheme="http" android:host="*" />
    <data android:mimeType="image/*" android:scheme="https" android:host="*" />
    <data android:mimeType="image/*" android:scheme="content" android:host="*" />
    <data android:mimeType="image/*" android:scheme="file" android:host="*" />
</intent-filter>
tknell
  • 9,007
  • 3
  • 24
  • 28
  • Thanks for the response. I 'll check it. – SKK Jun 19 '14 at 10:42
  • Hi, I have added what you mentioned above. It is working fine for the ppt and doc. But I couln't get the xls file path - (i.e) I couln't navigate it to my app when I click on the xls file. – SKK Jun 19 '14 at 11:16
  • Strange... better check that lines for a typo again. Are you sure it is .xls and not the newer .xlsx ? – tknell Jun 19 '14 at 11:40
  • I want to get both xls and xlsx file's path. Now I am trying with .xls file only. – SKK Jun 19 '14 at 12:33
  • Sorry, I also don't have a clue why the xls should not work like the others if it's declared exactly as them. – tknell Jun 19 '14 at 12:57
  • Ok tknell. I google it for this issue. I found some solution for xls and xlsx. stackoverflow.com/a/18354328. It is working for me. – SKK Jun 20 '14 at 04:20
  • Hi tknell, How can I set the intent-filter for the images like doc, xls and pdf? – SKK Jun 23 '14 at 07:26
  • For images? The same as above, just with the corresponding file endings for images. So .png, .jpg, .gif ... that would be the major ones. – tknell Jun 23 '14 at 08:22
  • ok. So I need to add the intent-filters for each type. correct? Is there any way to add only one common intent-filter for all image type(.png, .jpg, .gif and etc...)? – SKK Jun 23 '14 at 08:44
  • I don't think that this is possible, because you can't use full regex inside the pathPattern, but only '.' and '*'. – tknell Jun 23 '14 at 08:58
  • Ah, wait, create another with mimeType "image/*" and don't check for the pathpattern (action and categoty same as before and also add the four different data tags as before), that should work. I updated my answer to address this. – tknell Jun 23 '14 at 09:10