Unity3d+Android, Get path of Assets/Plugins/Android directory - android

I want to find the path of Assets/Plugins/Android directory.
I have tried string filePath = Application.streamingAssetsPath;
But it gives path like jar:file:///mnt/asec/com.cmpny.pkg-2/pkg.apk!/assets
Goal: I want to check programmatically whether a particular jar (abc.jar) file is is present or not. Kindly help me to find that.
I have placed the jar file here (AppName\Assets\Plugins\Android\abc.jar)
I would appreciate any help.
Thanks.

Related

How to get asset file path in Xamarin?

I have data.xlsx file in Assets folder and need to get its path to apply some library.
Found several solutions here but neither works for me. For example -
File Not Found Exception In Xamarin program
I tried to use file:///android_asset/data.xlsx but here is no file too.
I checked the path with: System.IO.File.Exists(filePath);
So how to get path to this file? Maybe I have to place it in different folder?
Update: possibly I can solve it this way: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
But I can't find where to place it.
Update: this question is about Java and this is unclear how to use this solution in Xamarin.Android: How to get the android Path string to a file on Assets folder?
Looks like the file isn't included in the APK. Ensure that the Build Action of the file in the Asset-folder is set to AndroidAsset.
in general using Xamarin.android , you can use this code :
private string _fileName {get;set;}
public string FileFullPath
{
get
{
return Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures),_fileName);
}
}
Hope it helps.. :)
Looks like it's impossible.
Closest solution is to write file to Cache.

what is OpenNLP's model file path?

I try to use OpenNLP in an Android application with eclipse, and I imported the 4 JARs into the libs folder.
It's probably a stupid question.. but where should I put the model files "en-pos-maxent.bin"? I can't find anything regarding the path anywhere
I try to run the code contains this line:
POSModel model = new POSModelLoader()
.load(new File("en-pos-maxent.bin"));
I tried putting the en-pos-maxent.bin inside a new folder within the project("tagger/en-pos-maxent.bin"), inside the libs folder, or simply give the path where the en-pos-maxent.bin is put when downloaded("Users/ariel/Downloads/en-pos-maxent.bin"), it always give me the error: POS Tagger model file does not exist path: (the path I typed in)
Could anybody help please?
When you use new File("filename") the file is expected to be in the current working directory, I don't think that's different on Android. You can use System.getProperty("user.dir") to get the current working directory. It's by default the directory you start the program from. You could also specify a full path like new File("/full/path/filename") instead.
In android the right way to add file to the application (inside APK) is to put into the assets folder. Then you can't get File object from assets folder but, you can create that File using a buffer or in you case just get it into the InputStream. For example if you will create models folder into the assets folder (assets/models), your code will look like this:
AssetManager am = getAssets();
InputStream inputStream = am.open("models/en-pos-maxent.bin");
POSModel posModel = new POSModel(inputStream);

Can't find file downloaded by download manager in android

I'm trying to download a file to directory that can vary based on whichever directory the user chooses. I store the current directory in a file object and now attempting to download the file. The file downloads, but it doesn't download the specified directory. So, what can I do to get the file in the directory selected.
// Getting path to store the file
String path = root.getAbsolutePath();
path += curr.getName();
request.setDestinationInExternalPublicDir(path, new File(url).getName());
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
The String named url, that is being passed to the File constructor, contains a URL. Just using that to retrieve that name of the file.
UPDATE:
I just found the file. Its in the phone not the sd card. It was in this folder, storage\emulated\00. Not sure why? Also, the absolute path that I'm getting is storage\emulated\0.
So, I figured out that the path returned is always storage\emulated\0 for the call getExternalStorageDirectory().getPath()) to the Environment. Which is what I using to the get the initial directory. So for instance if I navigated through the folders to the Downloads folder the path would be storage\emulated\0\Download. When I was downloading the file though instead of going to the actual downloads folder it would go to, or create, the downloads folder in the emulated folder in the storage folder. To resolve this I found the index of the zero in the path, added 1, and got the substring using that. After that it worked. Also I had to do this in another method where I navigate through the directory. As a parameter I pass in the file and then within the method I get the substring. Within the method that I use to download the file I get storage\emulated\0 no matter what. Not sure why it does this. If anyone could explain this it would be greatly appreciated.
Does root.getAbsolutePath() return a string with a path separator character at the end?
If not, then you might be doing something like bin/usr/var/appfilename.ext instead of bin/usr/var/app/filename.ext, because you're concatenating it straight into name of the file.
I still had this issue on Android 7. In my case, the file would not show up until I restart the device. This a known issue: https://issuetracker.google.com/issues/36956498
Source: https://stackoverflow.com/a/20413888/2552811

Adding a folder to the Application folder

I've used application folder
data/data/com.xxx.xxx/databases/Customer.db
to store a database,it works fine and i could open and used it,but i wanted to add multiple folders to this path like
/data/data/com.xxx.xxx/databases/b36f6e58-0971-4f79-aca0-dada4201d886/Customer.db
but when i download the database and put it on the path and when i want to open it, it throws Exception that couldn't open the database.i have also try downloading the db ,check and makeDir the path then move db to the path but it doesn't solve the issue.
is there anything wrong with adding another folder in application folder or am i missing something? Any help would be appreciated.
Try this way:
File newDir = new File(getFilesDir(), "newDir");
if (!newDir.exists()) {
newDir.mkdirs();
}
File inside newDir can be accessed with openFileInput/openFileOutput. For both you need a context

Sending file to dropbox from android

i am doing work on drop box through android, i need create a folder and send a file(Eg: .txt file) to that folder from SD card of the mobile.. I can successfully create folders using the following statement
Entry entry = api.createFolder("dropbox", "test_folder");
how can i send file from SD card to dropbox folder, i have searched in https://www.dropbox.com/developers/docs
but i didnt find the right solution yet, please give me the solution to send file to folder in dropbox.
Please help me, thanks in advance....
Perhaps you would like to use the Android-Api and have a look at
public int putFile(String root, String dbPath, File localFile)
and
public File getFile(String root, String dbPath, File localFile, String etag)
I think it's usage is straight-forward.

Categories

Resources