Take a screenshot android (continue) - android

first of all sorry.. but i cant answer in
Android take screen shot programmatically cause dont have enought reputation.
The code works fine! thanks.. but.. when i take the screenshot.. the file is stored in the root folder
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, getString(R.string.tituloAplicacion)+".jpg");
but also appears in the Camera DCM folder with another name, its possible avoid that?
Thanks

Related

How to get Internal and External SDcard path ?

I want to open file manager on a button click and want to get the path of a particular item on selection of that particular item.
File f=new File(Environment.getexternalstoragedirectory());
btn.setonclicklistener(new Onclicklistener){
onClick{
if(f.isDirectory){
}else{
//do what u want to do with file
}}}
To get SDCard path....
String sdcardPath = Environment.getExternalStorageDirectory().getAbsolutePath();
This will give you the "files" directory for your app external / internal.
context.getExternalFilesDir(null);
context.getFilesDir();
There's no built in android file picker. You need an entire module / activity. You can perhaps get one searching github, like this one here sounds like what you're looking for.
You can ask the user to select a file using the new Intent.ACTION_OPEN_DOCUMENT intent in KitKat.

Make picture available only for my Android application

I have an application which has loads of pictures. The total picture is saved in an SD card due to large number of picture. The main problem is that the pictures are available in gallery. I want a way to hide the picture from the gallery but must be available for my application.
I did put " . " in front of the file name to make it hidden
but the images were not displayed in may application also!
Anyone.. help.. please
thanks..
Gallery handles all media files it knows about, so if you want it to stay away of your assets you got two solutions. First, add .nomedia file to the folder with your images, and Gallery should skip it (most image viewers would honor .nomedia, yet there's no guarantee). Other solution is to use some own, proprietary file format, so Gallery or other tools won't be able to process it. I'd recomment .nomedia if that's sufficient solution.
Add .nomedia file into the image folder. The important thing is that, the folder should be empty, when you add .nomedia file. If the folder contains some images before adding '.nomedia' file, the gallery will not hide those images, and it will hide the images added after '.nomedia' file. So The first file added to the image folder should be '.nomedia'.
Hope dis will help you
Thankx,
This line of code can add the .nomedia file in your directory and makes your images hidden from the gallery
String NOMEDIA=" .nomedia";
File Folder = new File(Environment.getExternalStorageDirectory() + "/mydir");
if(Folder.mkdir()) {
nomediaFile = new File(Environment.getExternalStorageDirectory() + "/mydir/"+ NOMEDIA);
if(!nomediaFile.exists()){
nomediaFile.createNewFile();
}
}
i think the place where you save the images matter, try to save them into application cache directory, or files directory.
you can get access to cache directory using : getCacheDir() in your activity.
and your files directory: getFilesDir()
these two directories must not be visible or accessible to any other applications expect your application,
I used assets to accomplish this in my app.

Android picture saved to SD card not showing in Gallery

Currently I have a program that takes pictures and saves them as a jpg on the top level of the sdcard, but its not appearing in the Gallery. Is there something I must do to make it happen?
You need to call the MediaScanner so that it knows your file exists:
File file; // = your file
String mimetype; // = your file's mimetype. MimeTypeMap may be useful.
MediaScanner.scanFile(getApplicationContext(), new String[]{file.getPath()}, new String[]{mimetype}, null);
Try this answer. Working for me
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(finalFile)));
Maybe someone is "overseeing" it...
Take a look at:
https://stackoverflow.com/a/5110571/371749

Android: Saving a created bitmap to some equivalent of SharedPreferences?

So I'm having the user create a profile, which includes an avatar. I would like the program to, like the user's name and other info, remember the avatar so it appears as their avatar whenever they use the app. I'd prefer for this bitmap to be saved when created, so the app doesn't need to rebuild the avatar (which is scaled and whatnot) each time the app is started. Is this possible? From the looks of it this wouldn't be able to be saved in SharedPrefs... any idea what the best way to do this would be? Thanks.
Followup: Followed CommonWares's suggestion. Saved to SD... but having trouble calling it back when the app is reloaded.
Currently, in onCreate:
String path = "testapp/images/thumbs/"+m_username+".jpg";
File file = new File("testapp/images/thumbs/"+m_username+".jpg");
if(file.exists()) {
Log.e("TRY TO GET THUMB", "I EXIST");
m_thumb = BitmapFactory.decodeFile(path);
Drawable draw = new BitmapDrawable(getResources(), m_thumb);
m_photoButtonE.setBackgroundDrawable(draw);
}
Does not find the file, says it does not exist, though when I check my SD card the image is in that exact spot, with the proper file name and everything. Any ideas? Thanks all.
Is this possible?
Save it in a file.
From the looks of it this wouldn't be able to be saved in SharedPrefs... any idea what the best way to do this would be?
Save it in a file. If you intend on having multiple avatar files, put a path to the saved avatar file in the SharedPreferences.

FileNotFoundExcecption while inserting image into SDCard

I want to insert images into my SDCard.So I used below code
m_cImagePath = "/sdcard/"+ String.format("%d.jpg", System.currentTimeMillis());
FileOutputStream lObjOutStream = null;
try {
lObjOutStream = new FileOutputStream(m_cImagePath);
if (null != lObjOutStream && null != finalBitmap) {
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 85, lObjOutStream);
lObjOutStream.close();
}catch(FileNotFoundException fe){
fe.printStackTrace();
}
Sometimes it is giving FileNotFoundException even my SDCard had memory.When I remove some images from sdcard again it is working smoothly.Why this Happend?How can i know that file is inserted successfully in SDCard and Is there any functionality in Java1.5 to know available space of the SDCard like java 1.6?How can i know file length which is not before inserting into the SDCard(I searched in google and found that
"when the file is not physically there
then file.length() always gives 0"
).But before inserting i want to know the length of the file.Then Comparing this space to available SDCard space is simple.
Note :I had an idea to use Unix command
df sdcard
using in
Runtime class
to found SDCard space.
Please give me an idea in this problem.
Regards,
Android Developer
Never never never never never hardcode /sdcard in an Android application. First, it's wrong on Android 2.2+. Second, it's wrong on other devices as well. Always use Environment.getExternalStorageDirectory() for the root of external storage.
Is there any functionality in Java1.5 to know available space of the SDCard like java 1.6?
android.os.StatFs has what you need.

Categories

Resources