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

Access device storage and returning values #38

Closed
melbayoumy opened this issue May 13, 2018 · 4 comments
Closed

Access device storage and returning values #38

melbayoumy opened this issue May 13, 2018 · 4 comments

Comments

@melbayoumy
Copy link

Hi,

I need your assistance to know:

  • From a python script, how I can access the device storage (e.g. downloads folder) to read a file from it.
  • If my python script will print something. How I can pass it to the UI (may be as a toast).

Thanks

@mhsmith
Copy link
Member

mhsmith commented May 13, 2018

From a python script, how I can access the device storage (e.g. downloads folder) to read a file from it.

[Answer moved to the FAQ]


If my python script will print something. How I can pass it to the UI (may be as a toast).

There are several options:

  • To display a toast, follow the example in the demo app.
  • If your script is text-based, then it might be easiest to base it on the console app. Note that this currently targets Chaquopy 2.0.0, so you might need to edit build.gradle if you need features from newer versions.
  • Or for a fully native Android UI, see the examples for writing the UI either in Java or in Python.

@SameerChaudhari30
Copy link

Hi @mhsmith, I am facing issue while reading a file using cv2.imread

directory = str(Environment.getExternalStorageDirectory())
directory += "/Pictures/image,jpg"
img = cv2.imread(directory)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

Error : (-215:Assertion failed) !_src.empty() in function 'cvtColor'

@mhsmith
Copy link
Member

mhsmith commented Dec 2, 2020

Have you requested the READ_EXTERNAL_STORAGE permission, as described here?

If your app targets API level 29 or later, then "scoped storage" adds more complications. Once I've had a chance to learn about this, I'll edit my comment above with some recommendations.

Meanwhile, you can probably work around it by reducing your target API level to 28 or lower, or using the requestLegacyExternalStorage option as described here.

@mhsmith
Copy link
Member

mhsmith commented Feb 6, 2021

A solution which works with scoped storage is now given in the FAQ.

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

3 participants