Using the display intent on a page of a wearable notification - android

I create a wearable compatible notification with a second page which should embedd a custom activity (on the wearable).
Here is the relevant part of the Manifest from the wearable app:
<activity android:name=".Test"
android:label="aaa"
android:allowEmbedded="true"
android:taskAffinity=""
android:theme="#android:style/Theme.DeviceDefault.Light">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Here is my related android code from the phone:
Intent notificationIntent = new Intent();
notificationIntent.setClassName(BuildConfig.APPLICATION_ID, BuildConfig.APPLICATION_ID + ".wear.Main");
PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap bg = BitmapFactory.decodeResource(getResources(), R.drawable.bg_wearable);
Notification test = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Title")
.setContentText("Message")
.extend(new NotificationCompat.WearableExtender()
.setBackground(bg)
.addPage(new NotificationCompat.Builder(this)
.setContentTitle("Page 1")
.extend(new NotificationCompat.WearableExtender()
.setDisplayIntent(notificationPendingIntent)
.setCustomSizePreset(NotificationCompat.WearableExtender.SIZE_FULL_SCREEN)
).build()
)
)
.build();
NotificationManagerCompat.from(this).notify(12345, test);
Do you have any idea why this don't work on the phone, but on the wearable itself?

You can only create and issue custom notifications with embedded activities from the wearable itself.
From the docs:
You can only create and issue custom notifications on the wearable,
and the system does not sync these notifications to the handheld.
Source

Related

FCM notification doesn't show notification pop up in background

I'm using firebase cloud function for showing notification in my app and that working perfectly only issue I'm facing is when app is closed or in background notification doesn't show pop up.
Heads up notifications are used in app and I do get the notification but notification doesn't pop up as it do while app is in foreground.I have set the Priority to high for both channel and notification but still it doesn't work.
My Service Class :
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("msg", "onMessageReceived: " + remoteMessage.getData().get("message"));
Intent intent = new Intent(this, WebViewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
String channelId = "Default";
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.app_logo)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true).setContentIntent(pendingIntent)
.setDefaults(DEFAULT_SOUND | DEFAULT_VIBRATE)
.setPriority(Notification.PRIORITY_MAX);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, "Default channel", NotificationManager.IMPORTANCE_HIGH);
channel.setShowBadge(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
manager.createNotificationChannel(channel);
}
manager.notify(0, builder.build());
}
Manifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="com.noderon.riscalert.WebViewActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.noderon.riscalert.MainActivity">
</activity>
<service
android:name=".NotificationService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
Any help would be appreciated. Thanku
As you are already setting the Priorities it seems like you are not adding the metadata for the notification and when the app is in the background it won't get any data that's why it only showing the pop up in the foreground
add these metadata in your code:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/ic_stat_ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="#string/default_notification_channel_id" />
Also, you can see Google Cloud Messaging documentation for more details
Happy coding
I have faced the same issue. I have followed the official documentation from the firebase and now notifications are working fine. Follow this link
.
Have you created FirebaseMessage Instance() in your Activity?

Flutter app does not come to foreground when tapped on native android background service notification

I am new to learning flutter. My flutter app has a native android background service on kotlin where I have a socket running and whenever the socket listens to something I generate a notification using NotificationCompat.Builder.
But I am unable to bring the Flutter app back to foreground when ever the user taps on the notification.
I have tried creating a pendingintent and passing it to notificationbuilder setContentIntent() but nothing happens on tap.
shownotification function on Native background service:
fun shownotification (){
packageNamer = this.getPackageName()
launchIntent = this.getPackageManager().getLaunchIntentForPackage(packageName)
var className = launchIntent?.getComponent()!!.className.javaClass
intent.action = "SELECT_NOTIFICATION"
intent.setClass(this,className)
pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
var builder = NotificationCompat.Builder(this, "notifications")
.setOngoing(true)
.setContentIntent(pendingIntent)
.setFullScreenIntent(pendingIntent, true)
.setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
.setContentTitle("My notification")
.setContentText("Much longer text that cannot fit one line...")
.setStyle(NotificationCompat.BigTextStyle()
.bigText("Much longer text that cannot fit one line..."))
.setPriority(NotificationCompat.PRIORITY_HIGH)
manager?.notify(456,builder.build())
}
AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name=".MyApplication"
android:label="bizzyb_demo"
android:icon="#mipmap/ic_launcher">
<service android:name=".MyService" android:exported="true" android:enabled="true"/>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
What am I doing wrong here. I believe I am missing something very obvious here as I am new to mobile apps development.
Your expert feedbacks will be appreciated.
Thanks
You need to include click_action: FLUTTER_NOTIFICATION_CLICK as a "Custom data" key-value-pair in the notification payload.
Bundle bundle = new Bundle();
bundle.putString(Constants.EXAM_ID,String.valueOf(lectureDownloadStatus.getExamId()));
var builder = NotificationCompat.Builder(this, "notifications")
.setOngoing(true)
.setContentIntent(pendingIntent)
.setFullScreenIntent(pendingIntent, true)
.setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
.setContentTitle("My notification")
.setContentText("Much longer text that cannot fit one line...")
.setStyle(NotificationCompat.BigTextStyle()
.bigText("Much longer text that cannot fit one line..."))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setExtras(bundle) // Set the bundle

Android : GCM PendingIntent not working in Samsung note 2

I can receive gcm notification in all the devices. But when i click the notification then it is not navigating to corresponding activity what I have given in the Intent. I did not set any flags for the Intent.
It's working fine in all other devices.
This is my code.
Intent notificationIntent = new Intent(GcmIntentService.this, NotificationActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(GcmIntentService.this, 0, notificationIntent, 0);
mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.gcm)
.setContentTitle("New messages")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setDefaults(Notification.DEFAULT_SOUND)
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mBuilder.setAutoCancel(true);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
My manifest
<receiver
android:name="mellotv.com.gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
I have checked the device api and it is 19.
Could some one help me to solve this problem?

Resume activity on notification click [duplicate]

This question already has answers here:
Click on notification starts activity twice
(4 answers)
Closed 3 years ago.
I am having a problem with resuming activity on notification click. I have an app that plays a single song for some time. The idea is when you play a song, and press Home button, there should be notification that returns you to the app where you can stop the song.
Here is how I am making the notification:
private void pushNotificationsOld()
{
Intent resultIntent = new Intent(context, MainActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager mNM;
NotificationCompat.Builder builder;
mNM = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(getResources().getString(R.string.app_name))
.setContentText("Now playing: " + songList.get(activeSong).name)
.setOngoing(true);
builder.setContentIntent(resultPendingIntent);
mNM.notify(mId, builder.build());
}
And here is my Manifest:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
pushNotificationsOld() is called by pressing the Play button.
And there is only one activity in the app.
With this code, when I press notification, new activity is created, and the music continues playing in the background.
When I press Home and get back to app from recent apps or icon, it worsk good.
In your manifest.xml, add for the MainActivity:
android:launchMode="singleTop"

Android Push notifications on Samsung Galaxy Tab 10

I have a pair applications where I use a GCMBroadcastReceiver and a GCMIntentService to listen for google cloud messaging messages and then send a notification to Android's tray via NotificationManager. Pretty standard code, as far as I know I'm not doing anything strange here.
And the code works, most all devices show my notifications (both) , each application shows a similar notification, with a different icon.
The problem is, the Galaxy Tab 10 is only showing one of them, and the other not. And I can't put my finger on what could be causing the difference.
Specially since the code is so simple.
here is the code where I make the notification:
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 1,
new Intent(this, HomeActivity.class), 0);
Resources res = getResources();
Bitmap bm = BitmapFactory.decodeResource(res, R.drawable.notifier_app_launcher);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setLargeIcon(bm)
.setSmallIcon(R.drawable.app_icon_notifier)
.setContentTitle(getString(R.string.title))
.setNumber(number)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Also, this is how I define my receiver:
<receiver android:name="com.company.mobile.app.GcmBroadcastReceiver" android:exported="true" android:process=":remote" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.company.mobile.app" />
</intent-filter>
Is it a known error of that model? Has anyone experienced this before? am I missing something in the code? All feedback is welcome.

Categories

Resources