ACTION_VIEW taking down my app (was: Open PDF with external reader)

172 views
Skip to first unread message

Andreas Falkenhahn

unread,
Nov 11, 2012, 7:15:46 AM11/11/12
to andro...@googlegroups.com
Hi,

I've now found out that I can open PDFs in an external reader from my C app
by using ACTION_VIEW through JNI from C. This is working fine when a PDF
reader has been installed on the device. If there is no PDF reader on the
device, however, I get the following error:

E/AndroidRuntime( 1719): android.content.ActivityNotFoundException: No Activity found to handle Intent
{act = android.intent.action.VIEW dat=file:///sdcard/test.pdf typ=application/pdf flg=0x10000000 }

Of course, this error makes sense because there is no PDF reader on the device.
What is annoying me, however, is that after this error my app is shut down by
Android!

Is there any way to disable this behaviour? I'd like to intercept this error
and display a message to the user that informs him that there is no PDF reader
on his device... I do not want my app getting shut down just because of a
missing PDF reader :-(

Tks for suggestions!

--
Best regards,
Andreas Falkenhahn mailto:and...@falkenhahn.com

RichardC

unread,
Nov 11, 2012, 9:00:16 AM11/11/12
to andro...@googlegroups.com
Catch the Java Exception (on the Java side of your JNI call) and return an error to your C app.

Andreas Falkenhahn

unread,
Nov 11, 2012, 9:17:30 AM11/11/12
to RichardC
How exactly do I do this? I don't have any Java code in my app and I don't really
have a clue about a Java...

RichardC

unread,
Nov 11, 2012, 9:40:06 AM11/11/12
to andro...@googlegroups.com
I don't understand why your app is shutting you can check for the exception on the C side (see the docs for JNI exceptions) and clear it if it one you can handle.


Andreas Falkenhahn

unread,
Nov 12, 2012, 10:15:02 AM11/12/12
to RichardC
On 11.11.2012 at 15:40 RichardC wrote:

> I don't understand why your app is shutting you can check for the
> exception on the C side (see the docs for JNI exceptions) and clear it if it one you can handle.

Thanks, that solved the problem. I have to check for the exception and clear it
to prevent my app from getting shut down automatically.
Reply all
Reply to author
Forward
0 new messages