Android Studio - Long delay when selecting image through gallery - android

New to Android Studio, just wondering if anyone can help on this delay when I send an image that is taken from the gallery. Once image is selected there is a long delay until it is actually sent, and for a moment the screen goes black as well.
Here is the code - thanks
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.launch_voip_call) {
Utils.startCall(this, contact);
return true;
} else if (item.getItemId() == R.id.launch_camera) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Pick Image from")
.setCancelable(false)
.setPositiveButton("Camera", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//camera intent
Intent cameraIntent = new Intent(ConversationActivity.this, CameraActivity.class);
cameraIntent.putExtra("EXTRA_CONTACT_JID", contact.getJid());
startActivity(cameraIntent);
}
})
.setNegativeButton("Gallery", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
});
AlertDialog alert = builder.create();
alert.show();
}
return false;
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.WEBP, 5, stream);
byte[] byteArray = stream.toByteArray();
// Log.d(TAG, String.valueOf(bitmap));
EventBus.getDefault().post(new MessageEvent.SendMessage(contact.getJid(), byteArray, ""));
} catch (IOException e) {
e.printStackTrace();
}
}
}
#OnTextChanged(R.id.compose)
public void onMessageChanged(CharSequence s) {
sendButton.setVisibility(s.length() > 0 ? View.VISIBLE : View.INVISIBLE);
}
#OnClick(R.id.send)
public void onSend(final View view) {
String message = composeText.getText().toString().trim();
if (!message.isEmpty()) {
if (!amIOffline()) {
EventBus.getDefault().post(new MessageEvent.SendMessage(contact.getJid(), message));
composeText.setText("");
} else {
SimpleSnackbar.offlineGroupChat(view).show();
}
}
}

On Activity result is on Main Thread.. Compressing Image can take time.. Try to use AsyncTask to achieve compression in background and then send image in background as well.. Dont perform Compression on MainThread thats why you are getting long delay..
Let me know if you need code??
public class ImageSendingAsync extends AsyncTask<Bitmap,Void,Void> {
#Override
protected Void doInBackground(Bitmap... params) {
try {
Bitmap bitmap = params[0];
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.WEBP, 5, stream);
byte[] byteArray = stream.toByteArray();
// Log.d(TAG, String.valueOf(bitmap));
EventBus.getDefault().post(new MessageEvent.SendMessage(contact.getJid(), byteArray, ""));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
//This will go in Activity Result
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
new ImageSendingAsync().execute(bitmap);
}

I think the compress takes a while and thats why ur MainThread are not able to draw the Layout -> Black Screen.
maybe test the time it take to compress the pic.
if the time is to long, use ASyncTask.
[...]
long timeStart = System.currentTimeMillis();
bitmap.compress(Bitmap.CompressFormat.WEBP, 5, stream);
long timeEnd = System.currentTimeMillis();
Log.e("resizePicture Timer", "resize took " + (timeEnd - timeStart) + "ms");
[...]

Related

Attempting to implement a feature where a user can use their phone camera to take a picture and then it will be uploaded as their profile pic

I'm currently running into an issue with implementing a feature on my app where a user can take a picture using their phone's camera and then have it display as a bitmap image as well as be uploaded to Firebase.
I've seen several similar questions answered on here but nothing seems to be working for me, so I was hoping if someone could give my code a look and have insight for what I might be doing incorrectly.
My general process as of right now is that my "Choose from Gallery" option is working, but my "Take Photo" is not. When clicked in selectProfilePicOption(), I am able to take a picture and confirm it, but the data sent to onActivityResult() continues to get null. I want to be able to pass the taken photo and upload it as a Bitmap to my uploadImageToFirebase() function.
Thanks to all in advance for any assistance!
Here's my current code:
private void selectProfilePicOption(Context context){
final CharSequence[] options = {"Take Photo", "Choose from Gallery", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Choose your profile picture");
builder.setItems(options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
if(options[which].equals("Take Photo")){
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, TAKE_IMAGE_REQUEST);
}else if(options[which].equals("Choose from Gallery")){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select image..."), PICK_IMAGE_REQUEST);
}else if(options[which].equals("Cancel")){
dialog.dismiss();
}
}
});
builder.show();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_CANCELED) {
switch (requestCode) {
case TAKE_IMAGE_REQUEST:
if(resultCode == RESULT_OK){
data.getExtras().get("data");
File file = new File(Environment.getExternalStorageDirectory().getPath());
Uri uri = Uri.fromFile(file);
try{
System.out.println("attempting to store bitmap");
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
uploadImageToFirebase(bitmap);
} catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
}
break;
case PICK_IMAGE_REQUEST:
if (resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
uploadImageToFirebase(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
break;
}
}
}
private void uploadImageToFirebase(final Bitmap bitmap){
if(filePath != null){
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Uploading...");
progressDialog.show();
StorageReference ref = mStorageRef.child("images/ProfilePics/" + mUser.getUid());
ref.putFile(filePath).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
profilePicture.setImageBitmap(bitmap);
Toast.makeText(SetProfileData.this, "Image Uploaded", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText(SetProfileData.this, "Failed " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
#Override
public void onProgress(#NonNull UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount());
progressDialog.setMessage("Uploaded " + (int)progress + "%");
}
});
}
}
The line data.getExtras().get("data"); contains the thumbnail of your captured image, but for some reasons, you are completely ignoring it.
Do it this way,
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_CANCELED) {
switch (requestCode) {
case TAKE_IMAGE_REQUEST:
if(resultCode == RESULT_OK){
Bitmap bitmap = (Bitmap) intent.getExtras().get("data") //this line is important
uploadImageToFirebase(bitmap);
} catch (FileNotFoundException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
}
break;
case PICK_IMAGE_REQUEST:
if (resultCode == RESULT_OK && data != null && data.getData() != null) {
filePath = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
uploadImageToFirebase(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
break;
}
}
But beware the image thumbnail you received on onActivityResult() and uploaded to FireBase is not the full resolution image but just a compressed version of it. In order to get the full-size image, you can check out this

For a camera activity, result code is -1 in onActivityResult(). How to proceed debugging?

None of the submissions here deal with negative result code. I know it means that the task failed, but I have no idea how or why it failed. The app opens the camera and I'm able to take a picture.
btnN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
captureImage(v);
}
});
The function definitions are as given below.
public void captureImage(View view) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
File imageFile = null;
try {
imageFile = getImageFile();
} catch (IOException e) {
e.printStackTrace();
}
if (imageFile != null) {
Uri imageUri = FileProvider.getUriForFile(this, "com.example.testingproject.fileprovider", imageFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, 1);
}
System.out.println("imageFile length:" + imageFile.length());
}
}
In the above function, I've even tried sending request code as 2. Same functionality, I'm able to click a picture, but same issue.
public File getImageFile() throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmsss").format(new Date());
String imageName = "jpg_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File imageFile = File.createTempFile(imageName, ".jpg", storageDir);
currentImagePath = imageFile.getAbsolutePath();
System.out.println("currImPath: " + currentImagePath);
return imageFile;
}
The much needed onActivityResult() code is below
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
try {
System.out.println("reqCode: "+requestCode+" resCode: "+resultCode);
switch (requestCode) {
case 0: {
if (resultCode == RESULT_OK) {
File file = new File(currentImagePath);
Bitmap bitmap = MediaStore.Images.Media.getBitmap(MainActivity.this.getContentResolver(), Uri.fromFile(file));
if (bitmap != null) {
//...Do your stuffs
Toast.makeText(MainActivity.this, "Bitmap NOT null", Toast.LENGTH_SHORT).show();
imgView.setImageBitmap(bitmap);
}
else
{
Toast.makeText(MainActivity.this,"BitmapNull",Toast.LENGTH_SHORT).show();
}
}
break;
}
default: Toast.makeText(MainActivity.this,"result code not okay",Toast.LENGTH_SHORT).show(); break;
}
} catch (Exception error) {
error.printStackTrace();
}
}
The sysout in log is below
2020-05-01 13:52:24.644 10014-10014/com.example.testingproject I/System.out: reqCode: 1 resCode: -1
-1 is equal to RESULT_OK. It means the task completed successfully
When you look into the code. -1 is actully status code for RESULT_OK
public static final int RESULT_OK = -1;
Now you've set requestCode as 1 in this line
startActivityForResult(cameraIntent, 1);
So in your OnActivityResult which shows
reqCode: 1 resCode: -1
is Correct.

Androind ImageView in Fragment

I am trying to put an image on my fragment, but the image is not showing up. I am certain that it was working just yesterday but now it is not. Any help is appreciated.
This code is in my Fragment:
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mUser = (User) getArguments().getSerializable(ARGS_USER);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_picture_picker, container, false);
mImageView = v.findViewById(R.id.imageView);
mSelectImageButton = v.findViewById(R.id.select_image);
mSelectImageButton.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, IMG_REQUEST);
}
});
return v;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == IMG_REQUEST && resultCode == Activity.RESULT_OK && data != null){
Uri path = data.getData();
try {
bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), path);
mImageView.setImageBitmap(bitmap);
mImageView.setVisibility(View.VISIBLE);
mUser.setProfilePicture(bitmap);
}catch(IOException e){
e.printStackTrace();
}
}
}
Actually you are not using the Volley. Please change the heading of your question. You are accessing the Gallery and showing the image inside the imageView. Use the below code for accessing the image from camera as well as gallery.
if (action.equals("CAMERA")) {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
// Check Permissions Now
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CAMERA}, ACTION_REQUEST_CAMERA);
} else {
openCamera();
}
} else if (action.equals("GALLERY")) {
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Check Permissions Now
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, ACTION_REQUEST_GALLERY);
} else {
openGallery();
}
}
private void openCamera(){
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
getActivity().startActivityForResult(cameraIntent, ACTION_REQUEST_CAMERA);
}
private void openGallery(){
Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
Intent chooser = Intent.createChooser(galleryIntent, "Choose a Picture");
getActivity().startActivityForResult(chooser, ACTION_REQUEST_GALLERY);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println("OnActivityResult");
System.out.println("resultCode: "+resultCode+"\n"+"requestCode: "+requestCode);
ImageOperations operations = new ImageOperations();
if (resultCode == RESULT_OK) {
if (requestCode == ACTION_REQUEST_GALLERY) {
System.out.println("select file from gallery ");
Uri selectedImageUri = data.getData();
renderProfileImage(selectedImageUri,operations);
} else if (requestCode == ACTION_REQUEST_CAMERA) {
System.out.println("select file from camera ");
Bitmap photo = (Bitmap) data.getExtras().get("data");
String name = "profile_pic.png";
operations.saveImageToInternalStorage(photo,getActivity(),name);
profile_image.setImageBitmap(photo);
}
}
}
private void renderProfileImage(Uri selectedImageUri,ImageOperations operations) {
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), selectedImageUri);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, bytes);
String name = "profile_pic.png";
operations.saveImageToInternalStorage(bitmap,getActivity(),name);
profile_image.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
private class ImageOperations {
public boolean saveImageToInternalStorage(Bitmap image, Context context, String name) {
try {
// Use the compress method on the Bitmap object to write image to
// the OutputStream
FileOutputStream fos = context.openFileOutput("profile_pic.png", Context.MODE_PRIVATE);
// Writing the bitmap to the output stream
image.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
return true;
} catch (Exception e) {
Log.e("saveToInternalStorage()", e.getMessage());
return false;
}
}
public Bitmap getThumbnail(Context context,String filename) {
String fullPath = Environment.getDataDirectory().getAbsolutePath();
Bitmap thumbnail = null;
// Look for the file on the external storage
try {
if (isSdReadable() == true) {
thumbnail = BitmapFactory.decodeFile(fullPath + "/" + filename);
}
} catch (Exception e) {
Log.e("Image",e.getMessage());
}
// If no file on external storage, look in internal storage
if (thumbnail == null) {
try {
File filePath = context.getFileStreamPath(filename);
FileInputStream fi = new FileInputStream(filePath);
thumbnail = BitmapFactory.decodeStream(fi);
} catch (Exception ex) {
Log.e("getThumbnail()", ex.getMessage());
}
}
return thumbnail;
}
public boolean isSdReadable() {
boolean mExternalStorageAvailable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = true;
Log.i("isSdReadable", "External storage card is readable.");
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
Log.i("isSdReadable", "External storage card is readable.");
mExternalStorageAvailable = true;
} else {
// Something else is wrong. It may be one of many other
// states, but all we need to know is we can neither read nor write
mExternalStorageAvailable = false;
}
return mExternalStorageAvailable;
}
}
action is like what you want to do. ACTION_REQUEST_GALLERY and ACTION_REQUEST_CAMERA use some integer constants like 100 and 101. profileImage is your ImageView.

Fetching Captured Image sent through Intent

I'm working on a simple project, where I'm suppose to create an application for taking notes. I've sucessfully created the app but now I want to make it possible for the user to take a photo and save it with the note.
I can take the picture, preview it, and then click save.
But the problem is that I'm not able to get the image sent through the intent to my MainActivity class, where the note is suppose to be saved.
So my question is how do I save the note with the picture, please look at the picture that represents how I want my customRow to look like
I have no idea why this happends beacuse I get no errors... And its been driving me nuts.
Any ideas??
Image.class
public void capturePhoto(View view){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri();
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode){
case CAPTURE_IMAGE:
previewCapturedImage();
break;
}
}
else if (resultCode == RESULT_CANCELED) {
// user cancelled Image capture
Toast.makeText(getApplicationContext(),
"User cancelled image capture", Toast.LENGTH_SHORT)
.show();
} else {
// failed to capture image
Toast.makeText(getApplicationContext(),
"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
.show();
}
}
private void previewCapturedImage() {
try {
// bitmap factory
BitmapFactory.Options options = new BitmapFactory.Options();
// downsizing image as it throws OutOfMemory Exception for larger
// images
options.inSampleSize = 2;
bitmap = BitmapFactory.decodeFile(fileUri.getPath(),
options);
//Set image here
imageView.setImageBitmap(bitmap);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
public void sendImageAsIntent(Boolean isSending){
if(isSending = false){
isSending = true;
}
if(isSending = true) {
Intent i = new Intent(CheckOutMemo.this, MainActivity.class);
i.putExtra("filePath", fileUri.getPath());
setResult(RESULT_OK,i);
finish();
}
}
MainActivity.class
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_OK) {
return;
}
if (requestCode == Image.ADD_REQUEST_CODE) {
String header = data.getStringExtra("header");
String bodyText = data.getStringExtra("bodyText");
filePath = data.getStringExtra("filePath");
sourceFile = new File(filePath);
fileName = data.getStringExtra("filePath");
Uri imageUri = data.getData();
if(filePath!=null) {
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),imageUri);
imageIcon.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
Toast.makeText(MainActivity.this, "FileNoutFoundException MainActivity", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(MainActivity.this, "IOException MainActivity", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
Memo memo = new Memo(header, bodyText,imageIcon);
customAdapter.add(memo);
customAdapter.notifyDataSetChanged();
} else if (requestCode == Image.EDIT_REQUEST_CODE) {
int position = data.getIntExtra("position", 0);
Memo memo = customAdapter.getItem(position);
memo.header = data.getStringExtra("header");
memo.bodyText = data.getStringExtra("bodyText");
customAdapter.notifyDataSetChanged();
}
}
When you do:
Intent i = new Intent(CheckOutMemo.this, MainActivity.class);
i.putExtra("filePath", fileUri.getPath());
startActivity(i);
You are basically asking to create a new instance of MainActivity. To return to the previous activity while setting the result do this instead:
setResult(RESULT_OK, i);
finish();//finishing activity

how can I upload a photo from the gallery to parse.com?

I am trying to upload a photo from the gallery into my parse cloud but I can't figure it out here's my code and what I've done so far .
I've looked everywhere still can't find a solution , can't upload the photo :\
help me please.
public void loadImagefromGallery(View view) {
// Create intent to Open Image applications like Gallery, Google Photos
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Start the Intent
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
// When an Image is picked
if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK
&& null != data) {
// Get the Image from data
Uri selectedImage = data.getData();
myBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] scaledData = bos.toByteArray();
photoFile = new ParseFile("my_photo.jpg", scaledData);
photoFile.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e != null) {
Toast.makeText(getApplicationContext(),
"Error saving: " + e.getMessage(),
Toast.LENGTH_LONG).show();
} else {
// do something
}
}
});
Save ParseObject in the background
// Create the ParseFile
ParseFile file = new ParseFile("androidbegin.png", image);
// Upload the image into Parse Cloud
file.saveInBackground();
// ParseObject
ParseObject pObject = new ParseObject("ExampleObject");
// Create a column named "ImageName" and set the string
pObject.put("ImageName", "image name here");
// Create a column named "ImageFile" and insert the image
pObject.put("ImageFile", file);
pObject.saveInBackground(); // asynchronous, no callback
Save in the background with callback
pObject.saveInBackground(new SaveCallback () {
#Override
public void done(ParseException ex) {
if (ex == null) {
isSaved = true;
} else {
// Failed
isSaved = false;
}
}
});

Categories

Resources