0

There is an application (Graph Paper) that exports data in PDF to a limited set of applications, among which are Google Drive, Dropbox, GMail etc. but no plain file system or network.

So, how to build an application that will be able to catch this PDF? I just want save it on sdcard, or maybe pipe to IP where netcat can save it. I read a numerous posts about how to send a file with Intent.ACTION_SEND, but can't find anything for receiving. Must be pretty obvious, but I've never written for Android.

anatoly techtonik
  • 17,421
  • 8
  • 111
  • 131
  • `application ... that exports data in PDF to a limited set of applications, `. Well that is not how i see it. You suggest that Graph Paper limits the applications that can receive its pdf file. But Graph Paper has no influence on the set of applications that can receive the pdf. Instead Graph Paper starts an intent with ACTION_SEND. And depending on the applications which you installed on your device which told the OS that they can and want to handle pdf files the user can choose between those apps when PG intents its pdf. Of course a plain text application can not handle pdf files. – greenapps Aug 13 '15 at 06:25
  • @greenapps, I suspect that Graph Paper doesn't set PDF type correctly. I see only generic applications in the list, not the ones that work with PDF explicitly. – anatoly techtonik Aug 13 '15 at 06:28
  • 2
    In the store are apps like IntentIntercept. They tell you how the used intent actually looks like. Knowing that you can adjust your manifest file. – greenapps Aug 13 '15 at 06:36
  • Or... @greenapps you could just have a receiver listen to all intents and look at the respective data (which is what that app is doing) :) – JoxTraex Aug 13 '15 at 06:41
  • `you could just have a receiver listen to all intent`. And how would you do that? On can not listen to all intents as fas as i know. On has to register for every intent one wants to receive. If you know how you can listen to all intents then please tell. – greenapps Aug 13 '15 at 06:44
  • @greenapps, **Intent Intercept** rocks! It is `android.intent.action.SEND` with `application/pdf` type and couple of flags and extras. Hopefully those extras doesn't participate in the match. – anatoly techtonik Aug 13 '15 at 06:49
  • Looks like for viewing PDF, the intent should be `android.intent.action.VIEW`. – anatoly techtonik Aug 13 '15 at 06:50
  • And does Intent Intercept show how you can grab the pdf? Is there a file system path or a content path in the extras? Or is the content of the pdf transferred? – greenapps Aug 13 '15 at 06:53
  • @greenapps, yes EXTRA 3 contains `Class: android.net.Uri$HeirarchicalUri Key: android.intent.extra.STREAM Value: file:///storage/emulated/0/Documents/graph-paper/pdf/ad6...0d.pdf` – anatoly techtonik Aug 13 '15 at 06:57
  • So the file is already on external memory. That makes it easy for you. And further you do not have to wait for an intent but you can just look in that Documents directory for all files. – greenapps Aug 13 '15 at 06:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/86855/discussion-between-techtonik-and-greenapps). – anatoly techtonik Aug 13 '15 at 07:06

1 Answers1

1

If you can figure out the mimeType, you may be able to add your application to service the request by something similar to this:

    <activity class=".NoteEditor" android:label="@string/title_note">
         <intent-filter android:label="@string/resolve_edit">
             <action android:name="android.intent.action.SEND" />
             <category android:name="android.intent.category.DEFAULT" />
             <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
         </intent-filter>
     </activity>

Which it appears there is a standard for the pdf mimeType:

Proper MIME media type for PDF files

References

http://developer.android.com/reference/android/content/Intent.html

Community
  • 1
  • 1
JoxTraex
  • 13,105
  • 5
  • 30
  • 45
  • I suspect that the MIME type is set to something generic, because PDF Viewer is not on the list of applications to choose from. – anatoly techtonik Aug 13 '15 at 06:24
  • mimeType is meant to be generic for handling of specific types of data. Note that mimeType has NOTHING to do with applications it has to do with identifying the data that is incoming. – JoxTraex Aug 13 '15 at 06:26
  • If it can be done in XML, it can likely be done in code too. look @ http://developer.android.com/reference/android/content/Intent.html however; for standard, you should probably do it in XML. Most applications have one Activity/Service that handles that particular intent/data. The reason I say this because when intent resolution is happening its looking at activity that can handle THIS specific data and then builds a chooser for those than can handle it. – JoxTraex Aug 13 '15 at 06:27
  • Thanks. From the answer is not clear where should I put my code that receives the file and saves it to disk. Can you clarify this? – anatoly techtonik Aug 13 '15 at 06:31
  • usually when an Activity is started, you can get the intent that launched it via getIntent() and then you can probably figure it out from there. – JoxTraex Aug 13 '15 at 06:33
  • Is there only one Activity per application? I don't see where.. Ok. Seems I got it - `.NoteEditor` is the name of the class that handles the intent. And it should be located in `org/myapp/NoteEditor.java`. – anatoly techtonik Aug 13 '15 at 06:53
  • I need to integrate details from the comments into the answer, so that it will become useful. Also, the answer doesn't specify how to get file data from intent and is missing Intent Intercept part, which was vital in understanding what is going on. – anatoly techtonik Aug 14 '15 at 07:28