-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Uri-AbsolutePath converter for Android,
Squashed commit of the following: commit 61a68df15246531a6539d59e30d753724d4eed55 Author: 孙娇 <[email protected]> Date: Fri Mar 29 11:44:50 2024 +0800 Update files_page.dart commit 1de022bc565841c986cceefe4536abc81021796c Author: 孙娇 <[email protected]> Date: Fri Mar 29 11:43:01 2024 +0800 完成 commit 142a65aaca86b9355d5a73cffdb32e4f8c2a4e6f Author: 孙娇 <[email protected]> Date: Fri Mar 29 11:07:00 2024 +0800 Update settings.gradle commit 0c84db64a282ead743fdfc545bda49ad1b70dc97 Author: 孙娇 <[email protected]> Date: Fri Mar 29 10:50:48 2024 +0800 Update MainActivity.kt
- Loading branch information
Showing
32 changed files
with
167 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
android/app/src/main/kotlin/net/sunjiao/renamer/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,55 @@ | ||
package net.sunjiao.renamer | ||
|
||
import android.content.Context | ||
import android.database.Cursor | ||
import android.net.Uri | ||
import android.provider.MediaStore | ||
import android.util.Log | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.plugin.common.MethodChannel | ||
|
||
class MainActivity: FlutterActivity() { | ||
private val CHANNEL = "net.sunjiao.renamer/picker" | ||
|
||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { | ||
call, result -> | ||
if (call.method == "getRealPathFromURI") { | ||
val uriArg = call.argument<String>("uri") | ||
|
||
getRealPathFromURI(this, Uri.parse(uriArg), result) | ||
} else { | ||
result.notImplemented() | ||
} | ||
} | ||
} | ||
|
||
private fun getRealPathFromURI(context: Context, contentUri: Uri, result: MethodChannel.Result) { | ||
var cursor: Cursor? = null | ||
try { | ||
val proj = arrayOf(MediaStore.Images.Media.DATA) | ||
cursor = context.contentResolver.query(contentUri, proj, null, null, null) | ||
val columnIndex: Int? = cursor?.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) | ||
if (columnIndex == null) { | ||
result.error("Cannot get column index", null, null) | ||
return | ||
} | ||
|
||
cursor?.moveToFirst() | ||
val absolute = cursor?.getString(columnIndex) | ||
if (!absolute.isNullOrEmpty()) { | ||
result.success(absolute) | ||
return | ||
} | ||
|
||
result.error("Cannot get absolute path", null, null) | ||
} catch (e: Exception) { | ||
Log.e("net.sunjiao.renamer", "getRealPathFromURI Exception : $e") | ||
result.error(e.message.toString(), e.localizedMessage, null) | ||
} finally { | ||
cursor?.close() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.