I have custom notification sound in my application, with those parameters.
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ex_mark_r)
// open app on click
.setContentIntent(contentIntent)
.setSound(defaultSoundUri, RingtoneManager.TYPE_ALARM)
.setContentTitle(title)
.setAutoCancel(false)
.setCategory(Notification.CATEGORY_ALARM)
.addAction(R.mipmap.ex_mark_r, getResources().getString(R.string.alert), pendingIntentAlert)
.addAction( R.mipmap.close, getResources().getString(R.string.dismiss), pendingIntentDismiss)
.setContentText(message);
// .setFullScreenIntent(contentIntent, true);
mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
mBuilder.setDefaults(Notification.DEFAULT_LIGHTS);
mNotification = mBuilder.build();
mNotification.flags |= Notification.VISIBILITY_PUBLIC;
mNotification.flags |= Notification.FLAG_INSISTENT;
mNotification.flags |= Notification.FLAG_HIGH_PRIORITY;
mNotification.flags |= Notification.PRIORITY_MAX;
mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
}
How can I make my sound to rise [start low and become lowed] ?
Related
I simply call a Notification . But It continuously playing sound unless I drag notification ..
Below is my code and right now I am testing on below OREO..
NotificationManager mNotificationManager = (NotificationManager) mContext
.getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "droidudes.zcode";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
String name = "easyTouch";
String Description = "Best Utility Tool";
int importance = NotificationManager.IMPORTANCE_HIGH;//IMPORTANCE_HIGH
NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
mChannel.setDescription(Description);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern();
mChannel.setShowBadge(false);
mNotificationManager.createNotificationChannel(mChannel);
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
mContext, NOTIFICATION_CHANNEL_ID)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
///.setVibrate(longArrayOf(0, 1000, 500, 1000))
.setSmallIcon(R.drawable.icon_of_app)
.setContentTitle(mContext.getString(R.string.app_name))
.setContentText("Toucher Hiding Here")
.setAutoCancel(true);
PendingIntent pendingIntent = PendingIntent.getService(mContext, 1,
new Intent(mContext,EasyTouchService.class)
.setAction(EasyTouchService.ACTION_SHOW), PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pendingIntent);
Notification mNotification = mBuilder.build();
mNotification.flags |= Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
//mNotification.tickerText = getString(R.string.app_name);
// setUpAsForeground(message);
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
I have tried multiple ways by commenting vibration sound in above code . But still sound play for unlimited time..
Try this out:
final PendingIntent pendingIntent = PendingIntent.getActivity(
mCtx,
notfication_id,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(mCtx);
Notification mNotif = builder.setSmallIcon(R.mipmap.logo)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setContentTitle("title of your notification")
.setContentText("details of your notification")
.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(),R.drawable.logo_full))
.build();
mNotif.flags = Notification.FLAG_AUTO_CANCEL;
mNotif.defaults |= Notification.DEFAULT_SOUND;
mNotif.defaults |= Notification.DEFAULT_VIBRATE;
NotificationManager notificationManager = (NotificationManager)mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE), mNotif);
I am trying to play notification sound from my internal storage.
First I downloaded a file when anyone installs an application and then I want to use that notification sound that is downloaded in internal storage.
Following is the code that I am using but notification is playing system sound instead.
Notification notification = new Notification.Builder(this)
.setContentIntent(contentIntent)
.setContentText(text)
.setContentTitle(waktu)
.setSmallIcon(R.mipmap.ic_logo)
.setVibrate(new long[]{500, 1000})
.setSound(Uri.fromFile(new File(Environment.getExternalStorageDirectory()
+ "/Folder", Name + ".mp3")))
.setAutoCancel(true)
.build();
notification.flags |=
Notification.FLAG_ONGOING_EVENT |
Notification.FLAG_SHOW_LIGHTS;
notification.ledOnMS = 300;
notification.ledOffMS = 3000;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Send the notification.
mNotificationManager.notify(0, notification);
I'm creating an Android application. What I'm looking for is after computing the results I want the numeric value to be displayed on the notification window. How can I do it?
To display your result into notification you can use below code to create notification:
Bitmap icon = BitmapFactory.decodeResource(this.getResources(),
R.drawable.noti_icon);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.noti_icon)
.setLargeIcon(icon)
.setContentTitle("Your Title of Notification")
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
.setContentText("write here your score which you have counted");
Intent notificationIntent = new Intent(this, YourActivity.class); // here on notification click you are moved on this activity
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setContentIntent(contentIntent);
Notification notification = notificationBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.visibility |= Notification.VISIBILITY_PUBLIC;
notificationId = 0;
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, notification);
I am getting GCM Push Notification successfully. Now i want to add custom sound file instead of default sound. I have tried with Uri from
file:///res/raw/pop.mp3
in
Notification.DEFAULT_SOUND;
but not success. Please share if you have better solution.
My GCMIntentService.java method code is below -
/**
* Issues a notification to inform the user that server has sent a message.
*/
private static void generateNotification(Context context, String message) {
System.out.println("Called generateNotification>>>>>>>>>>>>>"+message);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
// Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context)
.setSmallIcon(R.drawable.app_icon)
.setContentTitle(title)
.setStyle(
new NotificationCompat.BigTextStyle().bigText(message))
.setContentText(message);
Intent notificationIntent = new Intent(context,
SplashActivity.class);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
mBuilder.setContentIntent(intent);
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}
To add custom sound add this
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.pop);
i.e. In your code change
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
to
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" +R.raw.pop);
notification.defaults |= Notification.DEFAULT_VIBRATE;
I am getting errors with these lines while handling notifications for different API levels. This is how i did so far:
...
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Notification notification;
if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB){
notification = new Notification(icon, text, time);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TaskDetails.class), 0);
notification.setLatestEventInfo(this, title, text, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
}
else
{
notification = new Notification.Builder(this) // error
.setContentTitle(title) // in
.setContentText(tmp_task_brief) // these
.setSmallIcon(icon) // lines
.setLargeIcon(null) // telling "this method call requires API level 11
.build(); // or higher"
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TaskDetails.class), 0);
notification.setLatestEventInfo(this, title, text, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
}
...
I don't understand how to remove these errors. Please help me.
Edit: I did applied edit as below but NotificationCompact.Builer too got deprecated method getNotification() that returns Notification object.
if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB)
{
notification = new Notification(icon, text, time);
notification.setLatestEventInfo(this, title, text, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
}
else
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentIntent(contentIntent)
.setSmallIcon(icon)
.setTicker(text)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle(title)
.setContentText(text);
notification = builder.getNotification();
mNM.notify(NOTIFICATION, notification);
}
Use NotificationCompact.Bulider from support liberary (V4 liberary) that supports from 1.6
i think that will solves your problem.
Finally, with the help of these guys i ended up to the solution of handling the deprecated methods:
if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
notification = new Notification(icon, text, time);
notification.setLatestEventInfo(this, title, text, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(NOTIFICATION, notification);
} else {
NotificationCompat.Builder builder = new NotificationCompat.Builder(
this);
notification = builder.setContentIntent(contentIntent)
.setSmallIcon(icon).setTicker(text).setWhen(time)
.setAutoCancel(true).setContentTitle(title)
.setContentText(text).build();
mNM.notify(NOTIFICATION, notification);
}