question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Capturing clicks on Android

See original GitHub issue

Foreground/background notifications are inconsistent at the moment (a common theme for all multi-platform push notification libraries).

On iOS, receiving a remote notification in foreground immediately triggers the onNotification event handler with foreground: true. If the app is in background when the notification arrives, clicking the notification will trigger the onNotification handler with foreground: false.

On Android, foreground notifications work the same. But in background, when the notification arrives, the onNotification handler triggers immediately with foreground: false. Clicking the notificiation opens the app of course, but doesn’t trigger the event handler again.

My goal is to execute some code if and only if the user clicks on a certain notification. Are there any plans to homogenize the behavior across platforms, or is there another way to determine when notifications are clicked on Android?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

50reactions
iggyfiskcommented, Sep 15, 2016

@osungjin @Dean177 it seems there’s a clean, permanent solution on the way https://github.com/zo0r/react-native-push-notification/issues/183, I came up with a hack until then.

After onNewIntent went away in RN 0.30, my workaround is adding the INFO intent to our MainActivity in AndroidManifest.xml. Like so:

<activity
  android:name=".MainActivity"
  android:label="@string/app_name">
  <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.INFO" />
  </intent-filter>
</activity>
<activity
  android:name=".SplashActivity"
  android:theme="@style/SplashTheme">
  <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

This makes getLaunchIntentForPackage return MainActivity, but still launches the app with SplashActivity. It could very well have catastrophic side effects, but we haven’t experienced any yet.

9reactions
iggyfiskcommented, Aug 11, 2016

I forgot to say, in my original issue I wrote:

Clicking the notificiation opens the app of course, but doesn’t trigger the event handler again.

This was a bug in my setup, because our app has two activities (one for a first-time splash screen, and a different MainActivity) so onNewIntent in MainActivity.java was never called. Clicking the notification meant that onCreate in our SplashActivity.java was called instead. Thought I’d mention it it in case someone googles their way in here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Capture click in any button with android - java - Stack Overflow
Capture click in any button with android ... Who to capture the click of any button? final Button button = (Button) findViewById(R.id.button1); ...
Read more >
Input events overview - Android Developers
On Android, there's more than one way to intercept the events from a user's interaction with your application. When considering events ...
Read more >
Android TextView with Clickable Links: how to capture clicks?
Android : Android TextView with Clickable Links: how to capture clicks ? [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] ...
Read more >
Log events | Google Analytics for Firebase
Catch up on everything announced at Firebase Summit, and learn how Firebase can ... Android Web Flutter. This guide shows you how to...
Read more >
Android - Event Handling - Tutorialspoint
Like button presses or screen touch etc. The Android framework maintains an event queue as first-in, first-out (FIFO) basis. You can capture these...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found