-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c0aa2c
commit bdd37b2
Showing
6 changed files
with
179 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
64 changes: 58 additions & 6 deletions
64
mobile/android/app/src/main/kotlin/com/example/dmedia/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,29 +1,81 @@ | ||
package com.example.dmedia | ||
|
||
import android.util.Log | ||
import android.content.Intent | ||
import android.content.ClipData | ||
import android.os.Bundle | ||
import androidx.annotation.NonNull | ||
import androidx.core.content.FileProvider | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.plugin.common.MethodChannel | ||
import java.io.File | ||
|
||
class MainActivity: FlutterActivity() { | ||
private val LOGTAG = "DMEDIA"; | ||
private val LOGTAG = "DMEDIA" | ||
private val CHANNEL = "org.altlimit.dmedia/native" | ||
private var intentAction: String? = null | ||
|
||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
|
||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { | ||
call, result -> | ||
if (call.method == "nativeMethod") { | ||
log("Called: " + call.method) | ||
} else { | ||
result.notImplemented() | ||
when (call.method) { | ||
"getIntentAction" -> | ||
result.success(intentAction) | ||
"setResult" -> { | ||
val path: String? = call.argument("path") | ||
val paths: Array<String>? = call.argument("paths") | ||
if (path != null || paths != null) { | ||
try { | ||
val intent = Intent() | ||
val context = getApplicationContext(); | ||
val provider = context.getPackageName() + ".provider" | ||
if (paths != null) { | ||
val clipData = ClipData.newRawUri(null, FileProvider.getUriForFile(context, provider, File(path))) | ||
for (i in 1 until paths.size) | ||
clipData.addItem(ClipData.Item(FileProvider.getUriForFile(context, provider, File(paths[i])))) | ||
intent.setClipData(clipData) | ||
} else | ||
intent.setData(FileProvider.getUriForFile(context, provider, File(path))) | ||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | ||
setResult(RESULT_OK, intent) | ||
} catch (e: Exception) { | ||
result.error("failed", "Error: $e", null) | ||
setResult(RESULT_CANCELED) | ||
} | ||
finish() | ||
} | ||
result.success(null) | ||
} | ||
else -> result.notImplemented() | ||
} | ||
} | ||
} | ||
|
||
override fun onCreate(bundle: Bundle?) { | ||
super.onCreate(bundle) | ||
updateIntentAction(getIntent()) | ||
log("onCreate: IntentAction $intentAction") | ||
} | ||
|
||
override fun onNewIntent(intent: Intent) { | ||
super.onNewIntent(intent) | ||
updateIntentAction(intent) | ||
log("onNewIntent: IntentAction $intentAction") | ||
} | ||
|
||
private fun updateIntentAction(intent: Intent) { | ||
val intent = getIntent() | ||
intentAction = intent.getAction() | ||
if (intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)) | ||
intentAction += "|MULTIPLE" | ||
if (intentAction != null && intent.getType() != null) | ||
intentAction += "|" + intent.getType(); | ||
} | ||
|
||
private fun log(message: String) { | ||
Log.d(LOGTAG, message); | ||
Log.d(LOGTAG, message) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<paths> | ||
<cache-path name="cache_files" path="." /> | ||
</paths> |
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