SoFunction
Updated on 2025-04-05

Detailed explanation of the camera and library examples of the Android calling system


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//Call this method after completing the photography
(requestCode, resultCode, data);
case 1:
switch (resultCode) {
case Activity.RESULT_OK://Click OK to complete the photo
String sdStatus = ();
if (!(Environment.MEDIA_MOUNTED)) { // Check whether sd is available
("TestFile", "SD card is not avaiable/writeable right now.");
return; }
Bundle bundle = ();
Bitmap bitmap = (Bitmap) ("data");// Get the data returned by the camera and convert it to Bitmap image format
FileOutputStream b = null;
File file = new File("/sdcard/pk4fun/");
();// Create a folder with the name pk4fun // Name the photo. In the target folder, use the current time number string as the name to ensure that each photo has different names. If the names of other demos circulating on the Internet are written in dead, no matter how many photos are taken, the next one will always cover the previous one. Careful students can also set this string, such as adding the word "IMG"; then you will find that under the myimage folder in the SD card, the photos taken just after calling the camera will be saved, and the photo names will not be repeated.
String str = null;
Date date = null;
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");// Get the current time and further convert it into a string
date = new Date(resultCode);
str = (date);
String fileName = "/sdcard/myImage/" + str + ".jpg";
sendBroadcast(fileName);
try {
b = new FileOutputStream(fileName);
(, 100, b);// Write data to a file
} catch (FileNotFoundException e) {
();
} finally {
try {
();
();
} catch (IOException e) {
();
}
} break;
case Activity.RESULT_CANCELED:// Cancel
break;
}
break;
case 2:
switch (resultCode) {
case Activity.RESULT_OK: {
Uri uri = ();
Cursor cursor = ().query(uri, null,
null, null, null);
();
String imgNo = (0); // Image number
String imgPath = (1); // Image file path
String imgSize = (2); // Image size
String imgName = (3); // Image file name
();
// Options options = new ();
// = false;
// = 10;
// Bitmap bitmap = (imgPath, options);
}
break;
case Activity.RESULT_CANCELED:// Cancel
break;
}
break;
}