Reputation: 578
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build();
StrictMode.setThreadPolicy(policy);
I tried the following code, but generates exception for class not found for ThreadPolicy
#if UNITY_ANDROID
using (AndroidJavaClass strictModeClass = new AndroidJavaClass("android.os.StrictMode"))
{
using (AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy"))
{
AndroidJavaObject Builder = threadpolicy.Call<AndroidJavaObject>("Builder");
AndroidJavaObject permitall = Builder.Call<AndroidJavaObject>("permitAll");
AndroidJavaObject build = permitall.Call<AndroidJavaObject>("build");
strictModeClass.Call<AndroidJavaObject>("setThreadPolicy", build);
}
}
#endif
Upvotes: 0
Views: 922
Reputation: 125255
It simply can't find the class on the Java side. This can be caused my misspelling, ProGuard obfuscating the class name or the package and plugin with the class not included in your project.
In your case, you get "class not found" exception at AndroidJavaClass("android.os.StrictMode.ThreadPolicy")
because ThreadPolicy
is not a package but an inner class so to differentiate between these two, you have to tell JRE that you are looking for an inner class and this can be done by replacing the "."
in the inner class with the "$"
symbol.
Replace
AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode.ThreadPolicy")
with
AndroidJavaClass threadpolicy = new AndroidJavaClass("android.os.StrictMode$ThreadPolicy");
Upvotes: 3