2

Im very new to kivy and python so I may have thrown myself in at the deep end here but i'm trying to figure out how to get an android intent and use it within a simple kivy app?

So im currently trying to figure out the basic design elements and just how to get stuff working. I want to be able to click on a link (for example) and launch my app and then do stuff, nothing too complicated, it just needs to be able to get the link which is passed to it from android.

I figured out this was to do with android intent filters and added the appropriate "intent_filters.xml" file to make this work. So clicking on the link will launch my app, which is good.

However I cant figure out then how to parse the information passed to the app in android. So below is a very simple app with a button and I just want to update the button to see if my intent is being picked up or not.

Currently clicking the button causes the app to close. When i test this in the Kivy VM I am using to compile the apk it will close with a message that "platform" is not defined (which makes sense as its not in android) but it doesnt much help with testing or tracking down how to make it work.

I've read some stuff which seems to suggest that this might not be possible with kivy? Can anyone confirm if this is possible in kivy and if so, how? (i've tried variations on activity.getIntent(), intent.getData(), Intent.getIntent().getStringExtra(Intent.EXTRA_TEXT), Intent().getData().getPath() all to no avail)

from kivy.app import App

from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout


class TutorialApp(App):

    def build(self):
        self.gen_btn = Button(text='Initial',
                         size_hint=(.90, .10),
                         pos=(5, 5),
                         font_size=50)
        self.gen_btn.bind(on_press=self.update_tutorialapp)
        l = BoxLayout()
        l.add_widget(self.gen_btn)
        return l

    def update_tutorialapp(self, *args):
        st = update_button()
        st.update_Message(self)

class update_button():

    def update_Message(self, source):
        source.gen_btn.text = "the event was called"
        if platform=="android":
            from jnius import cast
            from jnius import autoclass
            import android
            import android.activity

            # test for an intent passed to us
            PythonActivity = autoclass('org.renpy.android.PythonActivity')
            activity = PythonActivity.mActivity
            intent = activity.getIntent()
            intent_data = intent.getData()

            source.gen_btn.text = PythonActivity.getIntent().getStringExtra(Intent.EXTRA_TEXT)

if __name__ == "__main__":
    TutorialApp().run()
  • Hi, if your app crash, then please report the log associated to the crash. What does it tells you? – tito Nov 12 '18 at 12:40
  • Well the only way I have to run it on Android currently is to copy it to my phone so I don't really get any messages when it crashes. If I enable logging/debugging when I create the APK would I be able to retrieve any useful information from a non rooted android phone (ie from the apps install directory within android)? – Philip Shaw Nov 14 '18 at 17:49
  • Use android tool: adb logcat – tito Nov 14 '18 at 19:16
  • @Philip Have you had any success? Try importing ```from kivy.utils import platform```, as it seems the App only crashes when it tries to assess the ```If``` block. – Hmerman6006 Sep 16 '19 at 10:12

1 Answers1

0

def build(self):

android.activity.bind(on_new_intent=self.on_new_intent) # add this line in build 

def on_new_intent(self, intent):

data = intent.getData() # perform operations on intent