Example usage for android.content Context NOTIFICATION_SERVICE

List of usage examples for android.content Context NOTIFICATION_SERVICE

Introduction

In this page you can find the example usage for android.content Context NOTIFICATION_SERVICE.

Prototype

String NOTIFICATION_SERVICE

To view the source code for android.content Context NOTIFICATION_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.NotificationManager for informing the user of background events.

Usage

From source file:com.webkey.Ipc.java

public void notiyShow(Context pContext, String message) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(pContext);
    if (!prefs.getBoolean("statusbar", true)) {
        notiyDestroy(pContext);//from  w  w  w.ja  va2 s  .c  o  m
        return;
    }
    Notification notification;

    //      Log.d("Webkey","START_notify");      
    if (manager == null)
        manager = (NotificationManager) pContext.getSystemService(Context.NOTIFICATION_SERVICE);

    notification = new Notification();
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.icon = R.drawable.icon;
    //notification.tickerText = "Service is running";      
    notification.when = System.currentTimeMillis();
    //Intent notificationIntent = new Intent();
    //PendingIntent contentIntent = PendingIntent.getActivity(pContext, 0, notificationIntent, 0);
    //notification.setLatestEventInfo(pContext, "Webkey", "NotificationContent", contentIntent);
    Intent notifyIntent = new Intent(pContext, Webkey.class);
    notification.setLatestEventInfo(pContext, "Webkey", message,
            PendingIntent.getActivity(pContext, 0, notifyIntent, 0));
    manager.notify(1, notification);
}

From source file:kr.co.cashqc.MainActivity.java

@Override
protected void onResume() {
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancelAll();// w  w w.  j a v  a  2 s.  c  o  m
    super.onResume();
    // Check device for Play Services APK.
}

From source file:anastasoft.rallyvision.activity.MenuPrincipal.java

private void cancelNotification() {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancelAll();
}

From source file:com.openerp.base.ir.Attachment.java

private void initNotificationManager() {
    mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationBuilder = new NotificationCompat.Builder(mContext);
    mNotificationBuilder.setContentTitle("Downloading attachment");
    mNotificationBuilder.setContentText("Download in progress");
    mNotificationBuilder.setSmallIcon(R.drawable.ic_oe_notification);
    mNotificationBuilder.setVibrate(new long[] { 1000, 1000 });
    mNotificationBuilder.setAutoCancel(true);
    mNotificationBuilder.setOngoing(true);
}

From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java

private void oldPushNotification(Context context, Intent intent) {
    PushReportUtility.log("oldPushNotification->isForground = " + EBrowserActivity.isForground);
    if (EBrowserActivity.isForground) {
        if (mContext != null) {
            intent.putExtra("ntype", F_TYPE_PUSH);
            ((EBrowserActivity) mContext).handleIntent(intent);
        }//from   w  w w. j ava 2 s.c  o m
    } else {
        CharSequence tickerText = intent.getStringExtra("title"); // ????
        Resources res = context.getResources();
        int icon = res.getIdentifier("icon", "drawable", intent.getPackage());
        long when = System.currentTimeMillis(); // ?
        // ??Nofification

        String notifyTitle = null;
        String pushMessage = intent.getStringExtra("message");
        String value = intent.getStringExtra("data"); // ??json
        try {
            JSONObject bodyJson = new JSONObject(value);
            notifyTitle = bodyJson.getString("msgName");// ?
        } catch (Exception e) {
            PushReportUtility.oe("onReceive", e);
        }
        if (TextUtils.isEmpty(notifyTitle)) {
            notifyTitle = intent.getStringExtra("widgetName");// msgNamewidgetName?
        }
        if (TextUtils.isEmpty(notifyTitle)) {
            notifyTitle = "APPCAN";// widgetNameAPPCAN?
        }
        CharSequence contentTitle = notifyTitle; // ?
        Intent notificationIntent = new Intent(context, EBrowserActivity.class); // ??Activity
        notificationIntent.putExtra("data", value);
        notificationIntent.putExtra("message", pushMessage);
        notificationIntent.putExtra("ntype", F_TYPE_PUSH);
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
        Notification notification = new Notification(icon, tickerText, when);
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_SOUND;
        if (Build.VERSION.SDK_INT >= 16) {
            try {
                Field priorityField = Notification.class.getField("priority");
                priorityField.setAccessible(true);
                priorityField.set(notification, 1);
            } catch (Exception e) {
                PushReportUtility.oe("onReceive", e);
            }
        }
        PendingIntent contentIntent = PendingIntent.getActivity(context, notificationNB, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(context, contentTitle, tickerText, contentIntent);
        // NotificationNotificationManager
        mNotificationManager.notify(notificationNB, notification);
        notificationNB++;
    }
}

From source file:com.commontime.plugin.notification.notification.Manager.java

/**
 * NotificationWrapper manager for the application.
 *//*  w  ww.ja v a 2s. c o  m*/
private NotificationManager getNotMgr() {
    return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}

From source file:eu.codeplumbers.cosi.services.CosiLoyaltyCardService.java

public void showNotification() {
    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setContentTitle(getString(R.string.lbl_loyalty_cards))
            .setContentText(getString(R.string.lbl_contacts_ongoing_sync)).setSmallIcon(R.drawable.ic_fa_file)
            .setOngoing(true);/*from   ww w  .  j  av  a 2  s  . c  om*/
}

From source file:org.kde.necessitas.ministro.MinistroActivity.java

void finishMe() {
    if (-1 != m_id && null != MinistroService.instance())
        MinistroService.instance().retrievalFinished(m_id);
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancelAll();//from w w w .ja v  a  2s  . c  o  m
    finish();
}

From source file:it.mb.whatshare.SendToGCMActivity.java

@SuppressWarnings("deprecation")
private void showNotification(int sharedWhat, boolean sharedViaWhatsapp) {
    String title = getString(R.string.whatshare);
    Intent onNotificationDiscarded = new Intent(this, SendToGCMActivity.class);
    PendingIntent notificationIntent = PendingIntent.getActivity(this, 0, onNotificationDiscarded, 0);
    Notification notification = null;
    int notificationIcon = sharedViaWhatsapp ? R.drawable.notification_icon
            : R.drawable.whatshare_logo_notification;
    int notificationNumber = notificationCounter.incrementAndGet();
    String content = getString(R.string.share_success, getString(sharedWhat), outboundDevice.type);
    // @formatter:off
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(notificationIcon, 0)
            .setContentTitle(title).setContentText(content).setTicker(content)
            .setContentIntent(notificationIntent)
            .setDeleteIntent(PendingIntent.getActivity(this, 0, onNotificationDiscarded, 0))
            .setNumber(notificationNumber);
    // @formatter:on
    if (Build.VERSION.SDK_INT > 15) {
        notification = buildForJellyBean(builder);
    } else {/*from   w  w w. j a  v  a2  s.c om*/
        notification = builder.getNotification();
    }
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // cancel previous notification to clean up garbage in the status bar
    nm.cancel(notificationNumber - 1);
    nm.notify(notificationNumber, notification);
}

From source file:RhodesService.java

@Override
public void onCreate() {
    Logger.D(TAG, "onCreate");

    sInstance = this;

    Context context = this;

    mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    LocalFileProvider.revokeUriPermissions(this);

    Logger.I("Rhodes", "Loading...");
    RhodesApplication.create();/* w  w  w . j  a  va  2  s .  c  om*/

    RhodesActivity ra = RhodesActivity.getInstance();
    if (ra != null) {
        // Show splash screen only if we have active activity
        SplashScreen splashScreen = ra.getSplashScreen();
        splashScreen.start();

        // Increase WebView rendering priority
        WebView w = new WebView(context);
        WebSettings webSettings = w.getSettings();
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
    }

    initForegroundServiceApi();

    // Register custom uri handlers here
    mUriHandlers.addElement(new ExternalHttpHandler(context));
    mUriHandlers.addElement(new LocalFileHandler(context));
    mUriHandlers.addElement(new MailUriHandler(context));
    mUriHandlers.addElement(new TelUriHandler(context));
    mUriHandlers.addElement(new SmsUriHandler(context));
    mUriHandlers.addElement(new VideoUriHandler(context));

    mConnectionChangeReceiver = new ConnectionChangeReceiver();
    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mConnectionChangeReceiver, filter);

    RhodesApplication.start();

    if (BaseActivity.getActivitiesCount() > 0)
        handleAppActivation();
}