Unity3d 的 ACTION_USER_PRESENT 导致启动画面后崩溃

发布于 2024-12-08 21:55:11 字数 3027 浏览 0 评论 0原文

我为统一游戏制作了一个java插件,可以在屏幕解锁时重新打开音乐。在 Android 2.3.3 上它可以正常工作,但我收到抱怨说它在 Android 2.2 下使游戏崩溃。 我没有设备来测试这个,但是有很多抱怨,所以确实出了问题。

有人遇到过同样的问题吗?

Java插件仅包含一个BroadcastReceiver,它向unity发送一条消息:

    public void onReceive(Context arg0, Intent intent) {
    if(intent.getAction().equals(Intent.ACTION_USER_PRESENT))
    {
        try {
                UnityPlayer.UnitySendMessage("Camera", "OnUserReturned", null);
            } catch (UnsatisfiedLinkError e) {
                Log.e("UNITY_SEND_MSG", e.getMessage());
                e.printStackTrace();
            }
    }
        }

Manifest:中,

<receiver android:name="UserPresentReceiver">
        <intent-filter>
           <action android:name="android.intent.action.USER_PRESENT" /> 
        </intent-filter>
    </receiver>

我无法弄清楚导致崩溃的原因,并且无法重现它们在 Android 2.3 下。有人可以帮我解决这个问题,或者建议另一种方法在锁定屏幕下停止音乐并在锁定屏幕消失后重新启动音乐吗?

提前致谢

编辑: 堆栈跟踪:

01-01 02:29:31.036: WARN/dalvikvm(8970): JNI WARNING: received null jstring (Check_GetStringUTFChars)
01-01 02:29:31.036: INFO/dalvikvm(8970): "main" prio=5 tid=1 NATIVE
01-01 02:29:31.036: INFO/dalvikvm(8970):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001d928 self=0xccd8
01-01 02:29:31.036: INFO/dalvikvm(8970):   | sysTid=8970 nice=0 sched=0/0 cgrp=default handle=-1345017812
01-01 02:29:31.036: INFO/dalvikvm(8970):   | schedstat=( 3072569000 2291321000 12753 )
01-01 02:29:31.036: INFO/dalvikvm(8970):   at com.unity3d.player.UnityPlayer.UnitySendMessage(Native Method)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at com.angrymobgames.userpresent.UserPresentReceiver.onReceive(UserPresentReceiver.java:19)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.app.ActivityThread.access$3200(ActivityThread.java:125)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.os.Looper.loop(Looper.java:123)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.app.ActivityThread.main(ActivityThread.java:4627)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at java.lang.reflect.Method.invokeNative(Native Method)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at java.lang.reflect.Method.invoke(Method.java:521)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at dalvik.system.NativeStart.main(Native Method)
01-01 02:29:31.036: ERROR/dalvikvm(8970): VM aborting

I have made a java plugin for a unity game that turns music back on when the screen is unlocked. On Android 2.3.3 it works without problem but I am getting complains that it crashes the game under Android 2.2 .
I don't have a device to test this, but there are a LOT of complains so something is really wrong.

Did someone experienced the same problem?

The Java plugin contains only a BroadcastReceiver which sends a message to unity:

    public void onReceive(Context arg0, Intent intent) {
    if(intent.getAction().equals(Intent.ACTION_USER_PRESENT))
    {
        try {
                UnityPlayer.UnitySendMessage("Camera", "OnUserReturned", null);
            } catch (UnsatisfiedLinkError e) {
                Log.e("UNITY_SEND_MSG", e.getMessage());
                e.printStackTrace();
            }
    }
        }

In the Manifest:

<receiver android:name="UserPresentReceiver">
        <intent-filter>
           <action android:name="android.intent.action.USER_PRESENT" /> 
        </intent-filter>
    </receiver>

I can't figure out that is causing there crashes and I can't reproduce them under Android 2.3 . Can someone help me whit this or suggest another approach for stopping the music under lock screen and restarting it after the lock screens gone?

Thanks in advance

EDIT:
StackTrace:

01-01 02:29:31.036: WARN/dalvikvm(8970): JNI WARNING: received null jstring (Check_GetStringUTFChars)
01-01 02:29:31.036: INFO/dalvikvm(8970): "main" prio=5 tid=1 NATIVE
01-01 02:29:31.036: INFO/dalvikvm(8970):   | group="main" sCount=0 dsCount=0 s=N obj=0x4001d928 self=0xccd8
01-01 02:29:31.036: INFO/dalvikvm(8970):   | sysTid=8970 nice=0 sched=0/0 cgrp=default handle=-1345017812
01-01 02:29:31.036: INFO/dalvikvm(8970):   | schedstat=( 3072569000 2291321000 12753 )
01-01 02:29:31.036: INFO/dalvikvm(8970):   at com.unity3d.player.UnityPlayer.UnitySendMessage(Native Method)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at com.angrymobgames.userpresent.UserPresentReceiver.onReceive(UserPresentReceiver.java:19)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.app.ActivityThread.access$3200(ActivityThread.java:125)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.os.Looper.loop(Looper.java:123)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at android.app.ActivityThread.main(ActivityThread.java:4627)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at java.lang.reflect.Method.invokeNative(Native Method)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at java.lang.reflect.Method.invoke(Method.java:521)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-01 02:29:31.036: INFO/dalvikvm(8970):   at dalvik.system.NativeStart.main(Native Method)
01-01 02:29:31.036: ERROR/dalvikvm(8970): VM aborting

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文