How can we Retrive the 3gp file from sdcard into our application? - android

I'm new to Andriod development and was wondering how I could retrieve the 3gp file from an SD card into my application?

try this (one of the many way to do that)
String FilePath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/your/file/directory"+ "YOURFILENAME";
File 3gpFile = new File(FilePath);
now go ahead and use 3gpFile to do other stuff
remember to have uses-permission in your manifest file
<uses-permission android:name"android.permission.WRITE_EXTERNAL_STORAGE"/>

Related

Trying to save a file on an android system and make it downloadable by the user

I am sorry I am extremely new to android and I am lost. I successfully found out how to save a file on an android system, but every time I try to search for the file on my Android phone (which is where I have a copy of this app located) I am unable to locate it. I know it is there because the app would not start up with out it. How do you write a file that can be both used by the App AND searched by the user in the File Explorer. I am using a Galaxy Note 3 Android version 5.0 Any help would be appreciated.
private void WriteFile(String FileName, String FileCont, boolean isAppend){
File file = new File(getApplicationContext().getFilesDir().getAbsolutePath() + "/" + FileName);
try {
FileOutputStream stream = new FileOutputStream(file, isAppend);
stream.write(FileCont.getBytes());
stream.close();
}
catch(Exception ex){
}
}
Did set the permissions to write on external space in your manifest.xml?
For reference see
http://developer.android.com/reference/android/Manifest.permission.html
You have to set the "WRITE_EXTERNAL_STORAGE" permission to write on external disk. Just add the following line to your android manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
It will implicitly contain the permission to read external storage as well ;).

create visible folder sdcard, Android

I'm developping an application where I need to create new folders/files in the sdcard. The thing is I can see them using a root explorer but not with the default one which comes with Android.
I've taken a look at several similar questions here but don't seem to work for me.
For sure, I'm using in my manifest this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
and I'm writing all the Files using:
String path = Environment.getExternalStorageDirectory() + "/FolderName/FileName.format"
but as I said, these new folders/files remained hidden and can only be seen using a root explorer. Neither the folder nor file name starts with "."
Thanks in advance.
Try using mkDirs()
File dir = new File(fullPath);
if (!dir.exists()) {
dir.mkdirs();
}

How can we create a new folder for our app where we can save the downloaded data

I am developing an app that downloads the MP 3 files. I want to know how to create a new folder for my app that is visible in MY FILES of android and saves all the downloaded files into it.
Do you mean something like:
File theDirectory = new File("/sdcard/yourdir/");
theDirectory.mkdirs();
File outputFile = new File(theDirectory, filename);
Also, you probably want to use Environment.getExternalStorageDirectory() and also add:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
What do you mean with "MY FOLDERS"?
In general, you have to create a new File in an specific Folder:
File f = new File(getFilesDir(), "dateiname.mp3");

Android: Save data to internal memory using Download

I am downloading file from a server in Android using the DownloadManager class. I want to store this file in the internal memory of the device. I tried to use .setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory() +"/Android/data/xxx.xxx.xxx/files/") as mentioned here, but it is not working. How to solve my problem?
add
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to manifest.xml and create "/Android/data/xxx.xxx.xxx/files/" path
try this
File testDirectory = new File(Environment.getExternalStorageDirectory() +"/Android/data/xxx.xxx.xxx/files/");
and
if (!testDirectory.exists()) {
testDirectory.mkdirs();
}

save image to sdcard android Directory problem

Im trying to save data to sdCard first i tried to saave it privately within app directory on externalStorage using getExternalFilesDir but gives me nullPointerException so i tried the other way given below it worked but when i want to store files into a custom directory that i want to named myself it give me error:
FileOutputStream os;
dirName = "/mydirectory/";
try {
if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)){
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + dirName);
dir.mkdirs();
//File file = new File(this.getExternalFilesDir(null), this.dirName+fileName); //this function give null pointer exception so im using other one
File file = new File(dir, dirName+fileName);
os = new FileOutputStream(file);
}else{
os = context.openFileOutput(fileName, MODE_PRIVATE);
}
resizedBitmap.compress(CompressFormat.PNG, 100, os);
os.flush();
os.close();
}catch(Exception e){
}
ErrorLog:
java.io.FileNotFoundException: /mnt/sdcard/mvc/mvc/myfile2.png (No such file or directory)
Your directory "/mnt/sdcard/mvc/mvc" may not exist. What about changing your path to store the image in the Environment.getExternalStorageDirectory() path and then working from there?
Also, as Robert pointed out, make sure you have write permission to external storage in your manifest.
Edit - to create directories:
String root = Environment.getExternalStorageDirectory().toString();
new File(root + "/mvc/mvc").mkdirs();
Then you can save a file to root + "/mvc/mvc/foo.png".
Have you requested permission to write onto SD card? Add the following string to you app manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You should check if you have added the required permission android.permission-group.STORAGE to your app. Without that permission you won't be able to access anything on the SD-Card.
BTW: On the Android system I know the SD-card is mounted on /sdcard not /mnt/sdcard
I found this book to be very helpful: "Pro Android Media: Developing Graphics, Music, Video, and Rich Media Apps for Smartphones and Tablets". I noticed a part that allows saving images and stuff to the SD card.

Categories

Resources