Good afternoon, I have the following code in Android for take a photo and show in ImageView, the file photo is in the path when I check with filemanager, but dont show in ImageView and have the following message:
E/BitmapFactory: Unable to decode stream:
java.io.FileNotFoundException:
/storage/emulated/0/S3TAUDIT/photos/S3actual.png (No such file or
directory)
Please I need your help for finish my app. I use API 25 Android 7, permissions, options.inJustDecodeBounds. I have reviewed all posts with this error type and dont find solutions.
Thanks a lot.
package com.example.jorge.s3taudit;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Environment;
import android.os.StrictMode;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import java.io.File;
public class PICSSECTOR extends AppCompatActivity {
private final String carpeta_raiz="S3TAUDIT/";
private final String ruta_imagen=carpeta_raiz+"photos";
String path;
ImageView pics1actual;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_picssector);
public void pics1actual(View view) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
File pics1actualpng= new File(Environment.getExternalStorageDirectory(),ruta_imagen);
boolean isCreada =pics1actualpng.exists();
String nombre_imagen ="";
if (isCreada == false){
isCreada = pics1actualpng.mkdirs();
nombre_imagen = "S3actual.png";
}
if (isCreada==true){
nombre_imagen = "S3actual.png";
}
path = Environment.getExternalStorageDirectory()+File.separator +ruta_imagen+File.separator+ nombre_imagen;
File pics1actual =new File(path);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(pics1actual));
startActivityForResult(intent, 0);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
MediaScannerConnection.scanFile(this, new String[]{path}, null,
new MediaScannerConnection.OnScanCompletedListener() {
#Override
public void onScanCompleted(String s, Uri uri) {
Log.i("RUTA de almacenamiento", "Path: " + path);
}
});
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
ImageView pics1actual = (ImageView) findViewById(R.id.s1actual);
Bitmap bitmap = BitmapFactory.decodeFile(path,options);
pics1actual.setImageBitmap(bitmap);
}
}
}
The xml only for this action is:
<ImageView
android:id="#+id/s1actual"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_margin="4dp"
android:layout_weight="1"
android:background="#DDDDDD" />
<Button
android:id="#+id/ButtonPICS1actual"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableStart="#drawable/ic_stat_name"
android:onClick="pics1actual"
android:text="PHOTO"
android:textSize="20dp" />
This image I have in Debugger
Related
I am trying to make an applicaiton which takes has a camera. After clicking the picture you can save the image in phone. I have seen several tutorials and written the code accordingly(I am new in Android studio).
Yet I am getting syntax error where as others are not getting them.
I have two activities. Below is my MainActivity.java:
package com.none.www.dumpcam;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
String currentImagePath = null;
private ImageView mimageView;
private static final int IMAGE_REQUEST = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void captureImage(View view){
Intent imageTakeIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(imageTakeIntent.resolveActivity(getPackageManager())!=null){
File imageFile = null;
try {
imageFile = getImageFile();
} catch (IOException e){
e.printStackTrace();
}
if(imageFile!=null){
Uri imageUri = FileProvider.getUriForFile(context:this, authority:"com.example.android.fileprovider", imageFile); //one error is shown here
imageTakeIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(imageTakeIntent, IMAGE_REQUEST);
}
}
}
public void displayImage(View view){
Intent intent = new Intent(this,DisplayImage.class);
intent.putExtra(name: "image_path", currentImagePath);
startActivity(intent);
}
private file getImageFile() throws IOException{
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageName = "jpg_"+timeStamp+"_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File imageFile = File.createTempFile(imageName, suffix ".jpg", storageDir);
currentImagePath = imageFile.getAbsolutePath();
return imageFile;
}
}
Following is my DisplayImage.java:
package com.none.www.dumpcam;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
public class DisplayImage extends AppCompatActivity {
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_image);
imageView = findViewById(R.id.mimageView);
Bitmap bitmap = BitmapFactory.decodeFile(getIntent().getStringExtra( name: "image_path")); //One error is shown here.
imageView.setImageBitmap(bitmap);
}
}
Like I said I am writing the code from tutorials. There code is working fine.
I am getting the following syntax errors:
com/none/www/dumpcam/DisplayImage.java
error: ')' expected
error: ';' expected
error: illegal start of expression
error: ';' expected
com/none/www/dumpcam/MainActivity.java
error: ')' expected
error: not a statement
error: ';' expected
error: not a statement
error: ';' expected
error: not a statement
error: ';' expected
error: not a statement
error: not a statement
error: ')' expected
error: ';' expected
So I've managed to get a button to open a pdf file using an intent, however when i run the app and press the button it says "Cannot display PDF". Can anyone help me out as to where exactly the code goes wrong?
Here is the my activity:
package com.example.android.practiceapp;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import java.io.File;
public class promotions extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_promotions);
final Button button = (Button) findViewById(R.id.earlybird);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/pictures/Early_Bird_Bonus_Rules");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent1 = Intent.createChooser(intent, "Open With");
try {
startActivity(intent1);
} catch (ActivityNotFoundException e) {
// Instruct the user to install a PDF reader here, or something
}
}
});
}
}
I have an issue with my app that i cant solve. The app takes the input(reminder) from a user and then sets it as a notification. The user can create as many notifications as he/she likes. I want the user to click the notification and get taken to a new activity(Reminder), so he/she can see the reminder in a TextView. So i have an activity(SetReminder), which let the user put his data in a text editor.Then i save his data in a hashMap. The int is the id of user's string data. Then i have a class (AlarmReceiver) which extends BroacastReceiver and generates the notification.In this class i have an id for each notification,which matches the hashMap's int from the SetReminder activity. That way i was expecting that the user would see the data of each notification.But that's doesn't happen. I have multiple Notifications(i want that), but the user sees the data of the last notification, no matter which notifications selects. I am posting the code from the three activities.
Thanks in advance.
SetReminder.class
package demo.push_not_demo;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.SystemClock;
import android.widget.EditText;
import com.kunzisoft.switchdatetime.SwitchDateTimeDialogFragment;
import java.util.HashMap;
public class SetReminder extends AppCompatActivity {
private SwitchDateTimeDialogFragment dateTimeFragment;
Button b1,b2,b3;
EditText editText;
public static int counter=0;
public static HashMap<Integer,String> hashMap;
private static final String TAG_DATETIME_FRAGMENT = "TAG_DATETIME_FRAGMENT";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.set_reminder);
hashMap= new HashMap<Integer, String>();
b1=(Button) findViewById(R.id.set_date_time);
b2=(Button) findViewById(R.id.cancel);
b3=(Button) findViewById(R.id.save);
b1.setOnTouchListener(touch);
b2.setOnTouchListener(touch);
b3.setOnTouchListener(touch);
editText=(EditText) findViewById(R.id.reminder_edit);
}
View.OnTouchListener touch= new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (v.getId()){
case R.id.set_date_time:
if (event.getAction()==MotionEvent.ACTION_DOWN){
v.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
v.invalidate();
}
else if (event.getAction()== MotionEvent.ACTION_UP){
v.getBackground().clearColorFilter();
v.invalidate();
// Construct SwitchDateTimePicker
dateTimeFragment = (SwitchDateTimeDialogFragment) getSupportFragmentManager().findFragmentByTag(TAG_DATETIME_FRAGMENT);
if(dateTimeFragment == null) {
dateTimeFragment = SwitchDateTimeDialogFragment.newInstance(
getString(R.string.label_datetime_dialog),
getString(R.string.positive_button_datetime_picker),
getString(R.string.negative_button_datetime_picker)
);
}
dateTimeFragment.show(getSupportFragmentManager(), TAG_DATETIME_FRAGMENT);
}
break;
case R.id.cancel:
if (event.getAction()==MotionEvent.ACTION_DOWN){
v.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
v.invalidate();
cancelalarm();
}
else if (event.getAction()== MotionEvent.ACTION_UP){
v.getBackground().clearColorFilter();
v.invalidate();
Intent intent = new Intent(SetReminder.this,HomeScreen.class);
startActivity(intent);
}
break;
case R.id.save:
if (event.getAction()==MotionEvent.ACTION_DOWN){
v.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
v.invalidate();
}
else if (event.getAction()== MotionEvent.ACTION_UP){
v.getBackground().clearColorFilter();
v.invalidate();
counter++;
hashMap.put(counter,editText.getText().toString());
alarmservice();
}
break;
}
return false;
}
};
public void alarmservice(){
Intent intent = new Intent(this,AlertReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(alarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime()+ 5000,pendingIntent);
}
public void cancelalarm(){
Intent intent = new Intent(this,AlertReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
}
}
AlertReceiver.class
package demo.push_not_demo;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.widget.EditText;
import java.util.HashMap;
import static android.support.v4.app.NotificationCompat.DEFAULT_SOUND;
import static android.support.v4.app.NotificationCompat.PRIORITY_HIGH;
import static android.support.v4.app.NotificationCompat.VISIBILITY_PUBLIC;
public class AlertReceiver extends BroadcastReceiver {
public static int id=0;
#Override
public void onReceive(Context context, Intent intent) {
id++;
createNotification(context);
}
private void createNotification(Context context) {
NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
.setAutoCancel(true)
.setSmallIcon(R.drawable.offer1)
.setContentTitle("Notification Title")
.setContentText("Tap to see your reminder")
.setPriority(PRIORITY_HIGH)
.setVibrate(new long[] { 50, 1000, 500, 1000, 1000 })
.setDefaults(DEFAULT_SOUND)
.setVisibility(VISIBILITY_PUBLIC);
Intent intent = new Intent(context,Reminder.class);
PendingIntent pendingintent = PendingIntent.getActivity(context,id,intent,PendingIntent.FLAG_ONE_SHOT);
notification.setContentIntent(pendingintent);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification ntfc = notification.build();
nm.notify(id,ntfc);
}
}
Reminder.class
package demo.push_not_demo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import static demo.push_not_demo.AlertReceiver.id;
import static demo.push_not_demo.SetReminder.hashMap;
public class Reminder extends AppCompatActivity{
TextView txtv;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder);
txtv=(TextView) findViewById(R.id.reminder_textView);
txtv.setText(hashMap.get(id));
}
}
dont use static id,in your code id is always 0. you can check it using Log!
use another way for produce different ids.
when you add notification with same id, the new notification will replace with last notification. use random integer for id
I made a simple app that reads images and retrieves the number image as text with android. But the problem is that the accuracy is only about 60% and some unwanted noise also shows as well. I do perceive that the accuracy cannot be good as 100%,however, I believe that there must be a way to improve it. But, since I'm an amateur, I find it difficult. I've searched around google but was unable to gain a solid information.
I want to read the numbers 596 , 00 , and 012345 from a oriental lucky tickets like the image below.
Tesseract-ocr works best on images of characters which meet the following criteria:
The input image should have atleast 300 dpi
The input image should be black and white
There should be minimal noise in the input image (i.e. the text should be clearly distinguishable from the background)
Text lines should be straight
The image should be centered around the text to be detected
(See the tesseract-ocr wiki for further details)
For a given input image, tesseract will try to pre-process and clean the image to meet these criteria, but to maximise your detection accuracy, it is best to do the pre-processing yourself.
Based on the input image you provided, the main problem is that there is too much background noise. To remove the background noise from the text in the image, I have found that applying the Stroke Width Transform (SWT) algorithm with a threshold value to remove noise gives promising results. A fast implementation of SWT with many configurable parameters is provided in the libCCV library. How well it cleans the image depends on a number of factors including image size, uniformity of stroke width and other input parameters to the algorithm. A list of the configurable parameters is provided here.
You then pass the output of SWT to tesseract to obtain the text values of characters in the image.
If the image passed to tesseract still contains some noise, it may return some false detections such as punctuation characters. Given that the image you are processing is likely to only contain letters and numbers a-z A-Z 0-9, you can simply apply a regex to the output to remove any final false detections.
you can use Vision for text detection.
Add dependency in app gradle
compile 'com.google.android.gms:play-services-vision:10.0.0'
Add in Manifest.xml
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="ocr" />
MainActivity.java
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.text.TextBlock;
import com.google.android.gms.vision.text.TextRecognizer;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_GALLERY = 0;
private static final int REQUEST_CAMERA = 1;
private static final String TAG = MainActivity.class.getSimpleName();
private Uri imageUri;
private TextView detectedTextView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.choose_from_gallery).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, REQUEST_GALLERY);
}
});
findViewById(R.id.take_a_photo).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String filename = System.currentTimeMillis() + ".jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, filename);
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, REQUEST_CAMERA);
}
});
detectedTextView = (TextView) findViewById(R.id.detected_text);
detectedTextView.setMovementMethod(new ScrollingMovementMethod());
}
private void inspectFromBitmap(Bitmap bitmap) {
TextRecognizer textRecognizer = new TextRecognizer.Builder(this).build();
try {
if (!textRecognizer.isOperational()) {
new AlertDialog.
Builder(this).
setMessage("Text recognizer could not be set up on your device").show();
return;
}
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<TextBlock> origTextBlocks = textRecognizer.detect(frame);
List<TextBlock> textBlocks = new ArrayList<>();
for (int i = 0; i < origTextBlocks.size(); i++) {
TextBlock textBlock = origTextBlocks.valueAt(i);
textBlocks.add(textBlock);
}
Collections.sort(textBlocks, new Comparator<TextBlock>() {
#Override
public int compare(TextBlock o1, TextBlock o2) {
int diffOfTops = o1.getBoundingBox().top - o2.getBoundingBox().top;
int diffOfLefts = o1.getBoundingBox().left - o2.getBoundingBox().left;
if (diffOfTops != 0) {
return diffOfTops;
}
return diffOfLefts;
}
});
StringBuilder detectedText = new StringBuilder();
for (TextBlock textBlock : textBlocks) {
if (textBlock != null && textBlock.getValue() != null) {
detectedText.append(textBlock.getValue());
detectedText.append("\n");
}
}
detectedTextView.setText(detectedText);
}
finally {
textRecognizer.release();
}
}
private void inspect(Uri uri) {
InputStream is = null;
Bitmap bitmap = null;
try {
is = getContentResolver().openInputStream(uri);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inSampleSize = 2;
options.inScreenDensity = DisplayMetrics.DENSITY_LOW;
bitmap = BitmapFactory.decodeStream(is, null, options);
inspectFromBitmap(bitmap);
} catch (FileNotFoundException e) {
Log.w(TAG, "Failed to find the file: " + uri, e);
} finally {
if (bitmap != null) {
bitmap.recycle();
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
Log.w(TAG, "Failed to close InputStream", e);
}
}
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_GALLERY:
if (resultCode == RESULT_OK) {
inspect(data.getData());
}
break;
case REQUEST_CAMERA:
if (resultCode == RESULT_OK) {
if (imageUri != null) {
inspect(imageUri);
}
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="org.komamitsu.android_ocrsample.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/choose_from_gallery"
android:id="#+id/choose_from_gallery"
tools:context=".MainActivity"
android:layout_marginTop="23dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/take_a_photo"
android:id="#+id/take_a_photo"
tools:context=".MainActivity"
android:layout_marginTop="11dp"
android:layout_below="#+id/choose_from_gallery"
android:layout_centerHorizontal="true" />
<TextView
android:text=""
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/detected_text"
android:layout_alignParentBottom="true"
android:layout_below="#+id/take_a_photo"
android:layout_margin="25dp"
android:layout_centerHorizontal="true"
android:background="#EEEEEE"
android:scrollbars="vertical" />
</RelativeLayout>
i have create an android application that will capture picture and save in sdcard folder,now i want to save the image with a custom name.
import java.io.ByteArrayOutputStream;
import android.view.Menu;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.imageView = (ImageView) this.findViewById(R.id.imageView1);
Button photoButton = (Button) this.findViewById(R.id.button1);
photoButton.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI.getPath());
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, "new-photo-name.jpg");
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
MediaStore.Images.Media.insertImage(getContentResolver(), photo,
null, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
}
}
here is the code which i have used for capturing the image and save them in the sd card folder,please help me to save the image with a specific name for eg:android.jpeg
File outFile = new File(Environment.getExternalStorageDirectory(), "myname.jpeg");
FileOutputStream fos = new FileOutputStream(outFile);
photo.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
you would also need to add Permission in Android Manifest.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
the snippet will save the content of photo inside /sdcard with the name "myname.jpeg"
You need to put fileName as Intent Extras -
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, "android.jpg");
this article maybe useful, try it.
& this as well, the only different that he used the date as a default name.
change it.
It usually works :)