Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
HBHAndroid
Project
Project
Details
Activity
Releases
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
杨秀秀
HBHAndroid
Commits
576682ed
Commit
576682ed
authored
Oct 25, 2023
by
小费同学阿
💬
Committed by
杨秀秀
Nov 21, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
68174 【企业app-android】招聘详情中的投简历点击无反应
parent
b2a29cab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
36 deletions
+44
-36
JobDetailViewModel.java
...com/xx/merchanthbh/ui/recruitment/JobDetailViewModel.java
+44
-36
No files found.
app/src/main/java/com/xx/merchanthbh/ui/recruitment/JobDetailViewModel.java
View file @
576682ed
...
...
@@ -5,10 +5,12 @@ import static android.app.Activity.RESULT_OK;
import
android.app.Activity
;
import
android.app.Application
;
import
android.content.ContentResolver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.provider.MediaStore
;
import
android.provider.OpenableColumns
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.Toast
;
...
...
@@ -22,6 +24,8 @@ import com.xx.merchanthbh.data.http.respons.JobDetailBean;
import
com.xx.xxviewlibrary.witget.model.FileBean
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -95,16 +99,11 @@ public class JobDetailViewModel extends BaseViewModel<RecruitmentRequest> {
String
filePath
;
/*1-获取数据*/
Uri
uri
=
data
.
getData
();
/*2.获取路径*/
String
tFileName
=
uri
.
getPath
();
Log
.
v
(
"这是不厚的路径"
,
tFileName
);
/*3-对路径进行前缀判断(针对于最近文件报错问题)*/
if
(
tFileName
.
startsWith
(
"/document/"
))
{
filePath
=
"1"
;
Toast
.
makeText
(
activity
,
"请上传正确的PDF文件"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
/*格式化文件路径*/
filePath
=
getPathFromUri
(
uri
);
/*格式化文件路径*/
filePath
=
getFilePathForN
(
uri
,
activity
);
if
(!
filePath
.
toLowerCase
().
endsWith
(
".pdf"
))
{
Toast
.
makeText
(
activity
,
"请选择正确的PDF文件"
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
File
file
=
new
File
(
filePath
);
Log
.
v
(
"这是我选中获取的文件路径"
,
filePath
);
...
...
@@ -160,34 +159,43 @@ public class JobDetailViewModel extends BaseViewModel<RecruitmentRequest> {
}
/*对文件进行格式化路径*/
private
String
getPathFromUri
(
Uri
uri
)
{
String
filePath
=
null
;
if
(
uri
!=
null
)
{
String
scheme
=
uri
.
getScheme
();
if
(
ContentResolver
.
SCHEME_CONTENT
.
equals
(
scheme
))
{
try
(
Cursor
cursor
=
activity
.
getContentResolver
().
query
(
uri
,
null
,
null
,
null
,
null
))
{
if
(
cursor
!=
null
&&
cursor
.
moveToFirst
())
{
int
columnIndex
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
);
filePath
=
cursor
.
getString
(
columnIndex
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
else
if
(
ContentResolver
.
SCHEME_FILE
.
equals
(
scheme
))
{
filePath
=
uri
.
getPath
();
}
}
if
(
filePath
!=
null
)
{
Log
.
v
(
"这是我选中获取的文件路径11111"
,
filePath
);
if
(!
filePath
.
endsWith
(
".pdf"
))
{
Toast
.
makeText
(
activity
,
"请上传正确的PDF文件"
,
Toast
.
LENGTH_SHORT
).
show
();
/*不是pdf文件的情况*/
filePath
=
"1"
;
private
static
String
getFilePathForN
(
Uri
uri
,
Context
context
)
{
Uri
returnUri
=
uri
;
Cursor
returnCursor
=
context
.
getContentResolver
().
query
(
returnUri
,
null
,
null
,
null
,
null
);
/*
* Get the column indexes of the data in the Cursor,
* * move to the first row in the Cursor, get the data,
* * and display it.
* */
int
nameIndex
=
returnCursor
.
getColumnIndex
(
OpenableColumns
.
DISPLAY_NAME
);
int
sizeIndex
=
returnCursor
.
getColumnIndex
(
OpenableColumns
.
SIZE
);
returnCursor
.
moveToFirst
();
String
name
=
(
returnCursor
.
getString
(
nameIndex
));
String
size
=
(
Long
.
toString
(
returnCursor
.
getLong
(
sizeIndex
)));
File
file
=
new
File
(
context
.
getFilesDir
(),
name
);
try
{
InputStream
inputStream
=
context
.
getContentResolver
().
openInputStream
(
uri
);
FileOutputStream
outputStream
=
new
FileOutputStream
(
file
);
int
read
=
0
;
int
maxBufferSize
=
1
*
1024
*
1024
;
int
bytesAvailable
=
inputStream
.
available
();
//int bufferSize = 1024;
int
bufferSize
=
Math
.
min
(
bytesAvailable
,
maxBufferSize
);
final
byte
[]
buffers
=
new
byte
[
bufferSize
];
while
((
read
=
inputStream
.
read
(
buffers
))
!=
-
1
)
{
outputStream
.
write
(
buffers
,
0
,
read
);
}
}
else
{
Log
.
v
(
"这是我选中获取的文件路径"
,
"文件路径为空"
);
Log
.
e
(
"File Size"
,
"Size "
+
file
.
length
());
inputStream
.
close
();
outputStream
.
close
();
Log
.
e
(
"File Path"
,
"Path "
+
file
.
getPath
());
Log
.
e
(
"File Size"
,
"Size "
+
file
.
length
());
}
catch
(
Exception
e
)
{
Log
.
e
(
"Exception"
,
e
.
getMessage
());
}
return
file
Path
;
return
file
.
getPath
()
;
}
...
...
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