Reputation: 105
I have made an application with Python and Kivy. Générated an apk file with buildozer.
In this application I generate *.xlsx files. I want to add a button to open directly the xlsx file with the google Sheets application.
But I don't know how I can do this. I know the suprocess system on python but how I can call the android application ?
I have search on google but I don't have find any information.
Have you got an idea ?
Edit 2 : I have find the solution. I post the result code.
## Call pyjnius for call intent
# Request the kivy activity instance
PythonActivity = autoclass('org.renpy.android.PythonActivity')
# Get the Android Intent class
Intent = autoclass('android.content.Intent')
## get the URI android
Uri = autoclass('android.net.Uri')
## Get the File object
File = autoclass('java.io.File')
## String object
String = autoclass('java.lang.String')
#create a new Android Intent
p__intent = Intent()
# Set the action of the intent
p__intent.setAction(Intent.ACTION_VIEW)
# Set the intent myme type file
p__intent.setDataAndType(Uri.fromFile(File(p__current_file_month)),String("application/vnd.ms-excel"))
## Set extra to put the filename
p__intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
p__currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
# Run the intent activity
p__currentActivity.startActivity(p__intent)
This code open correctly the *.xlsx file.
Many thanks in advance
Upvotes: 1
Views: 2644
Reputation: 29460
You don't want to (and actually can't) use subprocess. Instead you must use pyjnius to create an Android Intent with the information about your task, which Android can then use to construct a list of available apps for the user.
You can find an example about this here, for an email sending intent, but the details should be fairly similar. You'll probably also want to read about the Android api a little to understand what's going on.
Upvotes: 1