Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
AndiovisualRecord
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yu_Tung
AndiovisualRecord
Commits
f8c10c4f
Commit
f8c10c4f
authored
Jun 30, 2020
by
Yu-Tung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
push
parent
81163bf8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
31 deletions
+44
-31
misc.xml
.idea/misc.xml
+1
-1
MainActivity.java
...a/com/example/audiovisualrecord/ui/main/MainActivity.java
+43
-30
file_paths.xml
app/src/main/res/xml/file_paths.xml
+0
-0
No files found.
.idea/misc.xml
View file @
f8c10c4f
<?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"
>
...
...
app/src/main/java/com/example/audiovisualrecord/ui/main/MainActivity.java
View file @
f8c10c4f
...
...
@@ -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
imag
e
;
imageFilePath
=
tempFile
.
getAbsolutePath
();
return
tempFil
e
;
}
...
...
@@ -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
();
}
...
...
app/src/main/res/xml/file_paths.xml
View file @
f8c10c4f
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment