PDA

View Full Version : نوتیفیکیشن پایدار



pouya1999best@g
سه شنبه 10 تیر 1393, 18:06 عصر
سلام؛
برنامه من یک نوتیفیکیشن میسازه؛
چجوری میشه پایدارش کرد؟؟؟
یعنی نشه از نوتیفیکیشن بار حذفش کرد؛مگر اینکه روی آن کلیک کنیم.
لطفا کمک کنید:افسرده:

Deathgate
چهارشنبه 11 تیر 1393, 04:45 صبح
سلام؛
برنامه من یک نوتیفیکیشن میسازه؛
چجوری میشه پایدارش کرد؟؟؟
یعنی نشه از نوتیفیکیشن بار حذفش کرد؛مگر اینکه روی آن کلیک کنیم.
لطفا کمک کنید:افسرده:
Doste aziz man ye in karo anjam dadam bebin be karet miyad private void Form3_Load(object sender, EventArgs e) {
NotifyIcon notify = new NotifyIcon();
notify.Icon = this.Icon;
notify.Visible = true;
int n = 3000;
notify.ShowBalloonTip(n, "Pchat", "You can click to this for open Pchat", ToolTipIcon.Info);
Hide();
PChat a = new PChat();
a.ShowDialog();
}

pouya1999best@g
چهارشنبه 11 تیر 1393, 14:47 عصر
کمکی بهم نشد دوست عزیز:ناراحت:

shahin bahari
چهارشنبه 11 تیر 1393, 17:20 عصر
یه فلگ داره به اسم setOngoing که اگه اون رو true کنید به شکل on going میشه.
Notification.Builder notif=new Notification.Builder(getApplicationContext());
notif.setOngoing(true)....

pouya1999best@g
چهارشنبه 11 تیر 1393, 23:46 عصر
من از این کد استفاده میکنم؛نمیتونم بهش اضافه کنم؛لطفا خودتون ویرایشش کنید:
(برگرفته ازسایت esfandune.ir)

package com.botskool.StatusBarNotification;
////نام پکیج شما
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class StatusBarNotificationActivity extends Activity {

private static final int NOTIFICATION_ID = 1;
/** برای دفعه اول که اکتیویتی اجرا شد،صدا زده می شود */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

/** تعریف تنظیمات برای نوتیفیکیشن ما */
int icon = R.drawable.icon;
///آدرس آیکون موردنظر جهت نمایش در استاتوس بار
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, StatusBarNotificationActivity.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);
mNotificationManager.notify(NOTIFICATION_ID, notification);

shahin bahari
پنج شنبه 12 تیر 1393, 00:57 صبح
اینجا از روش قدیمی (قبل از اندروید 4) استفاده کرده. این خط رو بعد از خط 34 اضافه کنید.


notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;

pouya1999best@g
پنج شنبه 12 تیر 1393, 13:45 عصر
حالا میخوام وقتی روی نوتیفیکیشن کلیک کردم،از نوار اعلانات ناپدید بشه.
چه کدی بزنم؟؟؟:متفکر:

shahin bahari
پنج شنبه 12 تیر 1393, 14:25 عصر
این خط رو جایگزین خط قبلی کنید:

notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL;

اینجا رو هم بخونید:
http://stackoverflow.com/questions/16179899/android-using-auto-cancel-on-a-notification-when-your-app-is-running-in-the-bac