1yaram
شنبه 04 مرداد 1393, 19:53 عصر
این کد من برای نمایش نوتیفیکیشنه که با کلیک کردن روی یه باتن نوتیفیکیشن مورد نظر به نمایش در میاد
خب حالا من کدی که لازم دارم اینه :
اولا نوتیفیکیشن بایدار باشه و حتی اگه گوشی خاموش بشه اون بالا بمونه دقیقا مثل برنامه : (باتری دکتر)
دوما بتونم یه دکمه دیگه قرار بدم برای حذف کردن نوتیفیکیشن(اگه بشه که آیکون چک باکس بزارم با گذاشتن تیک نوتیفیکیشن بیاد و با برداشتنش بره دیگه عالی میشه):متفکر:
private static final int NOTIFICATION_ID = 1;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("درمورد برنامه");
setContentView(R.layout.about);
int icon = R.drawable.ic_launcher;
//آدرس آیکون موردنظر جهت نمایش در استاتوس بار
CharSequence tickerText = "This is a sample notification";
long when = System.currentTimeMillis();
Context context = getApplicationContext();
CharSequence contentTitle = "Sample notification";
CharSequence contentText = "This notification has been generated as a result of button click.";
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
/** مقداردهی اولیه Notificationبا استفاده از تنظیمات بالا */
final Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
/** بازیابی مرجع از NotificationManager*/
String ns = Context.NOTIFICATION_SERVICE;
final NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
/** Listener برای کلیک */
Button statusbarnotify = (Button) findViewById(R.id.notific);
statusbarnotify.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
});
خب حالا من کدی که لازم دارم اینه :
اولا نوتیفیکیشن بایدار باشه و حتی اگه گوشی خاموش بشه اون بالا بمونه دقیقا مثل برنامه : (باتری دکتر)
دوما بتونم یه دکمه دیگه قرار بدم برای حذف کردن نوتیفیکیشن(اگه بشه که آیکون چک باکس بزارم با گذاشتن تیک نوتیفیکیشن بیاد و با برداشتنش بره دیگه عالی میشه):متفکر:
private static final int NOTIFICATION_ID = 1;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("درمورد برنامه");
setContentView(R.layout.about);
int icon = R.drawable.ic_launcher;
//آدرس آیکون موردنظر جهت نمایش در استاتوس بار
CharSequence tickerText = "This is a sample notification";
long when = System.currentTimeMillis();
Context context = getApplicationContext();
CharSequence contentTitle = "Sample notification";
CharSequence contentText = "This notification has been generated as a result of button click.";
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
/** مقداردهی اولیه Notificationبا استفاده از تنظیمات بالا */
final Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
/** بازیابی مرجع از NotificationManager*/
String ns = Context.NOTIFICATION_SERVICE;
final NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
/** Listener برای کلیک */
Button statusbarnotify = (Button) findViewById(R.id.notific);
statusbarnotify.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
});