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 :/
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 am hoping to develop an application that needs to read a log file from another popular application. The log file is in /android/data/com.xxx.xxx/files.
Initially I thought my application would need root, but using two different file managers on an unrooted phone, I can access the /Android/data/com.xxx.xxx/Files/ directory and read/write the files there.
Everything I read online tells me it shouldn't work that way though. Can someone help clarify things?
The only way to do this is with the FileProvider. Here a good example on how to implement this:
https://developer.android.com/reference/android/support/v4/content/FileProvider.html
Remember to add these two lines in the manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
to have the permission to read the files from other dirs.
To read this path:
"/your_sd_path/android/data/com.xxx.xxx/"
As you tested, root acess is not needed.
But for reading app dir in below path:
"/data/app/com.xxx.xxx/"
You should have root acess.
Hope it helps
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).
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);
}
}
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..