Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement FIleProvider in hard coded template #13

Closed
ThomasCWright opened this issue Dec 5, 2020 · 17 comments
Closed

Implement FIleProvider in hard coded template #13

ThomasCWright opened this issue Dec 5, 2020 · 17 comments

Comments

@ThomasCWright
Copy link
Owner

Used https://stackoverflow.com/q/38983649/7312441 as starting point, however, following error thrown

11-23 12:09:14.323 23238 5039 I python : jnius.jnius.JavaException: JVM exception occurred: file:///./blank_9x9.png exposed beyond app through ClipData.Item.getUri()

Quick search reveals promising post kivy/plyer#500 (comment)

also:
https://github.com/alecvn/kivy-android-camera#kivy-example-for-android-camera

but will create a new issue for this if next try can't make tests. Passed tests but still too big a rabbithole for task in hand. Off to backlog

Originally posted by @ThomasCWright in #1 (comment)

@ThomasCWright
Copy link
Owner Author

Due to the differing nature of print services on Android, the MVP needs to be able to fully share an image file via the app's FIleProvider.

On success, issue #12 should be looked at for completion.

@ThomasCWright
Copy link
Owner Author

Update C:\Users\tcw25\Documents\GitHub\Sudoku\.buildozer\android\platform\build-arm64-v8a\build\bootstrap_builds\sdl2\templates\AndroidManifest.tmpl.xml

@ThomasCWright
Copy link
Owner Author

ThomasCWright commented Dec 5, 2020

Implementing:
kivy/python-for-android#2020 (comment)

Looks like a great solution for future use of androidx but because

This requires android.api=28 or greater

No good for developing for Dad who's on api=25

@ThomasCWright
Copy link
Owner Author

OK. Back to the following link

@ThomasCWright
Copy link
Owner Author

Adding to main.py:

FileProvider = autoclass('android.support.v4.content.FileProvider')
Context = autoclass("android.content.Context")
Environment = autoclass("android.os.Environment")

@ThomasCWright
Copy link
Owner Author

support-v4-24.1.1.aar is required:
Downloaded here: https://maven.google.com/web/index.html?#com.android.support:support-v4:24.1.1
Added to buildozer.spec:

# (list) Android AAR archives to add (currently works only with sdl2_gradle
# bootstrap)
android.add_aars = support-v4-24.1.1.aar

@ThomasCWright
Copy link
Owner Author

Now modify existing share function to take advantage of FileProvider class:

photoUri = FileProvider.getUriForFile(
Context.getApplicationContext(),
"org.test.myapp.fileprovider",
photoFile
)

@ThomasCWright
Copy link
Owner Author

Trying forked p4a:develop with changes according to:
https://github.com/alecvn/kivy-android-camera#kivy-example-for-android-camera
$ pip install -e .
$ buildozer android debug => gives correct target API==29 but no change in AndroidManifest.xml
=> buildozer appclean and repeat step above

@ThomasCWright
Copy link
Owner Author

ThomasCWright commented Dec 7, 2020

Deleting fork of p4a and cloning https://github.com/pavelsof/python-for-android.git instead

From kivy/python-for-android#2200 (comment)

Insert

   <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="{{ args.package }}.fileprovider"
        android:grantUriPermissions="true"
        android:exported="false">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />
    </provider>

into AndroidManifest.tml.xml

@ThomasCWright
Copy link
Owner Author

ThomasCWright commented Dec 8, 2020

Reverting to https://github.com/Fak3/python-for-android.git and following comment

conda install -c anaconda python=3.7

@ThomasCWright
Copy link
Owner Author

Giving up on Fak3 PR and reverting to stock buildozer to try my luck with some hard wiring

@ThomasCWright
Copy link
Owner Author

ThomasCWright commented Dec 8, 2020

Following this comment

  • buildozer android debug
  • Add path to FileProvider lib:
    android.add_aars = ./support-v4-24.1.1.aar
  • .buildozer/android/platform/build-arm64-v8a/dists/BVWSudoku__arm64-v8a/templates/AndroidManifest.tmpl.xml updated
  • Then create a folder named xml in the .buildozer/android/platform/build-arm64-v8a/dists/BVWSudoku__arm64-v8a/build\src\main\res directory and create a file named file_paths.xml
  • buildozer android debug

@ThomasCWright
Copy link
Owner Author

Transferred to Ubuntu laptop

@ThomasCWright
Copy link
Owner Author

ThomasCWright commented Dec 10, 2020

🍾 🍾 🍾 🍾
modify /home/tcw/Github/Sudoku/.buildozer/android/platform/build-arm64-v8a/dists/BVWSudoku__arm64-v8a/templates/AndroidManifest.tmpl.xml gives file provider in manifest

@ThomasCWright
Copy link
Owner Author

Error: createNewFile permission denied in logcat
Add android:requestLegacyExternalStorage="true" to application tag

<application android:label="@string/app_name"
                 {% if debug %}android:debuggable="true"{% endif %}
                 android:icon="@drawable/icon"
                 android:allowBackup="{{ args.allow_backup }}"
                 android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
                 android:hardwareAccelerated="true"
                 android:requestLegacyExternalStorage="true" >

kudos

@ThomasCWright
Copy link
Owner Author

#17

@t0theRANCH
Copy link

I got tired of doing this repeatedly, so I wrote a nice little script to automate it
https://github.com/t0theRANCH/addFileProvider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants