PDA

View Full Version : مشکل خیلی مبتدی (نوتیفیکیشن)



netmaster.m
پنج شنبه 14 خرداد 1394, 12:10 عصر
روم به دیوار خیلی مشکل کوچیکیه

این کد مربوط به نوتیفیکشن است ،زمانی درست کار میکنه که توی oncreate تعریف شده باشه، اما وقتی توی تابع onclick یه دکمه تعریف میکنیم کلی ایراد میگیره
مشکل چیه؟


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 intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLA G_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());

dc-master
پنج شنبه 14 خرداد 1394, 17:34 عصر
اینو بذار اخر کدها


public void noti(){


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 intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLA G_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());


}


توی
onclick بنویس :
noti();

netmaster.m
پنج شنبه 14 خرداد 1394, 18:49 عصر
اینو بذار اخر کدها


public void noti(){


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 intent = new Intent(this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLA G_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());


}


توی
onclick بنویس :
noti();


خیلی ممنون (درست شد)