Showing
1 changed file
with
28 additions
and
0 deletions
| @@ -8,6 +8,7 @@ import android.os.Bundle | @@ -8,6 +8,7 @@ import android.os.Bundle | ||
| 8 | import android.util.Log | 8 | import android.util.Log |
| 9 | import io.flutter.plugin.common.MethodChannel | 9 | import io.flutter.plugin.common.MethodChannel |
| 10 | import io.flutter.plugin.common.MethodCall | 10 | import io.flutter.plugin.common.MethodCall |
| 11 | +import android.content.Intent | ||
| 11 | 12 | ||
| 12 | class MainActivity: FlutterActivity() { | 13 | class MainActivity: FlutterActivity() { |
| 13 | 14 | ||
| @@ -30,6 +31,7 @@ class MainActivity: FlutterActivity() { | @@ -30,6 +31,7 @@ class MainActivity: FlutterActivity() { | ||
| 30 | 31 | ||
| 31 | // 这里要获取启动时的intent | 32 | // 这里要获取启动时的intent |
| 32 | val uri = intent.data | 33 | val uri = intent.data |
| 34 | + | ||
| 33 | val paramsMap = mutableMapOf<String, String>() | 35 | val paramsMap = mutableMapOf<String, String>() |
| 34 | if (uri != null) { | 36 | if (uri != null) { |
| 35 | val set = uri.queryParameterNames | 37 | val set = uri.queryParameterNames |
| @@ -48,10 +50,36 @@ class MainActivity: FlutterActivity() { | @@ -48,10 +50,36 @@ class MainActivity: FlutterActivity() { | ||
| 48 | } | 50 | } |
| 49 | } | 51 | } |
| 50 | } | 52 | } |
| 53 | + override fun onNewIntent(intent: Intent) { | ||
| 54 | + super.onNewIntent(intent) | ||
| 55 | + // flutter版本更新后使用 getFlutterEngine().getDartExecutor().getBinaryMessenger()代替 getFlutterView() | ||
| 56 | + val channel = MethodChannel(getFlutterEngine()?.getDartExecutor()?.getBinaryMessenger(), CHANNEL) | ||
| 57 | + | ||
| 58 | + // 这里要获取启动时的intent | ||
| 59 | + val uri = intent.data | ||
| 60 | + val paramsMap = mutableMapOf<String, String>() | ||
| 61 | + if (uri != null) { | ||
| 62 | + val set = uri.queryParameterNames | ||
| 63 | + for (name in set) { | ||
| 64 | + val value = uri.getQueryParameter(name) | ||
| 65 | + paramsMap[name.toString()] = value.toString() | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + intentMap = paramsMap | ||
| 70 | + | ||
| 71 | + channel.setMethodCallHandler { call, result -> | ||
| 72 | + Log.i(TAG,intentMap.toString()); | ||
| 73 | + when (call.method) { | ||
| 74 | + "getIntent" -> get_intent(call, result) | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | +} | ||
| 51 | 78 | ||
| 52 | // 获取intent | 79 | // 获取intent |
| 53 | private fun get_intent(call: MethodCall, result: MethodChannel.Result) { | 80 | private fun get_intent(call: MethodCall, result: MethodChannel.Result) { |
| 54 | Log.i(TAG, "调用${call.method}方法") | 81 | Log.i(TAG, "调用${call.method}方法") |
| 55 | result.success(intentMap) | 82 | result.success(intentMap) |
| 83 | + intentMap.clear(); | ||
| 56 | } | 84 | } |
| 57 | } | 85 | } |
-
Please register or login to post a comment