Could someone save me from this Runtime Error?

Look in the html, you can edit this accordingly

<img src="Timetable.webp" width=50px height=50px/>

I believe this by default in Android <10. If you look at the blocks you will see the picked image copy is deleted after conversion, therefore is this is all your app does with the imagepicker there should be nothing in that folder related to the app :wink:

I take it the example is working for you :slight_smile:

1 Like

Thanks Tim. :smiley:

I would like to share my app to my friends having Android 10+. :thinking:

Btw, this is the HTML code I changed to. :arrow_down:

HTML code
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes">

<head>
	<title>Timetable</title>
</head>

<body style = "background:#ffffff">
	<img src="Timetable.webp" style="width: 100%; object-fit:contain"/>
</body>

</html>

Btw, what is the problem with &nbsp;Activity Starter&nbsp; ?
Why is it not working ?

Could you find out the problem ?

Asking cuz the &nbsp;Activity Starter&nbsp; setup I used is similar to &nbsp;Image Picker&nbsp;, so that shouldn't cause a problem. :thinking:

My example app should work with all android versions

I am not aware of a problem with the Activity Starter?

1 Like

Can I do the same in Java ?

That would be more helpful for me actually, but thanks.

The thing I was planning was actually,

  1. Call in a hidden Canvas.
  2. Set the dimensions of the Canvas to that of the Image.
  3. Use the Canvas1.SaveAs() to save the image as a .png file.
  4. Call the Webviewer 2 seconds after the method by using a clock component.

This way it would be possible actually.

But how can I delete I /_app_inventor_image_picker directory in such devices ?

Probably....

(Canvas needs to be visible in order to load and save an image)

Use one of the file extensions (delete all files within first, then delete directory.)

I am guessing, but if you do it will be recreated next time you use the imagepicker.

1 Like

I will set the delete method at the last of the ImagePicker.AfterPicking Event. At least that is what I did in my Paint app. But it leaded to deleting of some other of my app's data. So I prevented it at the first place. But thanks for helping me so far. :blush:

@TIMAI2 I've found out the problem.

Your extension isn't capable of converting files into .png format but it can convert them to .webp . But I need something to convert it to .png format.

You may want to check your work, before making such sweeping statements. The extension converts successfully to all three formats (from all three formats).

(if you are using the html file I previously provided, this is hard coded to display a webp file)

I've changed the .html file.
It set the image.src to window.AppInventor.getWebViewString()

When I changed the value of the global variable to Timetable.png the file wasn't even saved and threw the error. But when I changed it to Timetable.webp the file was saved.

Should I attach a .aia ?

Or show your relevant blocks and code.

Ummm... the Download Blocks as .png has glitched.

Here is the .aia :

Timetable.aia (41.1 KB)

You won't get a .png file if you set the output to .webp ?

image

I changed the code for the last test.

Try it after changing the value of the variable to Timetable.png

It won't work then.

png file created just fine in the .Timetable directory.

image

You do not need to provide a full file path to the webviewstring, just the filename, because the image is in the same directory as the html file.

image

There is something wrong with your code, you do not start the clock anywhere, and you have the imagepicker directory hard coded, this would need to be set based upon android version.

1 Like

It still doesn't work.

Blocks


***

Timetable.aia (42.8 KB)

I've fixed the clock issue, did some label debugging, and found that everything works fine before the convert method.

Could you provide an event that is raised when the conversion is successful ? That might help the situation and the concept of clock can thus be forgotten.

Also, this time, I'm getting a different error.

It says,

Runtime Error

Unexpected value : timetable.

                                                      END APPLICATION

No.
There is a lot wrong in your blocks. Only two of them:

  • The File component uses (needs) a relative path. So you must replace /storage/emulated/0 with an empty string.
  • The path to the assets starts with double slashes (//) only if the FileScope is set to Legacy. Since you set it to Asset, you shouldn't use a double slash.

And what about this? This is also wrong and what is the purpose of it? Also, this will not work on Android 11+ once there are files created by other apps. Your app can only access these with READ permission on Android 11+, but not remove them (this would require WRITE permission and this no longer exists on Android 11+).

I used the FileTools extension out there.

That is contributed by TIM.

But, these two are not a problem, cuz, the HTML file is properly copied to the exact folder with the exact name.

The clock is to check if the File is converted and placed to the selected directory, it checks every 4 seconds if the file is in the directory. Btw, my own app will create that folder due to the ImagePicker. And as far as I've read, I can write to folders created by my own app.

Even I want to avoid the ImagePicker because : Just in case the user is using an app made in App Inventor which also has a ImagePicker, but that app doesn't delete the ImagePicker directory, then, the directory will be created by the other app and I won't be able to delete that then. So in first place, due to such complications, I wanted to use the ActivityStarter.

Oh sorry, I missed that.

1 Like