James
James

Reputation: 3815

Expo Push Notifications not popping in Android phones (Floating Notifications)

EDIT: I discovered these are known as FLOATING NOTIFICATIONS. Anyone knows how to enable them by default from the app (through a permission etc) on an Android device?

I am currently testing push notifications on an Android device and noticed that although I get the push notifications, they are not popped up on the screen but stay in the background (I need to drag down the top status bar as per picture). I see this as rather useless as the user is not really notified if he's using the phone:

enter image description here

On iPhone, the pop up displays correctly with no issues whatsoever.

Upvotes: 11

Views: 4467

Answers (2)

IC_
IC_

Reputation: 1789

I've finally made it work using Expo.Notifications.createChannelAsync using priority: "max" and when sending a message add channelId: "mychannel".

Upvotes: 6

Bertram Gilfoyle
Bertram Gilfoyle

Reputation: 10235

To show a so called floating notification, app must have the permission SYSTEM_ALERT_WINDOW.

A permission is something given by the user. So, there is no way to enable them by default from the app. What you can do is to take user to the settings page.




Check if you already have the permission

The recommended way to do this is using Settings#canDrawOverlays(Context).This permission is introduced only in API level 23. Therefore as per doc, it there is no need to check the permission in older devices.

However it is seen that this won't work well as expected in some pre-Marshmallow devices like Xiaomi Mi 2. So is better to do it as shown in this post.

Take user to the settings page if there is no permission

If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen. The app requests the user's approval by sending an intent with action Settings.ACTION_MANAGE_OVERLAY_PERMISSION.

Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + context.getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(intent);

Upvotes: 0

Related Questions