How to add button to notifications in android?

You can create an intent for the action (in this case stop playing) and then add it as an action button to your notification. Intent snoozeIntent = new Intent(this, MyBroadcastReceiver.class); snoozeIntent.setAction(ACTION_SNOOZE); snoozeIntent.putExtra(EXTRA_NOTIFICATION_ID, 0); PendingIntent snoozePendingIntent = PendingIntent.getBroadcast(this, 0, snoozeIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.notification_icon) .setContentTitle(“My notification”) .setContentText(“Hello World!”) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setContentIntent(pendingIntent) .addAction(R.drawable.ic_snooze, getString(R.string.snooze), … Read more

How exactly to use Notification.Builder

Notification.Builder API 11 or NotificationCompat.Builder API 1 This is a usage example. Intent notificationIntent = new Intent(ctx, YourClass.class); PendingIntent contentIntent = PendingIntent.getActivity(ctx, YOUR_PI_REQ_CODE, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager nm = (NotificationManager) ctx .getSystemService(Context.NOTIFICATION_SERVICE); Resources res = ctx.getResources(); Notification.Builder builder = new Notification.Builder(ctx); builder.setContentIntent(contentIntent) .setSmallIcon(R.drawable.some_img) .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.some_big_img)) .setTicker(res.getString(R.string.your_ticker)) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setContentTitle(res.getString(R.string.your_notif_title)) .setContentText(res.getString(R.string.your_notif_text)); Notification n = builder.build(); nm.notify(YOUR_NOTIF_ID, n);

How to clear a notification in Android

Use the following code to cancel a Notification: NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID); In this code there is alway the same id used for notifications. If you have different notifications that need to be canceled you have to save the ids that you used to create the Notification.

Sending a notification from a service in Android

Both Activity and Service actually extend Context so you can simply use this as your Context within your Service. NotificationManager notificationManager = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE); Notification notification = new Notification(/* your notification */); PendingIntent pendingIntent = /* your intent */; notification.setLatestEventInfo(this, /* your content */, pendingIntent); notificationManager.notify(/* id */, notification);

Ask for User Permission to Receive UILocalNotifications in iOS 8

Since iOS 8 you need to ask user’s permission to show notifications from your app, this applies for both remote/push and local notifications. In Swift you can do it like this, Update for Swift 2.0 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { // Override point for customization after application launch. if(UIApplication.instancesRespondToSelector(Selector(“registerUserNotificationSettings:”))) { let … Read more

How to play a notification sound on websites?

2021 solution function playSound(url) { const audio = new Audio(url); audio.play(); } <button onclick=”playSound(‘https://your-file.mp3’);”>Play</button> Browser support Edge 12+, Firefox 20+, Internet Explorer 9+, Opera 15+, Safari 4+, Chrome Codecs Support Just use MP3 Old solution (for legacy browsers) function playSound(filename){ var mp3Source=”<source src=”” + filename + ‘.mp3″ type=”audio/mpeg”>’; var oggSource=”<source src=”” + filename + ‘.ogg” … Read more

Open application after clicking on Notification

See below code. I am using that and it is opening my HomeActivity. NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); Intent notificationIntent = new Intent(context, HomeActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)