I am trying to use ShapefileFeatureTable() to read shape file in android. No matter what path I give, it says, "File Not Found" exception.
try
{
ShapefileFeatureTable shpFileFeatTable = new ShapefileFeatureTable("/storage/sdcard/map.shp");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
Can anyone help me?
Note: I am working on Android Emulator. Also I am using arcGIS library.
see this example if helps you
https://developers.arcgis.com/android/api-reference/reference/com/esri/core/geodatabase/ShapefileFeatureTable.html
Your app is probably not requesting permission to read from external storage. You need to put the following in AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
At the moment, a ShapefileFeatureTable is read-only, but if this class gets editing capabilities in the future and you want to do editing, your app will need to request write permissions as well:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
See http://developer.android.com/guide/topics/manifest/uses-permission-element.html for more details.
It's also possible (but not likely) that your file path is simply incorrect. If you request read permissions and still get the FileNotFoundException, check the value of new File("/path/to/file.shp").exists(). If Android can't see the file, ArcGIS can't see the file either.
It turns out, it was displaying the shapefile. I had to blank the MapView to see it.
<com.esri.android.map.MapView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</com.esri.android.map.MapView>
I had same problem. Be sure that other files related to map.shp there are beside of it on same folder. Extensions of other files related to map.shp are: .dbf .prj .sbn .sbx .shp.xml .shx
Related
I am trying to read local pdf file which is saved in Android download folder.
I created app and set everything like it should be and app reads pdf if it is saved in asset:
Control.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file:///android_asset/abc.pdf")));
But if I use:
Control.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file:///storage/emulated/0/Download/foo.pdf")));
nothing is showing.
I checked if file exist:
string abc;
if (File.Exists(string.Format("/storage/emulated/0/Download/foo.pdf")))
{
abc = "exist!!!!";
}
else
{
abc = "not exist!";
}
and it confirmes file exist.
If i use OpenPdf project: https://github.com/acaliaro/OpenPdf
then it can open file saved in Download folder.
What am I doing wrong? Different Android version? Api level? I compared OpenPdf project with my project, everything seems to be ok.
Permisions are set too:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
For everybody who has similar issue:
Solution is very trivial.
Apart from permissions adjusted in AndroidManifest.xml I had to go to phone aplications settings and turn on memory permission manualy.
Everything is working now.
I'm fairly new to Android and I'm trying to use the camera via an intent. I know my permissions for API23 or lower are working. My app successfully opens the camera, but when I hit OK, it doesn't go back to my MainActivity. I found online that the reason is because my code fails to create a file for the picture. So I was able to narrow it down to mkdirs(). This function always returns false. I have tried everything and still mkdirs always returns false. I have followed exactly the same code in the documentation :
https://developer.android.com/guide/topics/media/camera.html#saving-media
under Saving data.
Here's my code:
private static File getOutputMediaFile(int type){
----- .... I do some checks first to make sure the SD card is mounted ...------
.....
File photosDirectory;
photosDirectory = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"myPhotos");
if(!photosDirectory.exists()) {
boolean file_creation = photosDirectory.mkdirs();
if(!photosDirectory.mkdirs()){
//return null; --->> HERE IS WHERE IT FAILS
}else{
Log.d("MyCameraApp", "FILE CREATION SUCCEEDED ");
}
}
----- I have some extra code here, not relevant to the question -----
}
Things I have tried:
1- Permissions. I have already included:
2- I have also tried:
try{
if(!photosDirectory.exists()) {
boolean file_creation = photosDirectory.mkdirs();
if(!photosDirectory.mkdirs()){
//return null; --->> HERE IS WHERE IT FAILS
}else{
Log.d("MyCameraApp", "FILE CREATION SUCCEEDED ");
}
} catch(Exception e){ show message}
3- I have also gone into the application and make sure that the App has CAMERA and STORAGE permissions.
4- I have tried different ways of calling the same code, but still.
I'm desperate. This is driving me nuts. I have spent 4 days working on this without any luck. I would immensely appreciate any input. Thank you very much!
The issue doesn't have to do with mkdirs(), but with my permissions. For API >=23 instead of using:
<uses-feature android:name="android.hardware.CAMERA" />
I should have used should use:
<uses-feature android:name="android.hardware.camera2"/>
I'm creating an excel file directly on Android. The code is working fine, I can verify the .xls has been created and I can check it's content from a rooted phone.
However I want save the excel file in a different folder from the project itself (which is /data/data/mypackage/files/). I want to save it on the normal phone documents, which would be something like "/storage/sdcard0/Documents/test.xls". I get a message saying "Permission denied" when trying to save the .xls file on that folder.
How can I get access to those folders?
Here I'm creating the excel file
WriteExcel test = new WriteExcel();
test.setOutputFile("/data/data/com.example.interfaz/files/test.xls"); // here is where I want to save the file to "/storage/sdcard0/Documents/test.xls"
try {
test.write();
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
}
Did you add permissions to your manifest?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You should also not hard code the SDCard location since it can, and does, changes between devices.
Instead, use Environment.getExternalStorageDirectory()
Check out this page for more info on saving files:
http://developer.android.com/training/basics/data-storage/files.html#GetWritePermission
Make sure you have the permission in your manifest to write files to external storage:
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
</manifest>
I am looking for a solution regarding a repeating log print that is caused by calling
BitmapFactory.decodeFile.
In My app i have a ListView that is being redrawn by a timer every second.
The ListView has an ImageView that gets is image source from the local storage, (not from the network)
The image is stored in :
filePath = /data/data/com.xxx.testlib/files/b22a1a294fd6e5ad3ea3d25b63c4c735.jpg
I am using the following code to redraw the image and it is working fine. with out exception.
try
{
File filePath = context.getFileStreamPath(imageName);
if(filePath.exists()){
bMap = BitmapFactory.decodeFile(filePath.getPath());
}
}catch (Exception e)
{
e.printStackTrace();
}
But when preforming the following line :
bMap = BitmapFactory.decodeFile(filePath.getPath());
I get a print in the log as follow:
03-07 09:55:29.100: I/System.out(32663): Not a DRM File, opening notmally
03-07 09:55:29.105: I/System.out(32663): buffer returned
....
How can i get read from the printing to the log.
Thank you
lior
Edit
Also it lags the phone whenever this operation is performed. And this reduced performance is noticeable specially when the phone is Waked up and we return to activity with this code.
Its more than a year for OP and still no answer is found. If anyone has found solution then please post it.
Thank you.
DRM stands for Digital Rights Management. It's normally a special keys used by owners of content to make sure that your device is authorized to view/play the content. iTunes was notorious for this for ages.
All it's doing is letting you know that the material you are opening is not DRM protected, and therefore can be opened normally.
Hope, this might help you.
I also got the same exception when i tried to save the image captured by camera directly to : /data/data/com.xxx.testlib/images/b22a1a294fd6e5ad3ea3d25b63c4c735.jpg.
Then i first saved the image to default location used by camera and the copied it to : /data/data/com.xxx.testlib/images/b22a1a294fd6e5ad3ea3d25b63c4c735.jpg.
and now "Not a DRM File, opening notmally" is removed from the log and saved the image successfully.
Conclussion : folder :- "/data/data/com.xxx.testlib/" is private and can be accessible from inside the application only.
Maybe it's a permission error.
Do you have added the right permission in your Manifest ?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
This is a strange problem. My Application can access the sdcard successfully if I don't set android.uid.system to it. But after setting android.uid.system to it, my application can't access the sdcard. At this time, the exception take place:07-13 09:11:24.999: INFO/System.out(9986): create file happen exception--->java.io.IOException: Permission denied. I check I write the right permission in the right place:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />.
Because use forceStopPackage in my application, I need to add android.uid.system to the manifest. And I have written LOCAL_CERTIFICATE := platform in the make file. Who can explain this strange problem. After setting android.uid.system, my application is belong the system process which should have more power to access the sdcard. This is my idea. The following are my code:
public void setPackage(String dir){
System.out.println( "setPackage dir=="+dir );
File share=new File("/mnt/sdcard","test.txt");
if(!share.exists()){
try{
share.createNewFile();
}catch(Exception e){
System.out.println( "creat file happen exception--->" +e.toString() );
}
}
try{
if(share!=null){
System.out.println( "create file is not null" );
FileOutputStream fops=new FileOutputStream(share);
fops.write(dir.getBytes());
fops.flush();
fops.close();
}
}catch(Exception e){
System.out.println( "write Exception-->" +e.toString() );
}
}
And My application run at the emulator and his target version is 2.3. Thank you very much.
Please read this: link1
and this link2
Use Environment.getExternalStorageDirectory().getAbsolutePath() to get the path, NOT "/mnt/sdcard"
Use: File share = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"test.txt");
This won't work: File share = new File("/mnt/sdcard", "test.txt");
You can see in android source code: frameworks\base\core\java\android\os\Environment.java, it have a function:
private static void throwIfSystem() {
if (Process.myUid() == Process.SYSTEM_UID) {
Log.wtf(TAG, "Static storage paths aren't available from AID_SYSTEM", new Throwable());
}
}
This function would be called getExternalStorageDirectory(), hence app with system uid can't access sdcard if you don't hack aosp.
android.uid.system make your app bind system, but sdcard observered by system also, then if your app delete this, it can access the sdcard. it seems
delete this line in your xml file :android:sharedUserId="android.uid.system"ystem