登录华为账号成功后,调用华为SDK浮标显示接口: HMSAgemt.Game.showFloatWindow(activity);
没有显示,看了下日志,报了如下错误
AndroidJavaException: android.content.res.Resources$NotFoundException: Resource ID #0x0
android.content.res.Resources$NotFoundException: Resource ID #0x0
android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:292)
android.content.res.Resources.loadXmlResourceParser(Resources.java:2390)
android.content.res.Resources.getLayout(Resources.java:1341)
android.view.LayoutInflater.inflate(LayoutInflater.java:421)
android.view.LayoutInflater.inflate(LayoutInflater.java:374)
com.huawei.appmarket.component.buoycircle.impl.view.FloatWindowSmallView.<init>(FloatWindowSmallView.java:229)
com.huawei.appmarket.component.buoycircle.impl.manager.FloatWindowManager.showSmallWindow(FloatWindowManager.java:373)
com.huawei.appmarket.component.buoycircle.impl.manager.FloatWindowManager.startShowSmallWindow(FloatWindowManager.java:573)
com.huawei.appmarket.component.buoycircle.impl.manager.FloatWindowManager.createSmallWindow(FloatWindowManager.java:303)
com.huawei.appmarket.component.buoycircle.impl.manager.FloatWindowManager.createSmallWindow(FloatWindowManager.java:223)
com.huawei.appmarket.component.buoycircle.impl.manager.BuoyCircleManager.createBuoyCircle(BuoyCircleManager.java:39)
com.huawei.hms.support.api.game.a.a.c(BuoyCircleHelper.java:83)
com.huawei.hms.support.api.game.a.a.b(BuoyCircleHelper.java:98)
com.huawei.hms.support.api.game.a.showFloatWindow(HuaweiGameApiImpl.java:609)
com.huawei.android.hms.agent.game.FloatWindowApi.showFinal(FloatWindowApi.java:123)
com.huawei.android.hms.agent.game.FloatWindowApi.showFloatWindow(FloatWindowApi.java:83)
com.huawei.android.hms.agent.HMSAgent$Game.showFloatWindow(HMSAgent.java:321)
com.lkgame.stsdk.HuaweiSdkApiHelper.showfloat(SourceFile:276)
com.unity3d.player.UnityPlayer.nativeRender(Native Method)
com.unity3d.player.UnityPlayer.a(Unknown Source:0)
com.unity3d.player.UnityPlayer$c$1.handleMessage(Unknown Source:114)
android.os.Handler.dispatchMessage(Handler.java:108)
android.os.Looper.loop(Looper.java:216)
com.unity3d.player.UnityPlayer$c.run(Unknown Source:20)
UnityEngine.AndroidJNISafe.CheckException ()
UnityEngine.AndroidJNISafe.CallStaticVoidMethod (IntPtr clazz, IntPtr methodID, UnityEngine.jvalue[] args)
UnityEngine.AndroidJavaObject._CallStatic (System.String methodName, System.Object[] args)
UnityEngine.AndroidJavaObject.CallStatic (System.String methodName, System.Object[] args)
StSdk.HuaweiSdkAndroid.Showfloat ()
解决办法
把HMSSdkGame/res/layout/c_buoycircle_window_small.xml
拷贝到Unity工程中的Assets/Plugins/Android/res/layout
目录中
补充
浮标需要的资源
1 layout
2 drawable
3 value-zh-rCN
4 Activity配置
在AndroidManifest.xml中配置BuoyBridgeActivity
<!-- 接入HMSSDK 游戏需要注册的activity | Activity to register when accessing HMSSDK game module using hmsagent code-->
<activity
android:name="com.huawei.appmarket.component.buoycircle.impl.delegete.BuoyBridgeActivity"
android:configChanges="orientation|locale|screenSize|layoutDirection|fontScale"
android:excludeFromRecents="true"
android:exported="false"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Translucent">
<meta-data
android:name="hwc-theme"
android:value="androidhwext:style/Theme.Emui.Translucent" />
</activity>
如下
5 调用点
显示浮标
建议在游戏界面的onResume
方法中调用显示浮标接口。
protected void onResume()
{
super.onResume();
HMSAgent.Game.showFloatWindow(this);
}
隐藏浮标
当用户操作触发游戏页面的onPause
方法,例如切换游戏界面、切换应用等,应用需要在onPause
中调用隐藏游戏浮标接口。
protected void onPause()
{
super.onPause();
HMSAgent.Game.hideFloatWindow(this);
}