I'm already created a plugin for my project and gratefully its work fine. Then I want to add another function on it that call an image in www folder (www/img/demo.png). I tried with this path
String picPath = "file://android/assets/www/img/demo.jpg";
But, it return with error
java.io.FileNotFoundException (No such file or directory)
Try:
String picPath = "file://android_asset/www/img/demo.jpg;
If you test on android device.
Related
I want to read a local html file to open it in Android WebView.
Why does the following work:
webViewMain.apply {
loadUrl("file:///android_asset/index.html")
}
But this code
webViewMain.loadDataWithBaseURL("file:///android_asset/",
URL("file:///android_asset/index.html").readText(Charset.forName("UTF-8")),
"text/html",
"UTF-8",
null)
gives me the following error: java.io.FileNotFoundException: /android_asset/index.html
The android file should be in the assets folder which is part of the root directory of the project.
assets/index.html
If you see the structure in the explorer it will be
/app/src/main/assets/index.html
and call webViewMain.loadUrl("file:///android_asset/index.html");
Things to check:
Make sure your assets folder spelling is right
The file is in the correct directory since it's giving you a FileNotFoundException
I am developing a file based application through flutter.
I can create a folder through getApplicationDocumentsDirectory() which gives the path to write files. But it cannot be seen in the files Explorer
I then created the folder through getExternalStorageDirectory() , which can be seen in the files explorer. But I want it to be created in the root.
You may have seen whatsapp folder in the root directory. I also want the same thing. I have tried the following:
Directory('FolderName').create()
But it gives the error saying 'read only os '
Is there a way to do it through flutter ?
You can do it this way:
String folderName = "My New Downloads";
var path = "storage/emulated/0/$folderName";
await new Directory(path).create();
I am creating an app in android studio that uses library opencv and yolo. I want to store the yolo config file and weights inside the android package. Right now I have those file in the external storage of my phone and I access them like this:
String yoloCfg = Environment.getExternalStorageDirectory() + "/dnns/traffic-yolov3-tiny.cfg" ;
String yoloWeights = Environment.getExternalStorageDirectory() + "/dnns/traffic-yolov3-tiny_15000.weights";
yolo = Dnn.readNetFromDarknet(yoloCfg, yoloWeights);
My question is: where do I put yolo config file and weights for them to be inside the app when the user downloads the apk and how do I get the path to them, since readNetFromDarknet needs as args the path of those files.
I have tried put them in the asset and attempt to get the path to asset but it doesnt work. This is the code I tried:
String yoloCfg = "file:///android_asset/traffic-yolov3-tiny.cfg";
String yoloWeights = "file:///android_asset/traffic-yolov3-tiny_15000.weights";
yolo = Dnn.readNetFromDarknet(yoloCfg, yoloWeights);
This is where I have the files:
Location of files
And this is the error I get:
E/cv::error(): OpenCV(4.0.1) Error: Parsing error (Failed to parse NetParameter file: file:///android_asset/traffic-yolov3-tiny.cfg) in readNetFromDarknet, file /build/master_pack-android/opencv/modules/dnn/src/darknet/darknet_importer.cpp, line 207
E/org.opencv.dnn: dnn::readNetFromDarknet_10() caught cv::Exception: OpenCV(4.0.1) /build/master_pack-android/opencv/modules/dnn/src/darknet/darknet_importer.cpp:207: error: (-212:Parsing error) Failed to parse NetParameter file: file:///android_asset/traffic-yolov3-tiny.cfg in function 'readNetFromDarknet'
E/SurfaceView: Exception configuring surface
I had the exact same issue. What I did to fix this was to add the files in the asset folder; then I created two files and copied the content of the asset folder files there.
Make sure to use the following path and create your files there:
applicationContext.filesDir.absolutePath
I am trying to access a file in Processing Android Mode using the following:
File file = new File(filePath);
And I tried the following options for setting filePath for the file “1.sf2” in the “data” folder that I created in the current sketch directory. However, none of them worked.
filePath = dataPath(“1.sf2”);
filePath = sketchPath(“data/1.sf2”);
filePath = sketchPath(“assets/1.sf2”);
filePath = “data/1.sf2”;
filePath = “assets/1.sf2”;
According to the github page of Processing Android Mode, everying file in the “data” folder of the current sketch directory are automatically copied to the “assets” folder of the generated apk file. However, I keep getting “java.io.FileNotFoundException: /null/restore_pixels: open failed: ENOENT (No such file or directory)” exception every time I run the application on my Android device.
Is there a way to correctly access a file in Processing Android Mode? Thanks a lot!
I'm trying to open a file with this:
document = builder.parse(new File("Data.xml"));
and I'm getting this message:
/Data.xml: open failed: ENOENT (No such file or directory)
and the file is in the root directory of the android project.
You are trying to open a file located in / (in linux this is the root directory of your file system). Instead you should be trying to create a file either on the SDCard or within the local storage directory for your application.
See this for more clarification: http://developer.android.com/guide/topics/data/data-storage.html
Move Data.xml into the assets folder of your project. Then to get a file reference, call getResources().getAssets().openFd( "Data.xml" )
You should probably try using a file input stream constructor for the builder instead, and use openFileInput( String fileName ) to get that, which does only use your app's data directory.
Using persistent storage
openFileInput()