mirror of
https://github.com/awfixers-stuff/OwnDroid.git
synced 2026-03-23 19:15:58 +00:00
REFACTOR PROJECT
This commit is contained in:
26
app/src/main/java/com/binbin/androidowner/Utils.kt
Normal file
26
app/src/main/java/com/binbin/androidowner/Utils.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.binbin.androidowner
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.widget.Toast
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
|
||||
fun uriToStream(
|
||||
context: Context,
|
||||
uri: Uri?,
|
||||
operation:(stream: InputStream)->Unit
|
||||
){
|
||||
if(uri!=null){
|
||||
try{
|
||||
val stream = context.contentResolver.openInputStream(uri)
|
||||
if(stream!=null) { operation(stream) }
|
||||
else{ Toast.makeText(context, "空的流", Toast.LENGTH_SHORT).show() }
|
||||
stream?.close()
|
||||
}
|
||||
catch(e: FileNotFoundException){ Toast.makeText(context, "文件不存在", Toast.LENGTH_SHORT).show() }
|
||||
catch(e: IOException){ Toast.makeText(context, "IO异常", Toast.LENGTH_SHORT).show() }
|
||||
}else{ Toast.makeText(context, "空URI", Toast.LENGTH_SHORT).show() }
|
||||
}
|
||||
Reference in New Issue
Block a user