In my app I am saving temporary files to my app cache folder. I am getting the name of the cache directory via this method:
context.getCacheDir();
It returns me such path: /data/user/0/my.app.packagename
But later when I am trying to get name of parent directory of my cache file via this method - file.getParent(); I am getting absolutely different path to cache directory, in my case this: /data/data/my.app-packagename
So I am just wondering why this is happening, why getParent() doesn't return the same path as context.getCacheDir()?
The behaviour is correct, technically its the same.
If you connect to your android device via adb shell and go into /data/user/ and run the 'll' command you will see that the folder 0 is just a symbolic link to /data/data/.
root#android:/data/user # ll
lrwxrwxrwx root root 1970-01-01 01:00 0 -> /data/data/
If you dont know what that means, read up on symbolic links.
So there is no issue and you can trust android that they are the same.
This behavior confused me a lot today.
Here are my 50 Cent to bring light into this:
I've started an Emulator with Android 8.1
I've connected my Android 9 Device via USB
After that I've started Android-Studio and opend the Device File Explorer.
Now strange things happend:
On Android 8.1 you see the structure /data/user/0/com.myApp/
on Android 9 there is no directory /data/user (and no symbolic link visible via android-studio)
BUT, internally the path seems to be the same (even if there is no symbolic Link visible in android studio).
I use RNFetchBlob (React native package to read files), and if I output the Result from RNFetchBlob.fs.dirs.CacheDir the result was /data/user/0/.... even if on Android 9 this Directory not exist.
But I'd gave it a try and output all files that will be found at this Directory with the following Command :
RNFetchBlob.fs.ls(RNFetchBlob.fs.dirs.CacheDir)
.then((files) => {
console.log("output-files",files);
})
...and found that this output all the files I've cached before.
If anybody knows some documentation why this behavior exist up from Android 9, please comment and point us to this.
Related
I'd like for my webapp which is deployed as a war ROOT.war to have write access to /var/www/html/static/images so that it can write uploaded and converted images to that folder so nginx can serve it statically. Currently it doesn't work and triggers a java.nio.file.FileSystemException exception together with the Filesystem is read-only message.
But the filesystem is not read-only and is in great condition. The folder has already been chmodded 777.
Extra info:
The tomcat setup is running on an Ubuntu 18.04 Azure VM with managed disk. The folder is residing on an Ext4 formatted drive
Let's start with: chmod 777 is great for testing, but absolutely unfit for the real world and you shouldn't get used to this setting. Rather set the owner/group correctly, before you give world write permissions.
Edit: A similar question just came up on the Tomcat mailing list, and Emmanuel Bourg pointed out that Debian Tomcat is sandboxed by systemd. Read your /usr/share/doc/tomcat9/README.Debian which contains this paragraph:
Tomcat is sandboxed by systemd and only has write access to the
following directories:
/var/lib/tomcat9/conf/Catalina (actually /etc/tomcat9/Catalina)
/var/lib/tomcat9/logs (actually /var/log/tomcat9)
/var/lib/tomcat9/webapps
/var/lib/tomcat9/work (actually /var/cache/tomcat9)
If write access to other directories is required the service settings
have to be overridden. This is done by creating an override.conf file
in /etc/systemd/system/tomcat9.service.d/ containing:
[Service]
ReadWritePaths=/path/to/the/directory/
The service has to be restarted afterward with:
systemctl daemon-reload
systemctl restart tomcat9
Edit 2022: Note that these are the 2019 paths - validate the file locations for later versions. From the comments to this answer (thank you to V H and Ng Sek Long) here are some updates:
In current Ubuntu file is here: sudo vi /etc/systemd/system/multi-user.target.wants/tomcat9.service – V H Feb 26, 2022 at 19:55
Mine (Ubuntu 20) is installed here /lib/systemd/system/tomcat9.service smh everybody use a different path. – Ng Sek Long Mar 28, 2022 at 8:36
End of edit, continuing with the passage that didn't solve OP's problem, but should stay in:
If - all things tested - Tomcat should have write access to that directory, but doesn't have it, the error message points me to an assumption: Could it be that
Tomcat is running as root?
The directory is mounted through NFS?
The default configuration for NFS is that root has no permissions whatsoever on that external filesystem (or was it no write-permission? this is ancient historical memory - look up "NFS root squash" to get the full story)
If this is a condition that matches what you are running, you should stop running Tomcat as root, and rather run it as an unprivileged user. Then you can set the permissions on the directory in question to be writeable by your tomcat-user, and readable by nginx, and you're done.
Running Tomcat as root is a recipe for disaster: You don't want a process that's available from the internet to run as root.
If these conditions don't meet your configuration: Elaborate on the configuration. I'd still stand by this description for others who might find this question/answer later.
Ok, I have searched and searched without any success for someone with a similar question. I am developing an Android app using Android Studio and have started creating my SQLite database. In order to test my creation and upgrade functions I would like to extract my SQLite database and view it's contents.
Instructions online are fairly clear, open up Android Device Monitor, select the device, go to file explorer, and then browse a few levels deep in the data folder to find your .db file. Here is where the trouble starts. I am unable to expand the root level data folder at all. I have found numerous other questions regarding people having the same problem but they are all due to people trying to do it on un-rooted physical devices. I am simply trying to do it on an emulated device. I am certain it is a permissions problem but I'm not sure how to fix it.
Things I've tried:
Verified that my app is listed as a process on the device selected in the device monitor.
Restarted the AVD, Android Studio, and then my entire machine.
Uninstalled my app and reinstalled.
TLDR; can't access data folder in DDMS for emulated device in order to extract SQLite database file.
Same question to me.
When I want to access /data directory via Android Device Monitor, some error have occurred :
08-21 07:32:36.837: W/ls(3101): type=1400 audit(0.0:50): avc: denied { getattr } for path="/default.prop" dev="rootfs" ino=2941 scontext=u:r:shell:s0 tcontext=u:object_r:rootfs:s0 tclass=file permissive=0
08-21 07:32:37.418: W/PlatformStatsUtil(2507): Could not retrieve Usage & Diagnostics setting. Giving up.
This information tells us we don't have permission to access the directory.
Here are what I have done and works for me.
My OS is Window10
Start your ADV & Open Android Device Monitor
cd to /the/path/to/Android/sdk/platform-tools
Open your cmd or openshell here (shift + right click you will see the option)
execute following commands
.
./adb.exe shell
su
chmod -R 777 /data/data/your/package
Now, enjoy your coding.
Run your app in an emulator with API 23 (or lower).
check detailed information in link below,
Android Device Monitor "data" folder is empty
When running the Java quickstart sample at https://developers.google.com/drive/web/quickstart/java?hl=hu in NetBeans, I'm receiving the error code:
Jun 04, 2015 12:12:11 AM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for everybody:
C:\Users\Quibbles\credentials\drive-api-quickstart
What am I doing wrong?
Edit: This is the complete error message.
Jun 04, 2015 5:11:39 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for owner: C:\Users\Quibbles\.credentials\drive-api-quickstart
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at DriveQuickstart.authorize(DriveQuickstart.java:64)
at DriveQuickstart.getDriveService(DriveQuickstart.java:87)
at DriveQuickstart.main(DriveQuickstart.java:96)
Java Result: 1
Had the same issue and wasted hours before realizing that "unable to change permissions for owner: C:\Users\Quibbles.credentials\drive-api-quickstart"
is just a warning.
The real issue is the null pointer here.
InputStream in =
DriveQuickstart.class.getResourceAsStream("/client_secret.json");
This line was the issue in my case. "in" was null and hence the null pointer.
InputStream in = new FileInputStream("<Full Path>\\client_secret.json");
This resolved my issue.
The actual problem is a bug in Google's API code for setPermissionsToOwnerOnly
The code was written to only work on Linux/Unix based systems and not Windows ACL based systems.
You can ignore the warning or write your own DataStore class that sets the permissions correctly for Windows.
I'm going to try to file a bug with Google on it too.
I was facing same issue in Eclipse. Here’s a solution:
Run eclipse in admin mode
Clear the directory
C:/Users/<username>.credentials/calendar-java-quickstart.json
Copy the .json file the bin directory, e.g. bin/main/resources/client_secret.json
You are free to run now.
Basically if you already enabled de Drive API and created credentials.json file at Google Drive API Rest, now you need :
1 - Remove the tokens directory generated in you last execution. In this directory contains a file StoredCredential.
2 - Change de SCOPE to DriveScopes.DRIVE like sample bellow:
private static List SCOPES = Collections.singletonList(DriveScopes.DRIVE);
3 - Re run the program. It will be request that you login in your google account to give the access consent.
4 - It will be generated a new one tokens directory in your project and now with with read and write permissions at google Drive.
This work for me.
I just ran into the same issue with the https://developers.google.com/google-apps/calendar/quickstart/java example. I suspect that the issue is that you are running it in Windows and the JVM that you are running it does not have Adminsitrator rights for changing the file permissions in Windows.
See Run Java application as administrator on Windows
Had the same problem when running the example given in the tutorial "https://developers.google.com/drive/v2/web/quickstart/java". Followed the instruction ditto as given the in the tutorial, but kept getting this permission exception. Eventually, managed to sort it out by moving the "client_secret.json" to the "\build\classes\main\classes" folder. Also, before building the project with "gradle -q run" for the first time, delete any files in the "C:\Users\userName\.credentials" folder.
Just make sure that client_secret.json is under main/resources/ directory.
InputStream in =
DriveQuickstart.class.getResourceAsStream("/json/client_secret.json");
Was able to resolve the issue by deleting the StoredCredentials files under the token folder. I had to reauthenticate again with google the next time the program was executed.
I'm trying to parse an XML file thru a DOM parser. However, I am having difficulty in getting my Main Activity to actually read the file. I've read that I should place the file in Assets and then called with getAssets(). I used something like this:
InputStream is = this.getAssets().open("myXML.xml");
This just results in an error: Unexpected error while launching logcat. Try reselecting the device.] device not found.
I've also tried new File("myXML.xml") using variations on the absolute path. Nothing seems to work. I'm getting a little frustrated. Does anyone have any suggestions?
sounds to me, as if your IDE has no connection to the Emulator or device on which you are trying to test your app.
LogCat is a logging output stream that can be used by any app to print out informations /logs. And LogCat needs to be connected (via ADB) to your device.
If you don't have a real phone connected you can use an emulator:
/path/to/your/androidSDK/tools/android
this SDK manager helps you to create a new AVD (Android Virtual Device). Klick Tools>
Manage ACDs> New...
If you have a real phone or tablet connected to your computer, try restarting ADB
(should be possible from within your IDE) or use the command line.
change to the directory where the Android SDK is installed (in windows something like):
c:\Program Files\Android\android-sdk-windows\platform-tools\
on linux it could be:
/opt/android-sdk-linux/platform-tools/
then type (win and linux)
adb kill-server
adb start-server
I'm trying to print using jPOS in Windows and get the following exception:
jpos.JposException: Could not connect to service with logicalName = Printer: Exception.message=jp.co.epson.uposcommon.util.EpsonJposServiceInstanceFactory
at jpos.loader.simple.SimpleServiceConnection.connect(Unknown Source)
at jpos.BaseJposControl.open(Unknown Source)
...
More information:
I'm trying to port our Java printing software from Linux (where it works well) to Windows. We are using an Epson TM-T70 receipt printer. I installed the regular printer drivers and was immediately able to print stuff using notepad, for instance.
Now I installed the Epson JavaPoS ADK. I configured the printer using the SetupPOS application that comes with the ADK. I created a new configuration for my printer with Logical Device Name "Printer". I saved everything and it created the jpos.xml file.
When I try run our application and it executes printer.open("Printer") where "Printer" is the logical device name and printer is a POSPrinter instance, I get the exception above.
I know that my generated jpos.xml file is being used because if I provide a random logical device name, I get a different exception.
I guess the problem is in the port configuration of SetupPOS. The printer is connected through USB. I tried the Port name that appears in the windows printer properties (ESDPRT001) and I even tried all combiniations of COM1 to COM10 but nothing works.
Does anyone have some suggestion? Thanks!
The Installation Routine of the Epson JavaPOS ADK is ... ahm ... let me say: "very special". So the Installation copies some jar files (like epsonupos.jar, jposXXX.jar and some more) in the ext/lib Directory of the JRE (!!!) (which must be selected while installing the JavaPOS Driver). We had also some very strange effects if we install another JavaPOS Version, switching to another JRE/JDK, using other Printers which are not from Epson or somthing else.
May be your problem is a result of any conflicts between different jar Version or JDK's or somthing else ...
EDIT:
Since ADK Version 1.11.anywhat (not realy sure, but I mean 1.11.9) you can specify the path in which the additional jar files are stored. But: Some DLL's will be also in the currently newest ADK Version (1.13.17) stored into the bin directory of the selected JRE. May be this is also a conflict between different Versions of used jar's and used DLLs or something else ...
I Solved this adding the following library paths to java project:
C:\Program Files\EPSON\JavaPOS\lib
C:\Program Files\EPSON\JavaPOS\SetupPOS
With javaPOS 1.14.6, on Debian 9 Linux I solved with LD_LIBRARY_PATH:
$ export LD_LIBRARY_PATH = /opt/EpsonJavaPOS/bin && javapos_application_to_run
On windows 10 copy:
BluetoothIO.DLL
epsonjpos.dll
EthernetIO31.DLL
SerialIO31.dll
USBIO31.DLL
from C:\Program Files\EPSON\JavaPOS\bin\
to C:\Program Files\Java\jre1.8.0.171\bin\
Run javaPOS application.
I know is a little late for response but may help others with similar problems.
In my case i am interacting with a Data logic Scanner using javapos, and i was having this message:
ERROR: Failed to open DL-Magellan-9400i-USB-OEM-Scanner-Scale profile, jpos.JposException: Could not connect to service with logicalName = DL-Magellan-9400i-USB-OEM-Scanner-Scale:
Exception.message=com.dls.jpos.service.DLSScannerInstanceFactory
i started looking in the javapos software that downloaded from datalogic and found that there was a jar file that was not included in my classpath (JavaPOS.jar) and that was why i was getting the error, take a look netx image:
I wanted to share in case someone has same issues.
(Took me almost 2 days to get it done!!)