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)
Related
I want to show image from Url in notification panel for that purpose I am trying to make custom UI with following code but its not working
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, "Custom Notification", when);
NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setImageViewResource(R.id.image, R.drawable.ic_launcher);
contentView.setTextViewText(R.id.title, "Custom notification");
contentView.setTextViewText(R.id.text, "This is a custom layout");
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
notification.defaults |= Notification.DEFAULT_SOUND; // Sound
mNotificationManager.notify(1, notification);
and how I can handle the click of each element like image TextView etc. I haven't found any stuff to handle click of each element.
Use remoteView.setOnClickPendingIntent(viewId, pendingIntent) to give click actions to views in your RemoteViews object. This will allow you to do things like start a Service or send a broadcast (to be received by a BroadcastReceiver).
I have a task in which I have to show Notification for an incoming message inside an activity using BroadcastReceiver with the address and content on the SMS. Now I have to click in order to insert the values in sms in database. When the task is finished i want it to clear from the activity. Is it possible to create notification for incoming sms inside an Activity?
You can Try This no generate your own Notification.
#SuppressWarnings("deprecation")
private static void generateNotification(Context context) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, "New Contact Added",
when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, MainActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);
PendingIntent intent = PendingIntent.getActivity(context, iUniqueId,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, "New", intent);
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(2, notification);
}
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. :)
I am developing notification related things.Problem is click on button. I wrote the following notification related code :
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
"New update received", when);
Intent notificationIntent = new Intent(context,
MessageReceivedActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Bundle bundle=new Bundle();
bundle.putString("post_title", message);
notificationIntent.putExtras(bundle);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, "Agility Logistics", "New update received", intent);
// notification.number +=1;
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notificationManager.notify(0, notification);
If button is clicked, the button onclick notification is overriding all the other notifications.This is undesirable. So how can I show all notifications received without having them overwritten by button click notification ?
I've an app that i can push notifications on to via GCM. I receive the notification in the notification drawer but when i click on it, an activity from the app is started(EntryActivity). What i'd like to happen is if the message in the notification is a url to the .apk file eg 'http://path_to_file.apk', then i'd like the file to start downloading.
Below is the code that generates the notification, is there something i need to add or change to start the download?
/**
* Issues a notification to inform the user that server has sent a message.
*/
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, EntryActivity.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, message, intent);
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(0, notification);
}
Try this:
Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://path_to_file.apk"));
notificationIntent.setClassName("com.android.browser",
"com.android.browser.BrowserActivity");