رفتن به مطلب
انجمن اندروید ایران | آموزش برنامه نویسی اندروید و موبایل
  • android.png.1fab383bc8500cd93127cebc65b1dcab.png

طریقه دائمی کردن نوتیفیکیشن


پست های پیشنهاد شده

سلام!;)

این کد برای نوتیفیکیشن هست! ولی کاربر با زدن دکمه ی clear اونو میتونه پای کنه! حالا من میخوام کاری کنم که تا زمانی که اپلیکیشنم باز هست یا در پشت صفحه باز هست این نوتیفیکیشن پاک نشه!

چیکار باید بکنم؟؟؟:huh:

اینم کد نوتیفیکیشن!

[shcode=java]

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);

        final Notification notification = new Notification(icon, tickerText, when);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

        String ns = Context.NOTIFICATION_SERVICE;

        final NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

        Button statusbarnotify = (Button) findViewById(R.id.statusbarbutton);

        statusbarnotify.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {              

                mNotificationManager.notify(NOTIFICATION_ID, notification);

            }

        });  

    }  

}

 

[/shcode]

لینک ارسال
به اشتراک گذاری در سایت های دیگر

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...