I'm trying to read a dicom file using the instructions given in "Adding Imebra to your Intellij Idea" and I am facing issues.
The exact code snippet where am facing the issue is this:
Stream stream = new Stream();
stream.openFileRead("/sdcard/Download/87FDH4G2.dcm");
The error I get is that the stream cannot be opened. I have placed the file. But still I am getting this error. Please suggest me.
Try adding the following line to your AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
This allows you to write to the external storage, and reading permission is included (I've tried only the read permission, but it didn't work for me, but write which has read included did... weird, but it worked).
Related
Our application has a large amount of C++ code that creates its own log file as a simple .txt file. It's a circular buffer so it's limited to the size we specify. It's also placed in whatever directory we specify.
The problem is where to place the file so it can be accessed with ADB or a similar tool (without rooting). If we didn't care about the publicly-accessible part, it seems this would be the logical place to locate the file:
packageManager.getApplicationInfo(applicationContext.getPackageName().dataDir
But since we want to be able to pull the file from a customer's phone for post-mortem debugging, I've tried placing it here:
"/mnt/sdcard/Android/data"
This is problematic for several reasons, but I'm not sure if they're all true. (1) It's hard-coded; (2) Not all Android devices have external storage, although I thought they still mapped it to internal storage? (3) The location isn't app-specific so it won't get uninstalled along with the app. And (4) Runtime permission for EXTERNAL_STORAGE is required.
I believe 1-3 can be solved with something like:
android.content.Context.getExternalFilesDir()
Or is there a better choice?
But I don't believe this will get around #4, which is unfortunate as I'd prefer not to "scare" users with more permission requests.
What's the best way to handle this?
Make sure that you have the permissions to read and write the External SD using this code in the Manifest File:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
And then this string will give you the wanted path:
String directory = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + getContext().getPackageName();
/storage/emulated/0/Android/data/com.exemple.yourapp/
I want to write an android app which can analyse the APK file and output the permissions this application required? I saw some app achieve this and can anyone tell me which method they might used? thanks
The best way of doing it with external apk files, not the installed ones:
The .apk file is a casual .zip with changed extension. The permissions are located in AndroidManifest.xml file, so your job is to load it into memory, parse with some XML parser and search for uses-permission tag.
It looks like this <uses-permission android:name="android.permission.XXX"/>.
To unzip the xml from Archive i would recommend This SO post
You should modify it to grab only the .xml file, and
Documentation of ZipEntry is telling that it has a .getName() method.
I will leave the xml-parsing research for you (that tutorial is not bad), and yes, its obviously possible.
EDIT: I found one library that could possibly do it - APK-Parser Github, but it was not tested on android. Some users are reporting some issues on android L
try(ApkParser apkParser = new ApkParser(new File(filePath))) {
for (String permission: apkMeta.getUsesPermissions()) {
Log.d("APK PERM",permission);
}
}
I loaded up the OpenCV library and demos into Eclipse and was able to run them without issues. I have since taken the tutorial 3 code (capture image, etc.) and modified it slightly to instead save an image with the same name every time in a specific location, where after I proceed to run some other OpenCV functions on this. This was working until a few days ago when I accidentally deleted the folder where this image was stored on my phone. My code checked to make sure the folder existed and if not then it created it before the photo was to be taken. Now though, the image never saves and there is no specific error in the logcat as to why. I will get a logcat posted in a few hours as I don't currently have my laptop with me. If anyone has any idea why this would occur please let me know. Thank You.
It is likely that you created the folder with some user or access permissions that do not allow your Android application to write on that folder. You need to research more about Android file system permissions...
Also make sure your Android application is allowed to read/write to the filesystem:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
You will find dozens of posts here on SO and elsewhere addressing these issues.
I need to convert mp3 to wav in android and i found that it can be possible using Jlayer.
To do this, i coded below, and it looks working for a long time about 30seconds with no error, but the wav file haven't created anywhere. could you advise for me?
Converter converter = new Converter();
converter.convert(sourceName, destinationName);
ps. The souceName path is /mnt/sdcard/mp3/xxx.mp3
and the destinationName path is /mnt/sdcard/mp3/xxx.wav
please, help
Do you add permission at AndroidManifest?
< uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
It could be a variety of things.
You might have a permissions issue: make sure you have
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
in your Android Manifest.
Or it could be the device you're testing on. "/mnt/sdcard" is NOT guaranteed to exist within the Android file system. It is present on most devices, but you shouldn't rely on it. What you should be using is
Environment.getExternalStorageDirectory()
which will return the correct path to external storage.
Or you might be eating any errors JLayer throws. It crashes if the input path isn't correct, or if the file isn't actually an MP3 file.
I'm going to guess it's a permissions error.
Edit: Also you should remove the JLayer tag, it refers to a Swing window decorator and not the MP3 library from JavaZoom :/
This seems like a trivial question, so whoever can answer first and provide me with a resource, I'd be happy to provide you with a green tick :)
How can I write files from within native code? I want to perform some processing in C++ which will output a .txt file, so I'd like to save that to the SD card. (I tried and it told me permission denied).
Thanks!
try to add this to your manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
in default, android denies you of writing to external storage unless you specify your desire to..