سلام، من هرجوری سعی میکنم کد ایجاد نوتیفیکیشن رو توی کلاس نمیتونم بنویسم،
لطفاً راهنمایی کنید چه تغییری باید داد تا بتونم توی یک کلاس جدا و مخصوص به خودش بنویسمش
یا این کد...
لطفاً راهنمایی کنید چه تغییری باید داد تا بتونم توی یک کلاس جدا و مخصوص به خودش بنویسمش
کد پیاچپی:
public static void Notificationm(Context context,String Title,String Detils,String packge){
NotificationManager nm=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify=new Notification(R.drawable.ic_launcher,"شما یک پیام دارید",System.currentTimeMillis());
notify.flags |= Notification.FLAG_AUTO_CANCEL; //Do not clear the notification
notify.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification
notify.flags |= Notification.FLAG_SHOW_LIGHTS; //Do not clear the notification
notify.defaults |= Notification.DEFAULT_LIGHTS; // LED
notify.defaults |= Notification.DEFAULT_SOUND; // Sound
CharSequence title=Title;
CharSequence detils=Detils;
Intent nazar = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://cafebazaar.ir/app/"+packge+"/?l=fa"));
//Intent intent=new Intent(context,send.class );
PendingIntent pend=PendingIntent.getActivity(context, 0, nazar, 0);
notify.setLatestEventInfo(context, title, detils, pend);
nm.notify(0,notify);
}
یا این کد...
کد پیاچپی:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher) // notification icon
.setContentTitle("Notification!") // title for notification
.setContentText("kelidestan.com") // message for notification
.setAutoCancel(true); // clear notification after click
Intent intent1 = new Intent(this, Akhbar.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent1,Intent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());