universal-tools / UTNotificationsFeedback

7 stars 0 forks source link

Crash on Startup because of legacy UnityPlayerNativeActivity dependency #49

Closed stephenmsullivan closed 7 years ago

stephenmsullivan commented 7 years ago

The new versions of unity use <activity android:name="com.unity3d.player.UnityPlayerActivity" as their main activity for Android. The plugin needs to be update to get this activity or the older native activity if that is not found.

NotificationIntentService.java has a hardcoded dependency on "UnityPlayerNativeActivity" which is for older versions of the Unity Editor.

try { mainActivityClass = Class.forName(getApplicationContext().getSharedPreferences(Manager.class.getName(), Context.MODE_PRIVATE).getString(Manager.MAIN_ACTIVITY_CLASS_NAME, "com.unity3d.player.UnityPlayerNativeActivity")); } catch (ClassNotFoundException e) {

This causes the error below:

Caused by android.content.ActivityNotFoundException: Unable to find explicit activity class {com.xxxxx.xxxxxxx/com.unity3d.player.UnityPlayerNativeActivity}; have you declared this activity in your AndroidManifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1777) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1501) at android.app.ContextImpl.startActivity(ContextImpl.java:1404) at android.app.ContextImpl.startActivity(ContextImpl.java:1386) at android.content.ContextWrapper.startActivity(ContextWrapper.java:323) at universal.tools.notifications.NotificationIntentService.onHandleIntent(NotificationIntentService.java:35) at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.os.HandlerThread.run(HandlerThread.java:61)

yuriy-universal-ivanov commented 7 years ago

Hi @stephenmsullivan ,

I've already replied you by email, but just in case duplicating it here:

First of all, thank you for using UTNotifications! Please note, that the plugin is updated: version 1.6.2 uses: mainActivityClass = Class.forName(getApplicationContext().getSharedPreferences(Manager.class.getName(), Context.MODE_PRIVATE).getString(Manager.MAIN_ACTIVITY_CLASS_NAME, "com.unity3d.player.UnityPlayerActivity"));

Best regards, Yuriy, Universal Tools team.

yuriy-universal-ivanov commented 7 years ago

Please also note, that the issue may happen if one of your clients had an old version of the app installed, which still had UnityPlayerNativeActivity as the main Unity activity. If the client has never started a new version of the app, with UnityPlayerActivity, then Manager.MAIN_ACTIVITY_CLASS_NAME value may still have the value of "UnityPlayerNativeActivity". It's pretty rare edge case, unfortunately the user will have to start your app at lease once to update that value. We save the main activity class name in order to support any overwritten (non-standard) main activities.