- Home /
get context of activity for android dont work in unity 5.4 please help
hi. i use this code for get signature hash code:
#if UNITY_EDITOR
return true;
#endif
// 获取Android的PackageManager
AndroidJavaClass Player = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject Activity = Player.GetStatic<AndroidJavaObject> ("currentActivity");
AndroidJavaObject PackageManager = Activity.Call<AndroidJavaObject> ("getPackageManager");
// 获取当前Android应用的包名
string packageName = Activity.Call<string> ("getPackageName");
// 调用PackageManager的getPackageInfo方法来获取签名信息数组
int GET_SIGNATURES = PackageManager.GetStatic<int> ("GET_SIGNATURES");
AndroidJavaObject PackageInfo = PackageManager.Call<AndroidJavaObject> ("getPackageInfo", packageName, GET_SIGNATURES);
AndroidJavaObject[] Signatures = PackageInfo.Get<AndroidJavaObject[]> ("signatures");
// 获取当前的签名的哈希值,判断其与我们签名的哈希值是否一致
if (Signatures != null && Signatures.Length > 0)
{
int hashCode = Signatures [0].Call<int> ("hashCode");
//hashlabel.GetComponent<UILabel> ().text = "hash " + hashCode;
Debug.Log ("signatooooooooooooooor " + hashCode);
return hashCode == 8888888888;//我们签名的哈希值
}
return false;
but when i run it i got this error:
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: static jfieldID 0x70fcce68 not valid for class java.lang.Class<android.app.ApplicationPackageManager>: com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] in call to GetStaticIntField: com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] from boolean com.unity3d.player.UnityPlayer.nativeRender(): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] "UnityMain" prio=5 tid=14 Runnable: com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] | group="main" sCount=0 dsCount=0 obj=0x12c02f90 self=0xb8894ea8: com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] | sysTid=5893 nice=0 cgrp=default sched=0/0 handle=0xa3f9f000: com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] | state=R schedstat=( 3569250003 396440721 5906 ) utm=321 stm=35 core=1 HZ=100: com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] | stack=0xa3e9d000-0xa3e9f000 stackSize=1036KB: com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] | held mutexes= "mutator lock"(shared held): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] native: #00 pc 0000484c /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] native: #01 pc 00003031 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] native: #02 pc 00243b8b /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*, BacktraceMap*)+70): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] native: #03 pc 002282af /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, BacktraceMap*) const+154): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] native: #04 pc 000b00dd /system/lib/libart.so (art::JniAbort(char const*, char const*)+584): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] native: #05 pc 000b0825 /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+60): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] native: #06 pc 000b7147 /system/lib/libart.so (art::CheckJNI::GetStaticIntField(_JNIEnv*, _jclass*, _jfieldID*)+274): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] native: #07 pc 00aabc58 /mnt/asec/com.milad.olfat-2/lib/arm/libunity.so (AndroidJNI_CUSTOM_GetStaticIntField(void*, void*)+200): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] native: #08 pc 00004294 (???): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] at com.unity3d.player.UnityPlayer.nativeRender(Native method): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] at com.unity3d.player.UnityPlayer.a(unavailable:-1): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] at com.unity3d.player.UnityPlayer$b$1.handleMessage(unavailable:-1): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] at android.os.Handler.dispatchMessage(Handler.java:98): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] at android.os.Looper.loop(Looper.java:211): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] at com.unity3d.player.UnityPlayer$b.run(unavailable:-1): com.milad.olfat
01-05 18:06:32.739 5868 5893 F art : art/runtime/check_jni.cc:65] : com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] Runtime aborting...: com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] Aborting thread:: com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] "UnityMain" prio=5 tid=14 Native: com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] | group="" sCount=0 dsCount=0 obj=0x12c02f90 self=0xb8894ea8: com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] | sysTid=5893 nice=0 cgrp=default sched=0/0 handle=0xa3f9f000: com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] | state=R schedstat=( 3611780367 409153744 6009 ) utm=324 stm=37 core=1 HZ=100: com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] | stack=0xa3e9d000-0xa3e9f000 stackSize=1036KB: com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] | held mutexes= "abort lock" "mutator lock"(shared held): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #00 pc 0000484c /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #01 pc 00003031 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #02 pc 00243b8b /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*, BacktraceMap*)+70): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #03 pc 002282af /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, BacktraceMap*) const+154): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #04 pc 0021825d /system/lib/libart.so (art::AbortState::DumpThread(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, art::Thread*)+24): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #05 pc 0021850d /system/lib/libart.so (art::AbortState::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)+436): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #06 pc 002186e1 /system/lib/libart.so (art::Runtime::Abort()+72): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #07 pc 000a65bb /system/lib/libart.so (art::LogMessage::~LogMessage()+1322): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #08 pc 000b02cb /system/lib/libart.so (art::JniAbort(char const*, char const*)+1078): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #09 pc 000b0825 /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+60): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #10 pc 000b7147 /system/lib/libart.so (art::CheckJNI::GetStaticIntField(_JNIEnv*, _jclass*, _jfieldID*)+274): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #11 pc 00aabc58 /mnt/asec/com.milad.olfat-2/lib/arm/libunity.so (AndroidJNI_CUSTOM_GetStaticIntField(void*, void*)+200): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] native: #12 pc 00004294 (???): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] at com.unity3d.player.UnityPlayer.nativeRender(Native method): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] at com.unity3d.player.UnityPlayer.a(unavailable:-1): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] at com.unity3d.player.UnityPlayer$b$1.handleMessage(unavailable:-1): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] at android.os.Handler.dispatchMessage(Handler.java:98): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] at android.os.Looper.loop(Looper.java:211): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] at com.unity3d.player.UnityPlayer$b.run(unavailable:-1): com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] Dumping all threads without appropriate locks held: thread list lock mutator lock: com.milad.olfat
01-05 18:06:32.776 5868 5893 F art : art/runtime/runtime.cc:295] : com.milad.olfat
Comment