How to Create Notification in Android?
It;s really simple way to do it.. Just create this Notification Class
NotificationClass.class
package com.example.mydoproject; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.support.v4.app.NotificationCompat; import android.text.style.SuperscriptSpan; public class NotificationClass{ private static Intent intent; NotificationManager notificationManager ; int mNotificationId ; NotificationCompat.Builder mBuilder; public static void main(String[] args) { } public void NotificationClass() {} public void setNotification(Context context,Class IntentClass,String Title,String Content,int NotificationIdFlag) { // Build notification // Actions are just fake mBuilder =new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(Title) .setContentText(Content); mNotificationId=NotificationIdFlag; intent = new Intent(context, IntentClass); PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); mBuilder.setContentIntent(pIntent); } public void show() { // Must THrow in Exception try { notificationManager.notify(mNotificationId, mBuilder.build()); //Service Onl // runningService(); } catch (Exception e) { e.printStackTrace(); // TODO: handle exception } } }
and then you can call notification class like this :
NotificationClassI=new NotificationClass(); I.setNotification(getApplicationContext(),NotificationReceiverActivity.class,"Notification title","Notification Content",1); I.show();
nice tutorial
ReplyDelete