Kivy on Android : How to keep local saved file after app update? - android

I want to know the correct steps to keep local saved data after app update.
I confirmed the following old question, but I can't solve the issue.
Save app data in kivy on Android
I tried the following.
1-1:I made android APK with buildozer(command:buildozer android debug). 1-2:And execute 'store.put' method using 'kivy.storage'. then 'hello.json' file was created in the './' directory.
https://kivy.org/doc/stable/api-kivy.storage.html
1-1:'./' directory in APK ver.1
main.pyo
1-2:'./' directory in APK ver.1
main.pyo, hello.json(created)
2-1:I made android APK ver.2(same app name as 1.APK). 2-2:After installing in update mode, execute only 'store.get' method using 'kivy.storage'. then method failed because 'hello.json' file was automatically deleted with app update.
2-1:'./' directory in APK ver.2
main.pyo(changed from APK ver.1)
2-2:'./' directory in updated APK
main.pyo(ver.2)
I tried changing the output location of the 'hello.json' file but it made no sense.
e.g. './data/data/[app_name]/files/hello.json' and './data/data/[app_name]/shared_prefs/hello.json'
How can I update my application?

Everything in the default current directory, which is named app, is deleted and replaced on app update. You can place persistent data in the directory above this, i.e. ../, and it should stick around between updates.
You can also use your app's external storage directory, using pyjnius to query the Android API for its location, but I don't have code for that right now.
This isn't especially well documented, I'll try to improve it.

Related

Android Studio Get Application Directory dataDir

In other Apps I can access files in directories like /storage/emulated/0/Android/data/com,xxx,yyy/files
In my own app I want to use it too. But with getApplicationInfo().dataDir I receive /data/user/0/com.xx.yy/files
How can I receive the path to /storage... and how to create this directory (it was not create automatically after installing the App)
Now I find out that getExternalFilesDir(null).getAbsolutePath() do the job

A question about the permissiones of files generated after the APK installation

I know that some directories(e.g. /data/data/{package}/lib) will be generated after APK installation.I want to know whether the permissions(e.g.-rwxr-xr-x) of these directories and files in them can be set at the code level before APK installation?Or is the permission of the files generated during installation granted by the Android system during installation and the permissions cannot be set in advance?How can I do to implement it if the permissions of the generated file can be set in advance?
The files in data/data/package/ are always private to your application. No other process can read or write them (except the system, of course). And there's no way to override those permissions at install time. You probably could at runtime, but I'm not sure why you'd want to.

Cordova android filesystem difficulties

We're developing an android application with cordova were files will be synchronized.
Cordova is up to date, but the problem is that our files are saved in the main storage directory.
The file url looks like:
file:///storage/emulated/0/{our_directory}//
After a cordova update we were forced to set
<preference name="AndroidPersistentFileLocation" value="Compatibility" /> in the config.xml, for still finding our files.
Now we really would like to have our files in the internal data directory.
So if course we just could remove the "Compatibility" setting in the config.xml but then all files would be invisible.
If we change to internal data directory we are having two problems:
In a transition period we need to have access on both directories (Compatibility: file:///storage/emulated/0/{our_directory}// and the new correct internal data directory: file:///data/user/0/{our_app_id}/files/files/{our_directory}//).
If we change to interal window.requestFileSystem(LocalFileSystem.PERSISTENT,0,fn) delivers the root directory of the internal app data directory. So how can I read or write to files which are not in this directory? I found out, that cordova.file.externalRootDirectorydelivers the old path. Any ideas on how to access to both directories?
The other thing is, that we may would like to move all the files from the old directory into the new correct internal app data directory. Any ideas on how to do this?
Thanks ahead!
If you already know the URL you want to store and retrieve files from you can use:
window.resolveLocalFileSystemURL(URL, callback);
The callback will be passed the directory entry.
To move files you can use the fileEntry method moveTo.
entry.moveTo(parentEntry, "newFile.txt", success, fail);
I know this documentation is for Cordova 3.3.0 but I believe it is still relevant.
https://cordova.apache.org/docs/en/3.3.0/cordova/file/fileentry/fileentry.html

openalpr on android - path to config and runtime_data

I want to use open alpr (automatic licences plate recognition) library in my android project. I compiled everything successfully and now it is time to use open alpr in app but...
to create Alpr class object properly I have to provide path to config file and path to runtime_data folder which contains some mandatory files needed by open alpr (ocr and trained data).
I tried something like:
Alpr alpr = new Alpr("eu", "android_assets/alpr.conf", "android_assets/runtime_data");
but Alpr.isLoaded() returns false which means that config or runtime_data have not been found.
Path to assets folder in project is: src/main/assets.
Can someone explain to me how path to "runtime_data" directory and "alpr.conf"
should looks to be visible by open alpr?
Thanks in advance.
I am not familiar with the specific library, but on newer Android devices (Android 6 and up), you can not rely on your application files residing under /data/data/your.package.name
The actual library name still includes the package name of your app, but also has some identifier appended to it in base64 format.
This identifier is unique per installation, and it will change if you uninstall and reinstall the app on the same device.
So, if your library needs to use a configuration file with a path to some other files, there are 2 options:
The right way:
Get the real address of your application files folder using Context.getFilesDir().
Unpack you files from the assets folder of the APK on the device using AssetManager.
Programmatically rewrite your configuration file with the path returned by getFilesDir().
The "hacky" but simpler way:
Use public storage to unpack your files.
You will need to add WRITE_EXTERNAL_STORAGE permission to your app, and unpack the assets files to the external storage.
For backwards compatibility this will be available under /sdcard folder on most Android devices, even with the latest Android version.
The second method is not recommended since using /sdcard directly is deprecated and strongly discouraged by Google.
Also, not all Android devices have /sdcard link to their public storage, but this is the only way to avoid dynamically editing the configuration file after installation.
Important note before you start implementing those steps. This library supports only arm CPU architecture. Good news is, most probably, your physical device is using arm architecture but to make sure just double-check it before implemting those steps.
I've recompiled this library to a new wrapper library. In original library, you need to manually configure openalpr.conf file and edit its content with correct path to your data directory. Manual configuration is cumbersome because since Android 5 multiple user accounts is supported and we can't simply hardcode data directory as /data/data/com.your.packagename/..... Because every user gets their symlink to data directory as /data/user/0/com.your.packagename/..... All those manual steps are gone in recompiled wrapper library.
Implementation
Add this in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency into app module:
dependencies {
...
implementation 'com.github.mecoFarid:openalpr:1.0.0'
}
And you're done. Please check this sample app to get started with UI.
Troubleshooting:
If your target sdk is targetSdkVersion >= 24 and you're running your app on a device with Android API 24+ you'll get following error:
android.os.FileUriExposedException: file:///storage/emulated/0/OpenALPR/2019-09-21-01-32-13.jpg exposed beyond app through ClipData.Item.getUri()
To solve this error: you can add following lines into onCreate() of your Activity as a workaround or you may use this thread for offical solution:
if(Build.VERSION.SDK_INT>=24){
try{
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
}catch(Exception e){
e.printStackTrace();
}
}
TEST:
You can use this image to test your app.
"/data/data/yourpackagename" + File.separatorChar + "runtime_data"
+ File.separatorChar + "openalpr.conf";

IBM Worklight 5.0.5.2 - How to change the Android package name

In worklight it seems that the android package name is set by the varible ${packageName}.
Where is this variable set? And how can I change it?
Right now the default seems to be com.applicationName. In the app im working on, this package name already exists in Google Play, so I would like to change it to com.corperationName.applicationName.
I know I can do this via Ant during Android project compilation, but I was wondering if there was somewhere within Worklight I can do this.
I was able to do this for Shell and Inner projects by making the following changes to the Shell project (check in or backup the shell and test before committing changes):
Add the following dir structure to the ShellApp/android/native/src
directory: com/corpname/{$appName}
Copy the contents of the ${packageDirectory} directory into the new
{$appName} directory (for me it was
${appName}.java.wltemplate.wluser, ForegroundService.java.wltemplate,
GCMIntentService.java.wltemplate).
In the files copied, every reference to ${packageName} needs to be
replaced with com.corpname.{$appName}
In AndroidManifest.xml.wltemplate.wluser, every reference to
${packageName} needs to be replaced with com.corpname.{$appName}.
Remove the ${packageDirectory} from the project.
Every inner project created from this Shell project should now have the package structure as com.corpname.appname

Categories

Resources