Created
November 12, 2014 03:18
-
-
Save korrio/cec6dff42a926a9e4da8 to your computer and use it in GitHub Desktop.
onActivityResult
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
// TODO Auto-generated method stub | |
super.onActivityResult(requestCode, resultCode, data); | |
if (resultCode == Activity.RESULT_OK) { | |
File f = new File(Environment.getExternalStorageDirectory() | |
.toString()); | |
for (File temp : f.listFiles()) { | |
if (temp.getName().equals("temp.jpg")) { | |
f = temp; | |
break; | |
} | |
} | |
if (requestCode == REQUEST_TAKE_PHOTO) { | |
try { | |
Bitmap bm; | |
BitmapFactory.Options btmapOptions = new BitmapFactory.Options(); | |
tempFile = f; | |
String path = f.getAbsolutePath(); | |
bm = BitmapFactory.decodeFile(path, btmapOptions); | |
int rotate = getCameraPhotoOrientation(path); | |
Intent postPhotoIntent = new Intent(getActivity(), | |
PostPhotoActivity.class); | |
postPhotoIntent.putExtra("photo", path); | |
postPhotoIntent.putExtra("rotate", rotate + ""); | |
// Toast.makeText(context, "rotate:" + rotate + "", | |
// Toast.LENGTH_SHORT).show(); | |
startActivity(postPhotoIntent); | |
f.delete(); | |
OutputStream fOut = null; | |
File file = new File(path); | |
try { | |
fOut = new FileOutputStream(file); | |
bm.compress(Bitmap.CompressFormat.JPEG, 70, fOut); | |
fOut.flush(); | |
fOut.close(); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} else if (requestCode == REQUEST_CHOOSE_PHOTO) { | |
Uri selectedImageUri = data.getData(); | |
String path = getRealPathFromURI(context, selectedImageUri); | |
int rotate = getCameraPhotoOrientation(path); | |
Intent postPhotoIntent = new Intent(getActivity(), | |
PostPhotoActivity.class); | |
postPhotoIntent.putExtra("photo", path); | |
postPhotoIntent.putExtra("rotate", rotate + ""); | |
startActivity(postPhotoIntent); | |
} else if (requestCode == RESULT_PICK_VIDEO) { | |
if (resultCode == Activity.RESULT_OK) { | |
mFileURI = data.getData(); | |
if (mFileURI != null) { | |
Intent intent = new Intent(context, | |
PostVideoActivity.class); | |
intent.setData(mFileURI); | |
startActivity(intent); | |
} | |
} | |
} else if (requestCode == RESULT_VIDEO_CAP) { | |
if (resultCode == Activity.RESULT_OK) { | |
mFileURI = data.getData(); | |
if (mFileURI != null) { | |
Intent intent = new Intent(context, | |
PostVideoActivity.class); | |
intent.setData(mFileURI); | |
startActivity(intent); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment