Package com. mysession;
Import java. Io. file;
Import Android. App. activity;
Import Android. App. notification;
Import Android. App. icationicationmanager;
Import Android. App. pendingintent;
Import Android. content. context;
Import Android. content. intent;
Import android.net. Uri;
Public class mynotification {
Private icationicationmanager micationicationmanager;
Private notification mnotification;
Private context mcontext;
Private Static final int icationication_id = 20120611;
Public mynotification (context ){
Mnotificationmanager = (notificationmanager) Context
. Getsystemservice (activity. icationication_service );
Mcontext = context;
}
Public void shownotification (String title, file ){
Mnotification = new notification ();
Mnotification. Icon = R. drawable. ic_launcher;
Mnotification. Flags = notification. flag_auto_cancel;
Mnotification. tickertext = "Download finished .";
Mnotification. defaults = notification. default_all;
Mnotification. Sound = NULL;
Pendingintent Pi = pendingintent. getactivity (mcontext, 0, getimagefileintent (file), 1 );
Mnotification. setlatesteventinfo (mcontext, title, "Download finished", Pi );
Micationicationmanager. Notify (icationication_id, mnotification );
}
Public void cancelnotification (){
Mnotificationmanager. Cancel (icationication_id );
}
// Android obtains an intent used to open an image file.
Private intent getimagefileintent (File file)
{
Intent intent = new intent ("android. Intent. Action. View ");
Intent. addcategory ("android. Intent. Category. Default ");
Intent. addflags (intent. flag_activity_new_task );
Uri uri = URI. fromfile (File );
Intent. setdataandtype (Uri, "image /*");
Return intent;
}
}