pyjnius

247 views
Skip to first unread message

Serge Vp

unread,
Oct 23, 2021, 2:41:43 AM10/23/21
to Kivy users support
hello,
Sorry if the question has already been asked, I did not find a subject
I had a function that worked very well under android 5,  I switched to API 26 and I got this messaga of error:
"jvm exception occured file: ///..apk exposed beyond app through intent.getdata ()"


              PythonActivity = autoclass('org.renpy.android.PythonActivity') #request the Kivy activity instance
                Intent = autoclass('android.content.Intent') # get the Android Intent class

                Uri = autoclass('android.net.Uri')
                File = autoclass('java.io.File')
                intent = Intent() # create a new Android Intent
                intent.setDataAndType(Uri.fromFile(File(str(self.localUpdateFile))), "application/vnd.android.package-archive")
                intent.setAction(Intent.ACTION_VIEW) #set the action (use ACTION_VIEW for install)
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

                currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
                currentActivity.startActivity(intent) # show the intent in the activity

Thank you for your help

Robert

unread,
Oct 23, 2021, 1:17:01 PM10/23/21
to Kivy users support
I suspect what is happening is the code is trying to share a File Uri (file://.......) but that is no longer allowed by Android. The app needs to share a Content Uri (content://.....)

Serge Vp

unread,
Oct 24, 2021, 5:21:36 AM10/24/21
to Kivy users support
PythonActivity = autoclass('org.%s.android.PythonActivity' %self.nomIntent) #request the Kivy activity instance

Intent = autoclass('android.content.Intent') # get the Android Intent class

Uri = autoclass('android.net.Uri')
FileProvider = autoclass('android.support.v4.content.FileProvider')
#Context = autoclass("android.content.Context")

File = autoclass('java.io.File')
intent = Intent() # create a new Android Intent
nApk = File(str(self.localUpdateFile))


currentActivity = cast('android.app.Activity', PythonActivity.mActivity)

ctx = currentActivity.getApplicationContext()
uriApk = FileProvider.getUriForFile(ctx, "org.test.ppv.fileprovider", nApk)
intent.setAction(Intent.ACTION_INSTALL_PACKAGE)

intent.setDataAndType(uriApk, "application/vnd.android.package-archive")
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)

currentActivity.startActivity(intent) # show the intent in the activity

ajout manifest:
<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="org.test.ppv.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
<meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>

 <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />


 file_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="." />
</paths>


buildozer.spec
android.add_aars = support-v4-24.1.1.aar

Serge Vp

unread,
Oct 24, 2021, 5:24:48 AM10/24/21
to Kivy users support
no errors but no install
idea?
thank's

Robert

unread,
Oct 24, 2021, 4:24:38 PM10/24/21
to Kivy users support
Just one suggestion, use try/except  around the FileProvider code.
With:
except Exception as e:
    print('>>>>>>>>',str(e))

The sample code looks about right (see below) but I have never tried ACTION_INSTALL_PACKAGE (which is now depreciated).

A long time ago, I wrote this (ACTION_SEND example attached to this post), something for you to maybe sanity check against:

Reply all
Reply to author
Forward
0 new messages