I searched many things as like :
How to show icon blinking on google map
but according to this i don't find how to blink notification icon blink
i want to blink icon on this
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, "Hi M rohit", when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, Home.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, "Rohit", intent);
//notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.defaults = Notification.DEFAULT_ALL;
notificationManager.notify(NOTIFICATION, notification);
i found solution :i created animation file and set that file , thanks i found solution
SET FILE name here:-
int icon = R.drawable.animationfile;
long when = System.currentTimeMillis();
notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, "Your location is tracing", when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, Home.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, "Rohit", intent);
//notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.defaults = Notification.DEFAULT_ALL;
notificationManager.notify(NOTIFICATION, notification);
i created this file
animationfile.xml :
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="#drawable/icaon" android:duration="10000" />
<item android:drawable="#drawable/icon" android:duration="10000" />
</animation-list>
To show the upload or download notification like the default one which we have in android (an up or down arrow moving up or down respectively like this , till the upload or download is completed), simply use the below.
Set your notification builder to,
mBuilder.setSmallIcon(android.R.drawable.stat_sys_download);
mBuilder.setTicker(mContext.getString(R.string.notification_ticker)); //Pass an empty string if you dont want any text to appear on the status bar
//Call notify() method of notification manager to see the effect
And when you want the animated icon to stop after the upload or download is completed use below,
mBuilder.setSmallIcon(R.drawable.ic_download); //ic_download is similar looking icon in your drawable folder
mNotifyManager.notify(0, mBuilder.build());
Hope this helps. :)
Related
I done an android application using Phonegap and Java. I got notification successfully in application , after clicking notification app is start from background.I want to reload my Index.html file after notification click. How can i handle this issue ?
Please help
thanks in advance.
thanks mit, here is my generate notification code
private static void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.putExtra("data1", "data1");
MainActivity ObjMain=new MainActivity();
ObjMain.sendJavascript("TestFunc");
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
PendingIntent contentIntent =PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
//notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
if (message!="")
{
notificationManager.notify(0, notification);
}
}
I've searched many times but I was not able to find what I actually needed,
There is something on stackoverflow like this and this
but I need to implement my code for api level 8 not 11. So how can I implement it in my code?
My code is here:
....
mNotification = new Notification(icon, tickerText, when);
//create the content which is shown in the notification pulldown
mContentTitle = mContext.getString(R.string.noti_comes_t_l); //Full title of the notification in the pull down
CharSequence contentText = "click to see notification"; //Text of the notification in the pull down
//you have to set a PendingIntent on a notification to tell the system what you want it to do when the notification is selected
//I don't want to use this here so I'm just creating a blank one
mContentIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, notify.class), 0);
//add the additional content and intent to the notification
mNotification.setLatestEventInfo(mContext, mContentTitle, contentText, mContentIntent);
//make this notification appear in the 'Ongoing events' section
mNotification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL ;
//show the notification
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
....
How can I implement this?
I think you need NotificationCompat from the Support library, you can use this code to generate a notification, adapt it as you need
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(icon)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(message)
.setDeleteIntent(PendingIntent);
mBuilder.setWhen(when);
Intent notificationIntent = new Intent(context, YOURCLASS.class);
notificationIntent.putExtra("url", url);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, random, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
mBuilder.setContentIntent(intent);
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(random, notification);
i have tried notification sample.
i can able to open activity on notification click event.
is it possible to open the desired tab widget on notification click event.
any any body help me to open the tab host on notification click event.
please check the below code..
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
Intent notificationIntent = new Intent(context, Viewmessage.class);
notificationIntent.putExtra("NotificationMessage",message);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(context,0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(context, title, message, pendingNotificationIntent);
notificationManager.notify(0, notification);
Assuming you're using a TabHost -- If you need to set the current tab programmatically you can use TabHost#setCurrentTab(int) or TabHost#setCurrentTabByTag(String)
I am using Phonegap with GCM plugin to show GCM notification.
I am able to display notification correctly but I am not able to show multiple notification. I tried Notification passes old Intent Extras but No results yet.
Please help.
private static void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);
// saveCallIntent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
Intent notificationIntent = new Intent(context, JainDharma.class);
// set intent so it does not start a new activity
//notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, iUniqueId, notificationIntent, 0);
//PendingIntent contentIntent = PendingIntent.getActivity(context, UNIQUE_INT_PER_CALL, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
//notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
If you mean that the last notification overrides the previous one, and you wish to change it, you need to change the following :
notificationManager.notify(0, notification);
Use a different id (instead of 0) for each notification and you'll see all of them.
However, you might want to reconsider whether it's such a good idea to show multiple notifications for the same app. I would find that annoying as a user of your app.
I am displaying a notification whenever a new message is received that contains particular keywords. I have used following code to show the notification in the notification area,
String contentTitle = "V-Card Received";
String contentText = "You have reeived a new V-Card";
mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, receiveVCard.class);
notificationIntent.putExtra("sender", sender);
notificationIntent.putExtra("vCardString", messages[i].getDisplayMessageBody());
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
int icon = R.drawable.contactvcard;
CharSequence tickerText = "V-Card Received";
long when = System.currentTimeMillis();
notifyDetails = new Notification(icon, tickerText, when);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
notifyDetails.flags =Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
Now I want to remove the notification once the user clicks on it. I Have used Notification.FLAG_AUTO_CANCEL to cancel the notification. But it is not removing the notification even if the user clicks on it. Is there any other way to remove the notification, when the user clicks on the notification.
You are basically setting flags after notification has been put.
You need to swap the last two lines of the code you have provided. Set flags before calling nm.notify();
try this it works fine for me
--> 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(i, notification);
this is the prototype of the notification i used in one of my app
Notification notification=new Notification(R.drawable.ic_stat_download_interrupted,getResources().getString(R.string.dint),System.currentTimeMillis());
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_download_complete);
contentView.setImageViewResource(R.id.notimage, R.drawable.ic_stat_download_interrupted);
contentView.setTextViewText(R.id.nottext, getResources().getString(R.string.dint));
contentView.setTextViewText(R.id.nottitle, update.initialDetail.fileName);
notification.contentView = contentView;
notification.flags=Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(getApplicationContext(), MainDashboard.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra(EXTRA_NOTIFICATION_SHOW_DOWNLOADS, true);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),0,notificationIntent, 0);
notification.contentIntent=contentIntent;
nm.notify(update.updateId.intValue(), notification);
its working for me
notifyDetails.flags =Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL;
Hope this is helpful for you.