Adding an intent-filter

339 views
Skip to first unread message

Alexander Taylor

unread,
Jul 5, 2013, 6:48:56 PM7/5/13
to kivy-...@googlegroups.com
I'd like to make my kivy app automatically open .sgf files - specifically, to appear in the 'Complete action using...' list that pops up when such a file is selected in a file manager or downloaded via a browser.

It seems there are two steps to this. The first is to include a suitable intent-filter in AndroidManifest.xml. I'm trying:
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:pathPattern=".*sgf" />
</intent-filter>

My first question is, should this intent-filter be correct for my desired behaviour? I can't get it to work, but I don't know if that's because it's syntactically wrong or because I have a different error during apk compilation.

The second question is, is there any mechanism within python-for-android to handle an existing program receiving arbitrary intents? It seems like it must in principle be possible, but I can't work out how or even if someone has tried to get tihs particular behaviour before. The ideal result (if I understand it correctly...) would be something like automatically starting the app (or opening a running instance) and calling App.on_intent(...) with some suitable arguments.

Gabriel Pettier

unread,
Jul 5, 2013, 8:25:12 PM7/5/13
to kivy-...@googlegroups.com
Hi

On Fri, Jul 05, 2013 at 03:48:56PM -0700, Alexander Taylor wrote:
> I'd like to make my kivy app automatically open .sgf files - specifically,
> to appear in the 'Complete action using...' list that pops up when such a
> file is selected in a file manager or downloaded via a browser.
>
> It seems there are two steps to this. The first is to include a suitable
> intent-filter in AndroidManifest.xml. I'm trying:
>
> <intent-filter>
> <action android:name="android.intent.action.VIEW" />
> <category android:name="android.intent.category.DEFAULT" />
> <data android:pathPattern=".*sgf" /></intent-filter>
>
>
> My first question is, should this intent-filter be correct for my desired
> behaviour? I can't get it to work, but I don't know if that's because it's
> syntactically wrong or because I have a different error during apk
> compilation.

Seems fine to me. Did you see
http://python-for-android.readthedocs.org/en/latest/toolchain/#usage ?
the intent-filter option allows you to have your intent-filter packaged
with your app.

>
> The second question is, is there any mechanism within python-for-android to
> handle an existing program receiving arbitrary intents? It seems like it
> must in principle be possible, but I can't work out how or even if someone
> has tried to get tihs particular behaviour before. The ideal result (if I
> understand it correctly...) would be something like automatically starting
> the app (or opening a running instance) and calling App.on_intent(...) with
> some suitable arguments.

I believe currently the intent is checked on start on resume for a file
passed as parameter, maybe it's not enough, or not general enough
https://github.com/kivy/python-for-android/blob/master/src/src/org/renpy/android/SDLSurfaceView.java#L422
i didn't test this for a long time, not sure how mature it was,
improvements welcome :)

>
> --
> You received this message because you are subscribed to the Google Groups "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Mathieu Virbel

unread,
Jul 7, 2013, 3:02:23 AM7/7/13
to kivy-...@googlegroups.com

Hi,

For the intent, I have recently worked on the android extension.

Can you test http://python-for-android.readthedocs.org/en/latest/android.html#module-android.activity ?

:)

Tommy Tang

unread,
Jul 9, 2013, 4:29:50 AM7/9/13
to kivy-...@googlegroups.com
Can I start activity on Kivy App run on Linux environment? Intent is now supported by Google Chrome or other browsers on Linux?

Mathieu Virbel於 2013年7月7日星期日UTC+8下午3時02分23秒寫道:

Alexander Taylor

unread,
Jul 16, 2013, 5:52:08 PM7/16/13
to kivy-...@googlegroups.com
I've been playing with this, but I have problems when my app starts on response to an intent (e.g. receiving a VIEW intent when I choose it to open a file in a file manager). It unpauses and receives the intent callback, but if this callback does anything more than just print a couple of things, it usually fails horribly. Often it crashes the program, sometimes hanging briefly before showing a black screen, sometimes getting some way through what it should do before failing somehow and presenting a partially constructred widget. Occasionally it works, but this seems highly unpredictable.

I'm not at all sure what could cause this (maybe some kind of race condition?), since as far as I can tell on_new_intent is called after the app has resumed and the function it is bound to works fine when used elsewhere in the program. Is there anything it could be, or a way to fix it?

As a semi-separate question, is it possible to query the activity intent status other than by binding to on_new_intent? e.g. to have anywhere in the program some code that checks the intent used to call the current activity. This would be generally useful, and also a convenient way to catch the intent if it is passed when the app is first started. With things as they currently are, I think it's impossible to catch the first VIEW intent because it takes place before python has initialised and set up the callback. It's possible to do it by monitoring the environment variable PYTHON_OPENFILE which seems to be the previously existing intent handling code, but this is clunky and inferior to the python activity stuff.


Thanks!

Alex
Reply all
Reply to author
Forward
0 new messages