Skip to content
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

Tap on notification won't open on oneSignal Flutter Android ONLY #488

Closed
nimr77 opened this issue Sep 15, 2021 · 33 comments
Closed

Tap on notification won't open on oneSignal Flutter Android ONLY #488

nimr77 opened this issue Sep 15, 2021 · 33 comments

Comments

@nimr77
Copy link

nimr77 commented Sep 15, 2021

Once I tap on the notification It doesn't open the app but it calls the handler for opening the notification, this issue is only on android, as for the IOS it is working perfectly.

and while using flutter 2.5 I'm getting this warning on building my app

The plugin onesignal_flutter uses a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it
since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

flutter doctor
[✓] Flutter (Channel stable, 2.5.0, on macOS 11.4 20F71 darwin-x64, locale en-MA)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] VS Code (version 1.58.0)
[✓] Connected device (3 available)

@aryany9
Copy link

aryany9 commented Sep 23, 2021

Happening on mine too. I just minimised the app by pressing home button and sent a test notification but on clicking the notification it never opens the app even though the app is not closed. Was not happening before.

@MingSern
Copy link

Same here

@yunuskaygun
Copy link

I also faced the same problem. But on many android devices, when i click on the push notification, the application opens. It just doesn't work on some phones. When I open the application manually, the relevant page is opened. "setNotificationOpenedHandler" method actually worked, but the app does not focus.

@hugoyair
Copy link

I have the same problem with setNotificationOpenedHandler, I´m into the app focus but setNotificationOpenedHandler is not working. Sometimes It works but sometimes not. Do you have any solution about this?

@pankokmu1
Copy link

I'm also experiencing the same problem, in version 3.1.0 of the plugin android works but ios doesn't, and in newer versions it's the other way around.
@Jeasmine
@jkasten2
help, please

@farlabjavier
Copy link

any updates?

@jkasten2
Copy link
Member

jkasten2 commented Nov 30, 2021

@nimr77 @aryanyadav9 @MingSern @yunuskaygun There an Android bug where the app would not bring he app to the foreground that was fixed in OneSignal-Flutter-SDK 3.2.5. This mostly effected notifications with launch URLs set but could also happen with ones without. This was regression bug introduced in the OneSignal-Flutter 3.2.1 so it is recommend you upgrade if you are using a version in that range.

@yunuskaygun Could you provide more details on which devices and Android versions worked and did not work?

@nimr77 The Android V2 embedding build warnings have been fixed in the OneSignal-Flutter-SDK 3.2.4.

@hugoyair Issue #509 is more relevant to setNotificationOpenedHandler issue you are seeing.

@jkasten2
Copy link
Member

@pankokmu1 Could you open a new issue for the iOS issue you are seeing?, this issue is Android specific.

@shameelsadaka
Copy link

Many users has reported this problem.. Does anyone have a fix ?

@Makarov96
Copy link

I have the same issue, any solution for this problem ?

@nan-li
Copy link
Contributor

nan-li commented Dec 28, 2021

Hi @shameelsadaka and @Makarov96, details are in jkasten2's post above.

Are you still experiencing this problem in OneSignal-Flutter-SDK 3.2.5 and up?

@Makarov96
Copy link

Yes I'm using the last version of onesignal_flutter 3.2.7 and don't work

@shameelsadaka
Copy link

Yes. I am also using the version 3.2.7 .

@ismailcaakir
Copy link

I have same error!

@Aksoyhlc
Copy link

i get the same error

@ismailcaakir
Copy link

Have you found any solution? @Makarov96 @shameelsadaka @farlabjavier

@ItsManikantaGopi
Copy link

Same Issue! any solutions?

@shrijanRegmi
Copy link

Facing same issue...

@Aksoyhlc
Copy link

Aksoyhlc commented Feb 9, 2022

Is there anyone who can take care of this? @jkasten2

@nimr77
Copy link
Author

nimr77 commented Feb 9, 2022

I had to use FCM and as for notifications from my website to my app I'm using server app with nodejs, as for onesignal no idea.

@bwrelawan
Copy link

While i change to 3.0.0 Version, its works again but sometimes cant open notification. This better than nothing XD

@nan-li
Copy link
Contributor

nan-li commented Feb 17, 2022

Thanks for reporting the updated information. I will try to reproduce this on OneSignal-Flutter-SDK 3.2.7.

In the meantime, can people share what Android devices and versions they encountered this on?

@nileshsoni97
Copy link

nileshsoni97 commented Feb 17, 2022

Still not solved in OneSignal-Flutter-SDK 3.2.8 : Android 11

I/WM-WorkerWrapper(23643): Worker result SUCCESS for Work [ id=e6c8f226-0ff7-43bc-928b-2ba9e9791714, tags={ com.onesignal.OSNotificationWorkManager$NotificationWorker } ] I/System.out(23643): [okhttp]:check permission begin! I/System.out(23643): [okhttp]:not MMS! I/System.out(23643): [okhttp]:not Email! I/System.out(23643): [socket]:check permission begin! D/DecorView[](23643): getWindowModeFromSystem windowmode is 1 D/DecorView(23643): createDecorCaptionView windowingMode:1 mWindowMode 1 isFullscreen: true

Please Resolve This Issue ASAP.

@nileshsoni97
Copy link

nileshsoni97 commented Feb 18, 2022

photofunny net_

photofunny net_ (1)

@bwrelawan
Copy link

This Problem is solved. This issue is not from onesignal side just a MIUI issue (Redmi & Mi Mobiles). Solve this problem by enabling this option in setting of your app.

photofunny net_

photofunny net_ (1)

How do you explain to all users that the xiaomi user must do that? its work but not for user :(

@Aksoyhlc
Copy link

@nileshsoni97
This method worked for me. I tried to make a request with the permissions handler, which is difficult to explain to users and to do, but I couldn't find it. Is there a shortcut for this process?

@Aksoyhlc
Copy link

Aksoyhlc commented Feb 19, 2022

@bwrelawan @nileshsoni97
I found a way, I am attaching sample codes below.

MainActivity.kt code:

package com.aaaaaaa
import android.content.Intent
import android.os.Build
import android.os.Environment
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import java.io.File
import java.io.FileInputStream
import java.io.IOException
import java.util.*

class MainActivity: FlutterActivity() {
    private val CHANNEL = "notiOpen"

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)

        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
           
            if(call.method == "startNotiOpen"){
                notifiOpen()
            }
        }
    }
    
    private fun notifiOpen() {
        try {
                val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                val manufacturer = Build.MANUFACTURER
                if ("xiaomi".equals(manufacturer, ignoreCase = true)) {
                    intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
                    intent.putExtra("extra_pkgname", packageName);
                    startActivity(intent);
                }

            } catch (ignore: java.lang.Exception) {
            }
            try {
                val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                val manufacturer = Build.MANUFACTURER
                if ("xiaomi".equals(manufacturer, ignoreCase = true)) {
                    intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity")
                    intent.putExtra("extra_pkgname", packageName)
                    startActivity(intent)

                }
            } catch (ignore: java.lang.Exception) {
            }


    }

    
}

Dart code:



static const platformChannel = MethodChannel('notiOpen');

perStart() async {
    await platformChannel.invokeMethod('startNotiOpen');
  }


@nileshsoni97
Copy link

@bwrelawan @nileshsoni97 I found a way, I am attaching sample codes below.

MainActivity.kt code:

package com.aaaaaaa
import android.content.Intent
import android.os.Build
import android.os.Environment
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import java.io.File
import java.io.FileInputStream
import java.io.IOException
import java.util.*

class MainActivity: FlutterActivity() {
    private val CHANNEL = "notiOpen"

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)

        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
           
            if(call.method == "startNotiOpen"){
                notifiOpen()
            }
        }
    }
    
    private fun notifiOpen() {
        try {
                val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                val manufacturer = Build.MANUFACTURER
                if ("xiaomi".equals(manufacturer, ignoreCase = true)) {
                    intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
                    intent.putExtra("extra_pkgname", packageName);
                    startActivity(intent);
                }

            } catch (ignore: java.lang.Exception) {
            }
            try {
                val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                val manufacturer = Build.MANUFACTURER
                if ("xiaomi".equals(manufacturer, ignoreCase = true)) {
                    intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity")
                    intent.putExtra("extra_pkgname", packageName)
                    startActivity(intent)

                }
            } catch (ignore: java.lang.Exception) {
            }


    }

    
}

Dart code:



static const platformChannel = MethodChannel('notiOpen');

perStart() async {
    await platformChannel.invokeMethod('startNotiOpen');
  }

Where to put this dart code? In main() ?

@Aksoyhlc
Copy link

Aksoyhlc commented Feb 19, 2022

@nileshsoni97 I added a button to get permission in "StatelessWidget" and when I clicked the button, I ran the "perStart()" function.

Add it in StatelessWidget
static const platformChannel = MethodChannel('notiOpen');
/*********/
Add the button in onPressed.
perStart()

This method worked for me.

@nileshsoni97
Copy link

@Aksoyhlc
Some Improvements to your answer till onesignal fix it.
Ask for the user to enable { display popup window while running in background permission } in other permission in app settings.

Code For Button (Ask user to enable)

`

if (Platform.isAndroid) {
              try {
                const platformChannel = MethodChannel('getDeviceInfo');
                Map<dynamic, dynamic> result =
                    await platformChannel.invokeMethod('getAndroidInfo');
                print(result);
                if(result.isNotEmpty){
                  if(result["MANUFACTURER"].toString().toLowerCase() == "xiaomi" &&
                      result["IS_OS_MIUI"]==true){
                    const platformChannel = MethodChannel('notiOpen');
                    await platformChannel.invokeMethod('startNotiOpen');
                  }
                }
              } on PlatformException catch (e) {
                if (kDebugMode) {
                  print(e);
                }
              }
            }

`

#Code in main activity

`

package com.yourpackagename
import android.content.Intent
import android.content.pm.PackageInfo
import android.os.Build
import android.text.TextUtils
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStreamReader
import java.util.*

class MainActivity : FlutterActivity() {
    private val CHANNEL = "notiOpen"
    private val CHANNEL2 = "getDeviceInfo"

override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
    super.configureFlutterEngine(flutterEngine)
    MethodChannel(
        flutterEngine.dartExecutor.binaryMessenger,
        CHANNEL
    ).setMethodCallHandler { call, result ->
        if (call.method == "startNotiOpen") {
            notifiOpen()
        } else {
            result.notImplemented()
        }
    }

    MethodChannel(
        flutterEngine.dartExecutor.binaryMessenger,
        CHANNEL2
    ).setMethodCallHandler { call, result ->
        if (call.method == "getAndroidInfo") {
            val deviceInfo = getDeviceInfo()
            if (deviceInfo.isNotEmpty()) {
                result.success(deviceInfo)
            } else {
                result.error("UNAVAILABLE", "Not Recived Device Info", null)
            }
        } else {
            result.notImplemented()
        }
    }
}

private fun getDeviceInfo(): Map<String, Any> {
    var deviceInfo: Map<String, Any> = mapOf()
    try {
        val packageInfo: PackageInfo = applicationContext.getPackageManager()
            .getPackageInfo(applicationContext.getPackageName(), 0)
        deviceInfo = mapOf(
            "MANUFACTURER" to Build.MANUFACTURER,
            "BRAND" to Build.BRAND,
            "MODEL" to Build.MODEL,
            "BOARD" to Build.BOARD,
            "HARDWARE" to Build.HARDWARE,
            "BUILD_CODE" to Build.VERSION.SDK_INT,
            "BUILD_CODE" to BuildConfig.VERSION_CODE,
            "DEVICE" to Build.DEVICE,
            "ID" to Build.ID,
            "VERSION_NAME" to Build.VERSION.RELEASE,
            "TYPE" to Build.TYPE,
            "APP_VERSION" to packageInfo.versionName,
            "APP_BUILD_NUMBER" to packageInfo.longVersionCode,
            "IS_OS_MIUI" to !TextUtils.isEmpty(getSystemProperty("ro.miui.ui.version.name"))
        )
        return deviceInfo
    } catch (e: Exception) {
    }
    return deviceInfo
}

private fun notifiOpen() {
    try {
        val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        val manufacturer = Build.MANUFACTURER
        if ("xiaomi".equals(manufacturer, ignoreCase = true)) {
            intent.setClassName(
                "com.miui.securitycenter",
                "com.miui.permcenter.permissions.PermissionsEditorActivity"
            );
            intent.putExtra("extra_pkgname", "com.yourpackagename")
            startActivity(intent);
        }
    } catch (ignore: java.lang.Exception) {
    } catch (e: Exception) {
    }
    try {
        val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        val manufacturer = Build.MANUFACTURER
        if ("xiaomi".equals(manufacturer, ignoreCase = true)) {
            intent.setClassName(
                "com.miui.securitycenter",
                "com.miui.permcenter.permissions.AppPermissionsEditorActivity"
            )
            intent.putExtra("extra_pkgname", "com.yourpackagename")
            startActivity(intent)
        }
    } catch (ignore: java.lang.Exception) {
    } catch (e: Exception) {
    }
}

fun getSystemProperty(propName: String): String? {
    val line: String
    var input: BufferedReader? = null
    try {
        val p = Runtime.getRuntime().exec("getprop $propName")
        input = BufferedReader(InputStreamReader(p.inputStream), 1024)
        line = input.readLine()
        input.close()
    } catch (ex: IOException) {
        return null
    } finally {
        if (input != null) {
            try {
                input.close()
            } catch (e: IOException) {
                e.printStackTrace()
            }
        }
    }
    return line
}
}

`

Some source of the code : https://gist.github.com/Muyangmin/e8ec1002c930d8df3df46b306d03315d

@supermnemonic
Copy link

same issue

@nan-li
Copy link
Contributor

nan-li commented May 26, 2022

Hi all,

For the Xiaomi issue, thank you for waiting and the fix is now in the latest OneSignal-Flutter-SDK release, version 3.3.1.

Most comments were about the Xiaomi bug, so I will close this issue, but please follow up if you are having any problems with it.

Please open a new issue if you were having a different problem.

@nan-li nan-li closed this as completed May 26, 2022
@mehroze-zaidi
Copy link

In the Xiaomi Remi Note 8, I'm not able to open an app when tapping on notification but It opens on other devices.

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

No branches or pull requests