Android/data/com.project.xx/files directory missing Unity - android

So I'm trying to use Application.persistentDataPath to save to device. What I'm seeing though is that its coming back null. I looked on device and am not seeing a files folder on my device, which makes me think that's why I'm getting back null. So I'm wondering how I can make sure a files directory is made when built to device using Unity.

To work with Mobile devices, you should try saving and loading files from Resources folder. All the files in Resources will be copied to your devices.
Unity Load text from resources

Related

How to create file on android using xamarin?

I've tried several folders but looks like no file is created.
External read & write permission have been enabled.
The code run without any sign of error. (as given below)
Here is the screenshot of the code inside mainactivity.cs (this is for testing purposes).
I also assume that since this is platform specific, the code must be in android project.
string filename = Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "count1.txt") ;
StreamWriter sw = File.CreateText(filename);
sw.WriteLine("asad ini test");
sw.Close();enter code here
1b. I 'm using Android 6.0 phone, but I can't find such folder /data/user...
(I'm not sure if such folder is targeted special version of Android)
I search both internal /Android/myproject/files/ and found nothing
I search external SDcard /Android/myproject/files/ and still found nothing
(please look at the my android phone folders, i can't even find /data folder
Once, this is accomplished the next step would be how to call this function from the generalproject (non android, non IOS, non UWP project).
Example to write file given in xamarin document.
Where should this code reside? in general project folder ? or, android project folder?
The term "external" used in android is very misleading. It doesn't mean the external removable SD card rather some folders that don't require "root" permission. Therefore, initially I can't find the folder which I save a file into.
Another reason is each phone manufacture uses different name, hence it is very difficult to get an absolute address of an external removable SD Card.
More details is explained in blog_external_removable_SD_Card
You can't write to the removable SD Card
an old post here

Access and edit files in runtime android app

My game is fed by parameters from a text file.
When I run the game in Unity, I can set the file path to my desktop or whatever and that works perfectly.
The problem is that when I run the game on an android device, I have to set the file path to some local folder in the device, a folder which I'll have access to.
How can I do that?
I want the file to be part of the .apk file.
I'm sure there's a way for doing that, yet could not find some relevant information on the internet.
I had a similar problem as your, I had to load some Translation Text Files in my game.
You can save the text file in the Resources folder. Then load it at runtime with Resources.Load("folderInsideResourcesFolder\textFile"). The Resources folder will be packaged in the APK.
You can find more info here: http://docs.unity3d.com/Manual/LoadingResourcesatRuntime.html

Android JNI: loadlibrary from install dir only

So, currently there is no way on Android, but to manually preload dependent shared libs. That's fine with me, not a big deal.
There is also some problem with android buildsystem (prebuild libraries feature), and for that reason I had to name differently different builds of my dependent shared library: libsal.so and libsal-slim.so. Depending on build settings one of these two makes it into the final apk. Then, on java side, I try to load libsal.so and if it fails, then I try to load libsal-slim.so.
It worked all fine, until we stumbled upon a phone that ships that libsal.so in default firmware installed into /system/lib. For that reason, my app stopped working on that phone if it's built with libsal-slim.so, since it tries to load libsal.so first and it loads wrong library from /system/lib.
Question: how can I ensure that only library from my install folder gets loaded? Maybe I can somehow retrieve install folder of my app and "calculate" full path of my shared lib? How can I do that java voodoo magic? I'm big time noob in java and android in general, if this questions looks too naive :) and yes, I don't speak English (or how they say), please rely in c++ [end-of-joke]
libsal.so isn't actual name, I used it only for example.
Using System.load(fullpath_of_the_lib)can probably solve your problem.
But your problem is to get the fullpath_of_the_lib. In fact the android API don't allow you to get the path of a resource. You can only get a stream to read it.
To workaround this limitation, what you can do is the following:
put your lib in your app assets folder.
open a InputStream on your lib : getAssets().open("libsal.so")
create a file named "libsal.so" (or whatever) in your sdcard
copy bytes from the inputstream to the file just created
get the absolute filepath of your "libsal.so" on the sdcard
call System.load(fullpath_of_the_lib_on_the_sd_card)
Of course you only need the last step in the lib is already on the sdcard.
An simpler alternative is maybe renaming your lib to something like libMyVeryUncommonLibraryName.so so that it won't conflict with another library name.

Packaging Flash Builder Apps for Android/IOS - assets directory Q

First timer here.
I've been writing an app that's intended to be deployed onto mobile platforms (iOS and Android ). This uses Flash Builder 4.6's android build target - it uses a subdirectory in the /assets/ directory, that contains an arbitrary number of .png files.
I code a directory loader as such:
public function LoadFromDirectory(directoryName:String, store:Vector.<BitmapData>):Boolean
{
//Changed here: this should work on both the development environment, AND the device.
//Guess what...
imageDirectory = File.applicationDirectory.resolvePath("assets/" +directoryString);
//This is triggering on Android. Doesn't do so in ADL. Not tested on iOS yet,
//but come on, if it doesn't work here, it won't work on iOS...
if (!imageDirectory.isDirectory)
{
trace("Directory not found:" +imageDirectory.url);
return false;
}
/*Snip loop through the contents of this directory, loading anything that is
a PNG and storing the bitmapData of all loaded PNGs into the vector, one by one*/
/*This of course, ALL works in ADL*/
}
This works in the air virtual devices, but isn't working on the mobile devices or on deployment. This is where I'm stuck.
Edit: Ok, I've gone and reduced the File code to just one line. I should be using resolvePath for cross-platform compatibility; also, the packager from Flash Builder doesn't see the "assets\" subdirectory unless I put it inside "bin-debug\", because that's where the compiled SWF went.
Still doesn't solve the problem tho - at least for the Android build, I can see the assets folder in the apk (by renaming it to a .zip and extracting it all), and it's the correct one (alongside the app's XML files and the SWF).
The apk installs and runs, but isDirectory still returns false when I debug on the device itself (once again, not on ADL - on the device only). Commenting that entire if...segment will crash the app instead because well, it can't find the assets\ directory.
I'm this close to solving the problem; would appreciate if someone helped me with the final step, because it's taking bloody ages to figure out.
PS: I would love to simply just embed the images in a FLA or SWC which I've done before and it works. Unfortunately, the number and name of images in that particular directory is arbitrary; the only thing that I'm certain of is the supported extensions.
PPS: Usage of this function: LoadImagesFromDirectory("imagesdirectory"), which should look under app:/assets/imagesdirectory in any platform. The Boolean return is for debugging (returns false if a directory with that name doesn't exist.)
...alright, I don't know if this is documented, but apparently I was calling LoadImagesFromDirectory to a directory name that is all caps, because on the PC, the target directory was also in all caps.
So in the test platform, the directory resolved to "app:/assets/IMAGESDIRECTORY".
But upon export, the device showed the directory instead resolved to "app:/assets/Imagesdirectory", therefore making the call to IMAGESDIRECTORY invalid.
Oddly, looking for "Imagesdirectory" works for both the PC and the device without changing folder layout and names.
Looks like I've been Gotcha'd - remember never to give directories names in all caps...

Where we put language files of tesseract ocr engine in an android app?

I'm programming an application in android which uses OCR. I'm using the tesseract ocr and I want to ask where should I put the language files in my project, so that when I install my app in my phone(Samsung Galaxy S) the files be somewhere for the app to use them for the ocr process. I think that it should be in a place like: /mnt/sdcard/tesseract/tessdata, but how this can be done without putting them myself in my device and let the installation to do this.
You'll have to include the files with your project in the assets folder.
See AssetManager to learn how to access your files from your activity. Also I would suggest that you don't copy them to the SDCard. Unfortunately since your files are going to have to be included with your project, and thus will be present in your apk file you're going to end up with a larger application size. But also unfortunately I don't believe that there is a way to delete the files from your apk at runtime, so even if you copy them over to the SD your app is still going to be the same size. For that reason I see no reason to copy them to the SD card, just access them from the AssetManager when you need to get them. Doing it that way also means that your application will not break if the SD card is removed / unmounted.
Simply put them under Assets in a "tessdata" folder. That is in your project.
You can use Xamarin and the Tesseract for Xamarin nuget package, they're really easy to use, just bear in mind that you probably will have to install older version of the nugget if the latest version doesn't work. (2.10 was the working one as far as i remember)

Categories

Resources