Skip to content

App crashes on notification click #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rgtstha opened this issue Sep 15, 2022 · 10 comments
Closed

App crashes on notification click #596

rgtstha opened this issue Sep 15, 2022 · 10 comments

Comments

@rgtstha
Copy link

rgtstha commented Sep 15, 2022

Description:

Notification is triggered and displaying in the android notification bar but clicking on notification shut down the app with error.

Environment

  1. onesignal_flutter: ^3.4.1
  2. Flutter version: 3.3.0

Steps to Reproduce Issue:

  1. added onesignal_flutter: ^3.4.1 in pubspec.yaml
  2. Initialized the SDK using OneSignal.shared.init(appID)'
  3. Trigger push notification from backend
  4. received push notification
  5. Click on the push notification

Anything else:

Error Code:

I/OneSignal(19652): SDK running startActivity with Intent: Intent { act=android.intent.action.VIEW dat=healhomecare://home flg=0x10000000 }
I/Timeline(19652): Timeline: Activity_launch_request time:15994037 intent:Intent { act=android.intent.action.VIEW dat=healhomecare://home flg=0x10000000 }
D/AndroidRuntime(19652): Shutting down VM
E/AndroidRuntime(19652): FATAL EXCEPTION: main
E/AndroidRuntime(19652): Process: com.healhomecare, PID: 19652
E/AndroidRuntime(19652): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.healhomecare/com.onesignal.NotificationOpenedReceiver}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=healhomecare://home flg=0x10000000 }
E/AndroidRuntime(19652): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
E/AndroidRuntime(19652): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
E/AndroidRuntime(19652): 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
E/AndroidRuntime(19652): 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
E/AndroidRuntime(19652): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
E/AndroidRuntime(19652): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
E/AndroidRuntime(19652): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(19652): 	at android.os.Looper.loop(Looper.java:201)
E/AndroidRuntime(19652): 	at android.app.ActivityThread.main(ActivityThread.java:6810)
E/AndroidRuntime(19652): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(19652): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
E/AndroidRuntime(19652): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
E/AndroidRuntime(19652): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=healhomecare://home flg=0x10000000 }
E/AndroidRuntime(19652): 	at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2022)
E/AndroidRuntime(19652): 	at android.app.Instrumentation.execStartActivity(Instrumentation.java:1679)
E/AndroidRuntime(19652): 	at android.app.Activity.startActivityForResult(Activity.java:4651)
E/AndroidRuntime(19652): 	at android.app.Activity.startActivityForResult(Activity.java:4609)
E/AndroidRuntime(19652): 	at android.app.Activity.startActivity(Activity.java:4970)
E/AndroidRuntime(19652): 	at android.app.Activity.startActivity(Activity.java:4938)
E/AndroidRuntime(19652): 	at com.onesignal.OneSignal.openDestinationActivity(OneSignal.java:2443)
E/AndroidRuntime(19652): 	at com.onesignal.OneSignal.handleNotificationOpen(OneSignal.java:2423)
E/AndroidRuntime(19652): 	at com.onesignal.NotificationOpenedProcessor.processIntent(NotificationOpenedProcessor.java:116)
E/AndroidRuntime(19652): 	at com.onesignal.NotificationOpenedProcessor.processFromContext(NotificationOpenedProcessor.java:64)
E/AndroidRuntime(19652): 	at com.onesignal.NotificationOpenedReceiverBase.onCreate(NotificationOpenedReceiverBase.kt:36)
E/AndroidRuntime(19652): 	at android.app.Activity.performCreate(Activity.java:7224)
E/AndroidRuntime(19652): 	at android.app.Activity.performCreate(Activity.java:7213)
E/AndroidRuntime(19652): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
E/AndroidRuntime(19652): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
E/AndroidRuntime(19652): 	... 11 more
I/Process (19652): Sending signal. PID: 19652 SIG: 9
Lost connection to device.
@emawby
Copy link
Contributor

emawby commented Sep 15, 2022

@rgtstha Thank you for reporting we will investigate. Is this happening on every notification open? Is this happening when the app is backgrounded/foregrounded/killed?

@emawby
Copy link
Contributor

emawby commented Sep 15, 2022

I am not able to reproduce this issue from any of the app states when using flutter 3.3.2 and OneSignal Flutter 3.4.1 in my example project. Is this happening consistently for your app?

@rgtstha
Copy link
Author

rgtstha commented Sep 16, 2022

It is happening every time when notification is tapped in all cases (foreground/background/killed).

I have initialized the the Onesignal setup in the home page. Below is the snippet of my code I used for the setup.


  initOneSignalSetup() async {
  
    await OneSignal.shared.setAppId(oneSignlId);
    await OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);
    await OneSignal().consentGranted(true);
    await OneSignal.shared.setRequiresUserPrivacyConsent(true);
    await OneSignal().userProvidedPrivacyConsent();
    OneSignal.shared.promptUserForPushNotificationPermission(fallbackToSettings: true);
 
    final _contactPerson = context.read<AuthProvider>().currentUser;
    String type = _contactPerson!.type!;
    String loginalbleId = _contactPerson.id.toString();
    await OneSignal.shared.sendTag("loginable", '${type}_$loginalbleId');

    OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult openedResult) {
      print(openedResult.toString());
   
    });

    OneSignal.shared
        .setNotificationWillShowInForegroundHandler((OSNotificationReceivedEvent event) {
      print('FOREGROUND HANDLER CALLED WITH: $event');
    });

    OneSignal.shared.setInAppMessageClickedHandler((OSInAppMessageAction action) {
      print(action.toString());
    });
  }

I have tried removing one signal gradle plugin from app/build.gradle but nothing works.

@andrea689
Copy link

@rgtstha to handle deeplink (healhomecare://home) you must add to the manifest:

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="healhomecare" />
            </intent-filter>

@emawby
Copy link
Contributor

emawby commented Oct 3, 2022

@rgtstha Hello! Did the fix above resolve this issue?

@rgtstha
Copy link
Author

rgtstha commented Oct 10, 2022

@andrea689's solution fixed the app crash issue. But setNotificationOpenedHandler function has not been called after tapping to the notification.

@emawby
Copy link
Contributor

emawby commented Oct 10, 2022

Ok I am closing this one then as a duplicate of #540

@emawby emawby closed this as completed Oct 10, 2022
@SolitaryWolf
Copy link

Hi @emawby , I am not sure this duplicate to #540 . because It is happening every time when notification is tapped in all cases (foreground/background/killed).I have same issue, only for some specific android devices. Any update on this ?

@rgtstha
Copy link
Author

rgtstha commented Mar 16, 2023

@SolitaryWolf This solution worked for me. In your case android:scheme might be different.

@SolitaryWolf
Copy link

@SolitaryWolf This solution worked for me. In your case android:scheme might be different.

But you said that 'But setNotificationOpenedHandler function has not been called after tapping to the notification.' That mean this just fixes crash only? cannot open the deeplink when click notification, right ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants