AppArg url path wrong - Android device

47 views
Skip to first unread message

P5music

unread,
Feb 6, 2021, 8:04:15 AM2/6/21
to CodenameOne Discussions
I am trying to check my CodenameOne app on Android device.
The file read/write permission seems to have some problems. The user is asked about it at installation, but it does not seem to become effective for the app (some basic files are not saved on filesystem, exception is thrown)

I know that my app is not developed to handle file write on Android device. I do not mind.

But
I am testing the file opening from the filesystem (AppArg).

When the user selects a file with .ext extension  (alias for the file type handled by the app)
from the Download folder
 I see in logcat:

System.err: java.io.FileNotFoundException: file:/data/user/0/com.myapp.app/files/myfile.ext: open failed: ENOENT (No such file or directory)

(and the app seems blocked, two "activity" screens are in the "recent apps")

It is strange because it does not seem that the url path is from the Download folder.
The app is trying to open the url from AppArg.

What's wrong?

Shai Almog

unread,
Feb 6, 2021, 9:14:46 PM2/6/21
to CodenameOne Discussions
Share intent on Android doesn't provide download folder access. It gives you a local URL to give you access to the file on your app without giving you access to all the downloaded files within the folder. So the URL should be fine. Not sure why it won't open though, How did you open that file?

P5music

unread,
Feb 7, 2021, 12:27:15 PM2/7/21
to CodenameOne Discussions
The following method is called:

public static String readTextFileFromUrl(String url) throws IOException {

try(InputStream is = FileSystemStorage.getInstance().openInputStream(url);) {

InputStreamReader br = new InputStreamReader(is);

int numChars=is.available();

char[] b=new char[numChars];

br.read(b, 0,numChars);

br.close();

return new String(b);

} catch(IOException err) {

String error=err.getMessage();

System.out.println("write exc "+error);

}

return null;

}


Shai Almog

unread,
Feb 7, 2021, 9:29:25 PM2/7/21
to CodenameOne Discussions
And the URL is just the unmodified apparg value or do you cache the value?
Is it possible the method is invoked more than once?

P5music

unread,
Feb 9, 2021, 9:53:50 AM2/9/21
to CodenameOne Discussions
The method is called once, and then the url is null when it gets to the application, I think that

String arg=Display.getInstance().getProperty("AppArg",null);

gives the exception, then yields null.

Regards



Shai Almog

unread,
Feb 9, 2021, 9:10:54 PM2/9/21
to CodenameOne Discussions
Can you isolate this to a test case in the issue tracker so we can have a look?
Message has been deleted

P5music

unread,
Feb 10, 2021, 6:16:53 AM2/10/21
to CodenameOne Discussions

It is a very simple case because just that instruction has to be put in the start() method of any test app with

codename1.arg.android.xintent_filter=<intent-filter><action android\:name\="android.intent.action.SEND" /><action android\:name\="android.intent.action.VIEW" /><action android\:name\="android.intent.action.PICK" /><category android\:name\="android.intent.category.DEFAULT" /><category android\:name\="android.intent.category.BROWSABLE" /><category android\:name\="android.intent.category.OPENABLE" /><data android\:scheme\="file" /><data android\:scheme\="content" /><data android\:mimeType\="*/*" /></intent-filter>

public void start() {
String arg=Display.getInstance().getProperty("AppArg",null);
System.out.println("arg="+arg);
if(current != null){
current.show();
return;
}

...

...

I sent the Android build, I do not think it is safe to attach the apk here. You can easily do the same.

Then put a file into the Download folder and open it with some file-manager app.

Regards

Shai Almog

unread,
Feb 10, 2021, 9:48:49 PM2/10/21
to CodenameOne Discussions
We don't need the APK. Just the test case in the issue tracker and we'll look into that.

P5music

unread,
Feb 11, 2021, 3:49:22 AM2/11/21
to CodenameOne Discussions
https://github.com/codenameone/CodenameOne/issues/3364

Please take into account that the issue is truly blocking.
Thanks
regards

Shai Almog

unread,
Feb 12, 2021, 12:10:34 AM2/12/21
to CodenameOne Discussions
I assigned it. Unfortunately we have a HUGE backlog of issues many of which are blocking so I don't know when we'll have a resource to look into that. You can debug this in Android studio and see if you can make sense of this.
Reply all
Reply to author
Forward
0 new messages