fmk
4 years ago
38 changed files with 274 additions and 110 deletions
@ -0,0 +1,15 @@
|
||||
package com.zsw.huixiang |
||||
|
||||
import android.app.Application |
||||
|
||||
class HxApplication : Application() { |
||||
|
||||
|
||||
override fun onCreate() { |
||||
super.onCreate() |
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,91 @@
|
||||
package com.zsw.huixiang.wxapi |
||||
|
||||
import android.app.Activity |
||||
import android.content.Intent |
||||
import android.content.pm.PackageManager |
||||
import android.os.Bundle |
||||
import com.jarvan.fluwx.handlers.FluwxResponseHandler |
||||
import com.jarvan.fluwx.handlers.FluwxRequestHandler |
||||
import com.jarvan.fluwx.handlers.WXAPiHandler |
||||
import com.tencent.mm.opensdk.modelbase.BaseReq |
||||
import com.tencent.mm.opensdk.modelbase.BaseResp |
||||
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler |
||||
import io.flutter.Log |
||||
|
||||
class WXEntryActivity : Activity(), IWXAPIEventHandler { |
||||
|
||||
|
||||
// IWXAPI 是第三方app和微信通信的openapi接口 |
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
Log.e("wx:", "onCreate:") |
||||
|
||||
try { |
||||
if (!WXAPiHandler.wxApiRegistered) { |
||||
var appInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA) |
||||
val wechatAppId = appInfo.metaData.getString("weChatAppId") |
||||
if (wechatAppId != null ){ |
||||
WXAPiHandler.setupWxApi(wechatAppId,this) |
||||
WXAPiHandler.setCoolBool(true) |
||||
Log.d("fluwx","weChatAppId:" + wechatAppId) |
||||
}else { |
||||
Log.e("fluwx","can't load meta-data weChatAppId") |
||||
} |
||||
} |
||||
WXAPiHandler.wxApi?.handleIntent(intent, this) |
||||
} catch (e: Exception) { |
||||
e.printStackTrace() |
||||
startSpecifiedActivity(defaultFlutterActivityAction()) |
||||
finish() |
||||
} |
||||
} |
||||
|
||||
override fun onNewIntent(intent: Intent) { |
||||
super.onNewIntent(intent) |
||||
Log.e("wx:", "onNewIntent:") |
||||
|
||||
setIntent(intent) |
||||
|
||||
try { |
||||
WXAPiHandler.wxApi?.handleIntent(intent, this) |
||||
} catch (e: Exception) { |
||||
e.printStackTrace() |
||||
startSpecifiedActivity(defaultFlutterActivityAction()) |
||||
finish() |
||||
} |
||||
} |
||||
|
||||
|
||||
override fun onReq(baseReq: BaseReq) { |
||||
Log.e("wx:", "onReq: ${baseReq.toString()}") |
||||
// FIXME: 可能是官方的Bug,从微信拉起APP的Intent类型不对,无法跳转回Flutter Activity |
||||
// 稳定复现场景:微信版本为7.0.5,小程序SDK为2.7.7 |
||||
FluwxRequestHandler.onReq(baseReq,this) |
||||
} |
||||
|
||||
// 第三方应用发送到微信的请求处理后的响应结果,会回调到该方法 |
||||
override fun onResp(resp: BaseResp) { |
||||
Log.e("wx:", "onResp: ${resp.toString()}") |
||||
FluwxResponseHandler.handleResponse(resp) |
||||
finish() |
||||
} |
||||
|
||||
private fun startSpecifiedActivity(action: String, bundle: Bundle? = null, bundleKey: String? = null) { |
||||
Intent(action).run { |
||||
bundleKey?.let { |
||||
putExtra(bundleKey, bundle) |
||||
} |
||||
addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) |
||||
packageManager?.let { |
||||
resolveActivity(packageManager)?.also { |
||||
startActivity(this) |
||||
finish() |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private fun defaultFlutterActivityAction(): String = "$packageName.FlutterActivity" |
||||
|
||||
} |
Loading…
Reference in new issue