Commit f8c10c4f by Yu-Tung

push

parent 81163bf8
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -3,6 +3,7 @@ package com.example.audiovisualrecord.ui.main;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.content.FileProvider;
import androidx.core.os.EnvironmentCompat;
import android.content.DialogInterface;
import android.content.Intent;
......@@ -176,6 +177,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
MediaStore.ACTION_IMAGE_CAPTURE);
settingSystemCamera(pictureIntent);
if (pictureIntent.resolveActivity(getPackageManager()) != null) {
//Create a file to store the image
photoFile = null;
try {
......@@ -186,14 +188,21 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
}
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this, "com.example.audiovisualrecord.provider", photoFile);
pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
photoURI);
startActivityForResult(pictureIntent,
REQUEST_CAPTURE_IMAGE);
// Uri photoURI = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", photoFile);
// pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
// photoURI);
// startActivityForResult(pictureIntent,
// REQUEST_CAPTURE_IMAGE);
pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
pictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(pictureIntent, REQUEST_CAPTURE_IMAGE);
}
}
}
private void openRecordVideoIntent() {
String timeStamp =
new SimpleDateFormat("yyyyMMdd_HHmmss",
......@@ -212,24 +221,30 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
private File createImageFile() throws IOException {
Date c = Calendar.getInstance(Locale.TAIWAN).getTime();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HH:mm:ss");
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HH:mm");
String formattedDate = df.format(c);
// String timeStamp =
// new SimpleDateFormat("yyyyMMdd_HHmmss",
// Locale.getDefault()).format(new Date());
String imageFileName =formattedDate;
Log.e("time",imageFileName);
File storageDir =
getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// String imageFileName =formattedDate;
String imageName =new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
Log.e("time",imageName);
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
Log.e("storageDir",getExternalFilesDir(Environment.DIRECTORY_PICTURES).toString());
// File image = File.createTempFile(
// imageFileName, /* prefix */
// ".jpg", /* suffix */
// storageDir /* directory */
// );
// imageFilePath = image.getAbsolutePath();
// return image;
if (!storageDir.exists()) {
storageDir.mkdir();
}
File tempFile = new File(storageDir, imageName);
if (!Environment.MEDIA_MOUNTED.equals(EnvironmentCompat.getStorageState(tempFile))) {
return null;
}
imageFilePath = image.getAbsolutePath();
return image;
imageFilePath = tempFile .getAbsolutePath();
return tempFile;
}
......@@ -243,14 +258,15 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Date c = Calendar.getInstance(Locale.TAIWAN).getTime();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HH:mm:ss");
String formattedDate = df.format(c);
if (requestCode == REQUEST_CAPTURE_IMAGE && resultCode == RESULT_OK) {
File imgFile = new File(imageFilePath);
Log.e("imagePath", imageFilePath);
File newFile = new File(imageFilePath, formattedDate + ".jpg");
imgFile.renameTo(newFile);
//照片的檔案
if (imgFile.exists()) {
......@@ -261,14 +277,11 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
out.flush();
out.close();
MediaStore.Images.Media.insertImage(getContentResolver(), myBitmap, formattedDate, formattedDate);
Log.e("fileName", imgFile.getName());
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath()))));
Log.e("picture", Environment.getExternalStorageDirectory().getPath());
// Intent it = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
// Uri uri = Uri.fromFile(imgFile);
// it.setData(uri);
// this.sendBroadcast(it);
MediaStore.Images.Media.insertImage(getContentResolver(), myBitmap, "", "");
// Log.e("fileName", imgFile.getName());
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(imageFilePath))));
// Log.e("picture", Environment.getExternalStorageDirectory().getPath());
} catch (Exception e) {
e.printStackTrace();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment