I am making a birthday wisher app, everthing works fine but I want that user can select image from gallary and it passes to 2nd activity, when timer is finised, I used ticker coundown in this.
My MainActivity
public class MainActivity extends AppCompatActivity {
CircularView circularViewWithTimer;
EditText entertime;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
);
entertime = (EditText) findViewById(R.id.Txt_time);
circularViewWithTimer = findViewById(R.id.circular_view);
CircularView.OptionsBuilder builderWithTimer =
new CircularView.OptionsBuilder()
.shouldDisplayText(true)
.setCounterInSeconds(15)
.setCircularViewCallback(new CircularViewCallback() {
#Override
public void onTimerFinish() {
String name = entertime.getText().toString();
Intent i = new Intent(MainActivity.this, Bday_page.class);
i.putExtra("text", name);
startActivity(i);
finish();
}
#Override
public void onTimerCancelled() {
// Will be called if stopTimer is called
Toast.makeText(MainActivity.this, "CircularCallback: Timer Cancelled ", Toast.LENGTH_SHORT).show();
}
});
circularViewWithTimer.setOptions(builderWithTimer);
}
public void btn_pause(View view) {
circularViewWithTimer.pauseTimer();
}
public void btn_start(View view) {
MediaPlayer mMediaPlayer;
if(entertime.getText().toString().isEmpty()){
Toast.makeText(this, "Enter name of bday boy", Toast.LENGTH_SHORT).show();
}
else {
circularViewWithTimer.startTimer();
mMediaPlayer = new MediaPlayer();
mMediaPlayer = MediaPlayer.create(this,R.raw.count);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setLooping(true);
mMediaPlayer.start();
}
}
public void btn_resume(View view) {
circularViewWithTimer.resumeTimer();
}
}
My 2nd Activity
public class Bday_page extends AppCompatActivity {
TextView nameuser;
MediaPlayer mMediaPlayer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bday_page);
nameuser = (TextView)findViewById(R.id.txt_imagename);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
);
mMediaPlayer = new MediaPlayer();
mMediaPlayer = MediaPlayer.create(this, R.raw.happybady);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setLooping(true);
mMediaPlayer.start();
Intent i = getIntent();
nameuser.setText(i.getStringExtra("text"));
}
}
first of all you have to request the storage permission in the manifest
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
after that in your MainActivity make your onTimerFinish methods like these
#Override
public void onTimerFinish() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent,1777);
}
now you requsted the image from Galary then add onActivityResult method to your main activity to receive the image
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ( resultCode == Activity.RESULT_OK) {
if (requestCode == CAMERA_REQUEST) {
Uri uri = data.getData();
Cursor cursor;
String[] filePathColumn = { MediaStore.Images.Media.DATA };
cursor = getContentResolver().query(uri,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
picturePath = cursor.getString(columnIndex);
cursor.close();
String name = entertime.getText().toString();
Intent i = new Intent(MainActivity.this, Bday_page.class);
i.putExtra("text", name);
i.putExtra("imagePath",picturePath )
startActivity(i);
finish();
}}}
now you get the path of selected image and send it to the next activity
and in your 2nd Activity receive the image like these
Intent i = getIntent();
nameuser.setText(i.getStringExtra("text"));
String imagePath = i.getStringExtra("imagePath") //add these
now you have the image Path in the new activity you can do what you want to do with it
Related
I am making an app that sends a picture taken from the Camera app however the image it returns seems to be only a thumbnail how can I get it to turn the whole image?
The following code gets an image, but it's too small.
public class OnTheJobActivity extends Activity{
private static final int CAMERA_PIC_REQUEST = 1337;
private Button takePictureButton;
private Button sendPictureButton;
private Bitmap thumbnail;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.onthejob);
takePictureButton = (Button) findViewById(R.id.takePictureButton);
takePictureButton.setOnClickListener(takePictureButtonListener);
sendPictureButton = (Button) findViewById(R.id.sendPictureButton);
sendPictureButton.setOnClickListener(sendPictureButtonListener);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) findViewById(R.id.photoResultView);
image.setImageBitmap(thumbnail);
sendPictureButton.setVisibility(Button.VISIBLE);
}
}
private OnClickListener takePictureButtonListener = new OnClickListener() {
#Override
public void onClick(View arg0){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
};
private OnClickListener sendPictureButtonListener = new OnClickListener() {
#Override
public void onClick(View arg0){
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL, "abc#gmail.com");
i.putExtra(Intent.EXTRA_SUBJECT,"On The Job");
i.putExtra(Intent.EXTRA_STREAM, thumbnail);
i.setType("image/bmp");
startActivity(Intent.createChooser(i,"Emailfile"));
}
};
}
You could also change the intent you're using.
//in your buttonListener
ContentValues values = new ContentValues();
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
//create new Intent
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
try{
startActivityForResult(i, ACTIVITY_GET_IMAGE);
}
catch(Exception ex){
Log.v("BRE", ex.toString());
}
//in your activity
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == ACTIVITY_GET_IMAGE){
if(resultCode == RESULT_OK){
try{String uri = data.getData().toString()}
catch(NullPointerException e){//do something}
}
}
}
This will return a uri which you can then use to access the full resolution image
Try using the implementation shown here
Specifically:
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] imageData, Camera c) {
}
};
My Main2Activity class
public class Main2Activity extends AppCompatActivity {
private static int PICK_IMAGE_REQUEST = 1;
ImageView imgView;
static final String TAG = "Main2Activity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
public void loadImagefromGallery(View view) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && null != data) {
final Uri uri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
int nh = (int) (bitmap.getHeight() * (1024.0 / bitmap.getWidth()));
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 1024, nh, true);
imgView = (ImageView) findViewById(imageView);
imgView.setImageBitmap(scaled);
Button button3 = (Button) findViewById(bt_tab3);
button3.setOnClickListener
(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Main3Activity.class);
intent.setData(uri).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
});
} else {
Toast.makeText(this, "No.", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Oops! Sorry", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
And the Main3Activity
public class Main3Activity extends AppCompatActivity {
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
imageView = (ImageView) findViewById(R.id.imageView2);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Uri imageUri = getIntent().getData();
imageView.setImageURI(imageUri);
}
}
How can I show same gallery image in MainActivity and another Activity?
Move your Button related codes into onCreate() and send Uri as String using intent extras.
Update Main2Activity as below:
public class Main2Activity extends AppCompatActivity {
static final String TAG = "Main2Activity";
private static int PICK_IMAGE_REQUEST = 1;
ImageView imgView;
Button button3;
Uri imageUri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
imgView = (ImageView) findViewById(R.id.imageView);
button3 = (Button) findViewById(R.id.bt_tab3);
button3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Main3Activity.class);
intent.putExtra("imageUri", imageUri.toString());
startActivity(intent);
}
});
}
public void loadImagefromGallery(View view) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && null != data) {
// Get uri
imageUri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
int nh = (int) (bitmap.getHeight() * (1024.0 / bitmap.getWidth()));
Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 1024, nh, true);
// Set image
imgView.setImageBitmap(scaled);
} else {
Toast.makeText(this, "No.", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Oops! Sorry", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
Get Uri as string from intent and construct Uri from string using Uri.parse() method.
Update Main3Activity as below:
public class Main3Activity extends AppCompatActivity {
ImageView imageView;
Uri imageUri;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
imageView = (ImageView) findViewById(R.id.imageView2);
if (getIntent().getExtras() != null) {
imageUri = Uri.parse(getIntent().getStringExtra("imageUri"));
imageView.setImageURI(imageUri);
}
}
}
Pass the file path from the uri as String like this to Main3Activity.
button3.setOnClickListener
(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Main3Activity.class);
intent.putExtra("filePath", uri.getPath());
startActivity(intent);
}
});
And in Main3Activity get the data passed from the calling Activity like this.
public class Main3Activity extends AppCompatActivity {
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
imageView = (ImageView) findViewById(R.id.imageView2);
File file = new File(getIntent().getStringExtra("filePath"));
setImageFromFileIntoImageView(file);
}
private void setImageFromFileIntoImageView (File imgFile)
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(myBitmap);
}
}
}
You need to add the following permission in your AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
based on you not accepting previous answers here is a different approach :
first convert your image to byte array like :
Bitmap bm = BitmapFactory.decodeFile("/path/to/image.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is bitmap object
byte[] b = baos.toByteArray();
then convert that into string like :
String encodedImage = Base64.encodeToString(byteArrayImage, Base64.DEFAULT);
then from your first activity make an intent and put that string as an extra like:
Intent imageIntent = new Intent(context,Main3Activity.class);
imageIntent.putExtra("image",encodedImage);
startActivity(imageIntent);
and after that it is so easy to get this string in the next activity using getIntent and then getExtra
hope this helps.
I am new with android and i am making a simple application where i will get a video from local device and play it in a videoview in my layout. Playing the video works fine but when i change orientation from portrait to landscape, the video disappear. I believe i need to save the state of the activity. Here is my code.
public class MainActivity extends AppCompatActivity {
private int position = 0;
private VideoView vidView;
private static int RESULT_LOAD_VIDEO = 1;
String vidDecodableString;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button buttonLoadVideo = (Button)findViewById(R.id.buttonLoadVideo);
this.vidView = (VideoView)findViewById(R.id.myVideo);
buttonLoadVideo.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_VIDEO);
}
});
}
#Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
try {
if (requestCode == RESULT_LOAD_VIDEO && resultCode == RESULT_OK && null != data){
Uri selectedVideo = data.getData();
String[] filePathColumn = { MediaStore.Video.Media.DATA };
Cursor cursor = getContentResolver().query(selectedVideo, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
vidDecodableString = cursor.getString(columnIndex);
//URI
Uri vidUri = Uri.parse(vidDecodableString);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.start();
} else {
Toast.makeText(this, "Please select video to play.", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong.", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putInt("Position", vidView.getCurrentPosition());
vidView.pause();
}
#Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
position = savedInstanceState.getInt("Position");
vidView.seekTo(position);
}
}
After i run the code, the selecting and playing of the video works but when i change the orientation, the video loaded disappear. Where am i doing wrong. Please advice.
add this attribute in manifest
<activity
android:name=".YourActivity"
android:configChanges="keyboardHidden|orientation|screenSize" />
Here, I have to select an image from gallery or camera. When user selects image from gallery, that selected image should be displayed to next activity. But here these both activities are under the same tab, say tab A. Means in tab A there are two activities. In first activity, user has two options to select image either from gallery or from camera. And in second activity under same tab A, user gets that selected image. But here I'm not getting the expected output. Below is my code...
MainActivity.java
public class MainActivity extends TabActivity {
TabHost tabHost;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources ressources = getResources();
tabHost = getTabHost();
Intent intentProfile = new Intent().setClass(this, Tab1.class);
TabSpec tabProfile = tabHost
.newTabSpec("Profile")
.setIndicator("Profile", ressources.getDrawable(R.drawable.ic_launcher))
.setContent(intentProfile);
Intent intentFriends = new Intent().setClass(this, Tab2.class);
TabSpec tabFriends = tabHost
.newTabSpec("Friends")
.setIndicator("Friends", ressources.getDrawable(R.drawable.ic_launcher))
.setContent(intentFriends);
tabHost.addTab(tabProfile);
tabHost.addTab(tabFriends);
tabHost.setCurrentTab(0);
}
public void switchTabBar(int tab) {
tabHost.setCurrentTab(tab);
}
#Override
public void onBackPressed() {
// Called by children
MainActivity.this.finish();
}
}
ABCGroup.java
public class ABCGroup extends ActivityGroup{
public static ABCGroup group;
private ArrayList<View> history;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.history = new ArrayList<View>();
group = this;
View view = getLocalActivityManager().startActivity
("ParentActivity",
new Intent(ABCGroup.this, Tab1.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
replaceView(view);
}
public void replaceView(View v) {
// Adds the old one to history
history.add(v);
// Changes this Groups View to the new View.
setContentView(v);
}
public void back() {
if(history.size() > 0) {
history.remove(history.size()-1);
if(history.size()<=0){
finish();
}else{
setContentView(history.get(history.size()-1));
}
}else {
finish();
}
}
#Override
public void onBackPressed() {
ABCGroup.group.back();
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_BACK){
ABCGroup.group.back();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
Tab1.java
public class Tab1 extends ActivityGroup {
Button gallery, camera;
private ArrayList<View> myActivityHistory;
private static final int REQUEST_ID = 1;
private static final int HALF = 2;
private static final int TAKE_PICTURE = 3;
private Uri mUri;
private Bitmap mPhoto;
int i = 0;
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
myActivityHistory = new ArrayList<View>();
gallery = (Button)findViewById(R.id.gallery);
camera = (Button)findViewById(R.id.camera);
gallery.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_ID);
}
});
camera.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
File f = new File(Environment.getExternalStorageDirectory(), "photo.jpg");
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
mUri = Uri.fromFile(f);
startActivityForResult(i, TAKE_PICTURE);
}
});
}
public void replaceContentView(String id, Intent newIntent, int flag)
{
View mview = getLocalActivityManager().startActivity(id,newIntent.addFlags(flag)).getDecorView();
ABCGroup.group.replaceView(mview);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case TAKE_PICTURE:
if (resultCode == Activity.RESULT_OK)
{
getContentResolver().notifyChange(mUri, null);
ContentResolver cr = getContentResolver();
try
{
mPhoto = null;
mPhoto = android.provider.MediaStore.Images.Media.getBitmap(cr, mUri);
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
}
catch (Exception e)
{
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
break;
case REQUEST_ID :
InputStream stream = null;
if (resultCode == Activity.RESULT_OK) {
try
{
stream = getContentResolver().openInputStream(data.getData());
Bitmap original;
original = null;
original= BitmapFactory.decodeStream(stream);
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
Intent in = new Intent(Tab1.this, Second.class);
replaceContentView("activity3", in, Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
catch (Exception e)
{
e.printStackTrace();
}
if (stream != null) {
try {
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
break;
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
Toast.makeText(getBaseContext(), "" + cursor.getString(column_index) , 5000).show();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor editor = preferences.edit();
editor.putString("data", cursor.getString(column_index) );
editor.commit();
return cursor.getString(column_index);
}
}
Second.java
public class Second extends ActivityGroup {
public static Bitmap bmp;
String path;
ImageView iv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Button btn = (Button)findViewById(R.id.button1);
iv = (ImageView)findViewById(R.id.imageView1);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
path = preferences.getString("data", "");
File imgFile = new File(path);
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
iv.setImageBitmap(myBitmap);
}
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
ABCGroup.group.back();
}
});
}
#Override
public void onBackPressed() {
// this.getParent().onBackPressed();
Intent intent = new Intent(Second.this, Tab1.class);
Tab1 parentActivity = (Tab1)getParent();
parentActivity.replaceContentView("Profile", new Intent(Second.this, Tab1.class), Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
}
I am making an app that sends a picture taken from the Camera app however the image it returns seems to be only a thumbnail how can I get it to turn the whole image?
The following code gets an image, but it's too small.
public class OnTheJobActivity extends Activity{
private static final int CAMERA_PIC_REQUEST = 1337;
private Button takePictureButton;
private Button sendPictureButton;
private Bitmap thumbnail;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.onthejob);
takePictureButton = (Button) findViewById(R.id.takePictureButton);
takePictureButton.setOnClickListener(takePictureButtonListener);
sendPictureButton = (Button) findViewById(R.id.sendPictureButton);
sendPictureButton.setOnClickListener(sendPictureButtonListener);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) findViewById(R.id.photoResultView);
image.setImageBitmap(thumbnail);
sendPictureButton.setVisibility(Button.VISIBLE);
}
}
private OnClickListener takePictureButtonListener = new OnClickListener() {
#Override
public void onClick(View arg0){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
};
private OnClickListener sendPictureButtonListener = new OnClickListener() {
#Override
public void onClick(View arg0){
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_EMAIL, "abc#gmail.com");
i.putExtra(Intent.EXTRA_SUBJECT,"On The Job");
i.putExtra(Intent.EXTRA_STREAM, thumbnail);
i.setType("image/bmp");
startActivity(Intent.createChooser(i,"Emailfile"));
}
};
}
You could also change the intent you're using.
//in your buttonListener
ContentValues values = new ContentValues();
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
//create new Intent
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
try{
startActivityForResult(i, ACTIVITY_GET_IMAGE);
}
catch(Exception ex){
Log.v("BRE", ex.toString());
}
//in your activity
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == ACTIVITY_GET_IMAGE){
if(resultCode == RESULT_OK){
try{String uri = data.getData().toString()}
catch(NullPointerException e){//do something}
}
}
}
This will return a uri which you can then use to access the full resolution image
Try using the implementation shown here
Specifically:
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] imageData, Camera c) {
}
};