۱۳۹۴/۰۵/۱۴, ۱۰:۵۷ ب.ظ
سلام من یک نوتیفیکشن ساختم که میخوام کاربر بتونه تو تنظیمات اون رو خاموش یا روشن کنه
من تنظیمات رو درست کردم که وقتی swich خاموشه نشون نده وقتی تغییر داد نشون بده که درست کار میکنه اما وقتی دوباره می خوام خاموش بشه خطا میده
swich پیش فرض روی خاموش هست واسه همین درست کا میکنه کد هام رو اینجا میزارم ممنون میشم کسی بتونه کمکی کنه
هرچند مبهم توضیح دادم
اینها صفحه اصلی برنامه که تو oncreat هستنداینها هم تو اکتیویتی تنظیماتبازم ممنون
من تنظیمات رو درست کردم که وقتی swich خاموشه نشون نده وقتی تغییر داد نشون بده که درست کار میکنه اما وقتی دوباره می خوام خاموش بشه خطا میده
swich پیش فرض روی خاموش هست واسه همین درست کا میکنه کد هام رو اینجا میزارم ممنون میشم کسی بتونه کمکی کنه
هرچند مبهم توضیح دادم
اینها صفحه اصلی برنامه که تو oncreat هستند
کد پیاچپی:
SharedPreferences notification = getSharedPreferences("notiffsett",
MODE_PRIVATE);
boolean norifbollen = notification.getBoolean("notiffk", true);
if (norifbollen) {
notification1 = new Notification(R.drawable.ic_launcher,
"برنامه من", System.currentTimeMillis());
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
RemoteViews contentView = new RemoteViews(getPackageName(),
R.layout.custom);
contentView
.setImageViewResource(R.id.image, R.drawable.ic_launcher);
contentView.setTextViewText(R.id.title, "نکات مورد نظر");
contentView.setTextViewText(R.id.text,
"|در اینجا نکات قرار می گیرد|در اینجا نکات قرار می گیرد|");
notification1.contentView = contentView;
Intent notificationIntent = new Intent(this, Main_page.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification1.contentIntent = contentIntent;
notification1.flags |= Notification.FLAG_ONGOING_EVENT;
notification1.flags |= Notification.FLAG_HIGH_PRIORITY;
mNotificationManager.notify(1, notification1);
} else {
//اشکال برنامه اینجا باید باشه
// notification1.flags |= Notification.FLAG_AUTO_CANCEL;
}
کد پیاچپی:
//in 3 satr to oncreat hast
notification = getSharedPreferences("notiffsett", MODE_PRIVATE);
norifbollen = notification.getBoolean("notiffk", true);
swnoti.setChecked(norifbollen);
//این 3 سطر هم وقتی باتن ذخیره کلیک میشه
SharedPreferences.Editor notiedit = notification.edit();
notiedit.putBoolean("notiffk", swnoti.isChecked());
notiedit.commit();