Example usage for android.app Notification Notification

List of usage examples for android.app Notification Notification

Introduction

In this page you can find the example usage for android.app Notification Notification.

Prototype

@Deprecated
public Notification(int icon, CharSequence tickerText, long when) 

Source Link

Document

Constructs a Notification object with the information needed to have a status bar icon without the standard expanded view.

Usage

From source file:com.sentaroh.android.SMBSync.NotificationUtil.java

@SuppressWarnings("deprecation")
static final public void initNotification(GlobalParameters gwa) {
    gwa.notificationManager = (NotificationManager) gwa.svcContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    gwa.notification = new Notification(R.drawable.ic_32_smbsync, gwa.svcContext.getString(R.string.app_name),
            0);/*from  ww  w .  j ava  2  s.com*/

    gwa.notificationAppName = gwa.svcContext.getString(R.string.app_name);

    gwa.notificationIntent = new Intent(gwa.svcContext, SMBSyncMain.class);
    gwa.notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    gwa.notificationIntent.setAction(Intent.ACTION_MAIN);
    gwa.notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    gwa.notificationPendingIntent = PendingIntent.getActivity(gwa.svcContext, 0, gwa.notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    gwa.notificationBuilder = new NotificationCompat.Builder(gwa.svcContext);
    gwa.notificationBuilder.setContentIntent(gwa.notificationPendingIntent)
            //            .setTicker(gwa.notificationAppName)
            .setOngoing(true).setAutoCancel(false).setSmallIcon(gwa.notificationIcon)//smbsync_animation)
            .setContentTitle(gwa.notificationAppName).setContentText("")
            //          .setSubText("subtext")
            //          .setLargeIcon(largeIcon)
            .setWhen(0)
    //         .addAction(action_icon, action_title, action_pi)
    ;
    gwa.notification = gwa.notificationBuilder.build();
    if (Build.VERSION.SDK_INT >= 16) {//JB(4.1
        gwa.notificationBigTextStyle = new NotificationCompat.BigTextStyle(gwa.notificationBuilder);
        gwa.notificationBigTextStyle.setBigContentTitle(gwa.notificationLastShowedTitle)
                .bigText(gwa.notificationLastShowedMessage);
    }

}

From source file:com.sentaroh.android.TextFileBrowser.NotificationUtil.java

@SuppressWarnings("deprecation")
static final public void initNotification(Context c, NotificationCommonParms gwa) {
    gwa.notificationManager = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
    gwa.notification = new Notification(R.drawable.ic_32_browse_text, c.getString(R.string.app_name), 0);

    gwa.notificationAppName = c.getString(R.string.app_name);

    gwa.notificationIntent = new Intent(c, MainActivity.class);
    gwa.notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    gwa.notificationIntent.setAction(Intent.ACTION_MAIN);
    gwa.notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    gwa.notificationPendingIntent = PendingIntent.getActivity(c, 0, gwa.notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    buildNotification(c, gwa);/*  w  w  w  .j ava  2 s. c om*/
}

From source file:com.sentaroh.android.SMBSync2.NotificationUtil.java

@SuppressWarnings("deprecation")
static final public void initNotification(GlobalParameters gwa) {
    gwa.notificationManager = (NotificationManager) gwa.appContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    gwa.notification = new Notification(R.drawable.ic_48_smbsync_wait,
            gwa.appContext.getString(R.string.app_name), 0);

    gwa.notificationAppName = gwa.appContext.getString(R.string.app_name);

    gwa.notificationIntent = new Intent(gwa.appContext, ActivityMain.class);
    gwa.notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    gwa.notificationIntent.setAction(Intent.ACTION_MAIN);
    gwa.notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    gwa.notificationPendingIntent = PendingIntent.getActivity(gwa.appContext, 0, gwa.notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    gwa.notificationLargeIcon = BitmapFactory.decodeResource(gwa.appContext.getResources(),
            gwa.notificationSmallIcon);//from  ww  w.j a  v a2 s  .c  o  m
    gwa.notificationBuilder = new NotificationCompat.Builder(gwa.appContext);
    gwa.notificationBuilder.setContentIntent(gwa.notificationPendingIntent)
            //            .setTicker(gwa.notificationAppName)
            .setOngoing(true).setAutoCancel(false).setSmallIcon(R.drawable.ic_48_smbsync_wait)//smbsync_animation)
            .setLargeIcon(gwa.notificationLargeIcon).setContentTitle(gwa.notificationAppName).setContentText("")
            //          .setSubText("subtext")
            //          .setLargeIcon(largeIcon)
            .setWhen(0)
    //         .addAction(action_icon, action_title, action_pi)
    ;
    gwa.notification = gwa.notificationBuilder.build();
    gwa.notificationBigTextStyle = new NotificationCompat.BigTextStyle(gwa.notificationBuilder);
    gwa.notificationBigTextStyle.setBigContentTitle(gwa.notificationLastShowedTitle)
            .bigText(gwa.notificationLastShowedMessage);

}

From source file:com.innoc.secureline.ui.NotificationBarManager.java

public static void setCallInProgress(Context context) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent contentIntent = new Intent(context, SecureLine.class);
    contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0);
    String notificationText = context.getString(R.string.NotificationBarManager_redphone_call_in_progress);
    Notification notification = new Notification(R.drawable.stat_sys_phone_call, null,
            System.currentTimeMillis());

    notification.setLatestEventInfo(context, notificationText, notificationText, pendingIntent);
    notification.flags = Notification.FLAG_NO_CLEAR;
    notificationManager.notify(RED_PHONE_NOTIFICATION, notification);
}

From source file:com.mindprotectionkit.freephone.ui.NotificationBarManager.java

public static void setCallInProgress(Context context) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent contentIntent = new Intent(context, RedPhone.class);
    contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0);
    String notificationText = context.getString(R.string.NotificationBarManager_redphone_call_in_progress);
    Notification notification = new Notification(R.drawable.stat_sys_phone_call, null,
            System.currentTimeMillis());

    notification.setLatestEventInfo(context, notificationText, notificationText, pendingIntent);
    notification.flags = Notification.FLAG_NO_CLEAR;
    notificationManager.notify(RED_PHONE_NOTIFICATION, notification);
}

From source file:com.odoo.util.ONotificationHelper.java

@SuppressWarnings("deprecation")
public void showNotification(Context context, String title, String subtitle, String authority, int icon) {
    mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notification = new Notification(icon, title, System.currentTimeMillis());
    if (notificationIntent != null) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(context, title, subtitle, pendingIntent);
    }//from   w  w w  .j a  va2  s .com
    mNotifyManager.notify(0, notification);
}

From source file:cn.com.flashman.cordova.xpush.Baidu.java

static public void pushCallback(JSONObject r) {
    //???//from  w w w  .  java2 s  . c  om
    if (isActive && !webview.isFinishing()) {
        webview.sendJavascript("cordova.plugins.XPush.Baidu.pushCheck()");

        //?????
    } else {
        try {
            if (r.getString("type") == "message") {
                JSONObject info = new JSONObject(r.getString("message"));
                String title = info.getString("title");
                String desc = info.getString("description");
                NotificationManager nm = (NotificationManager) webview
                        .getSystemService(webview.NOTIFICATION_SERVICE);
                Notification notification = new Notification(icon, title, System.currentTimeMillis());
                notification.defaults = Notification.DEFAULT_ALL;
                PendingIntent pt = PendingIntent.getActivity(webview, 0,
                        new Intent(webview, webview.getClass()), 0);
                notification.setLatestEventInfo(webview, title, desc, pt);
                nm.notify(nitify_id, notification);
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:uk.co.jarofgreen.cityoutdoors.Service.SendFeatureContentOrReportService.java

protected void onHandleIntent(Intent intent) {

    OurApplication ourApp = (OurApplication) getApplication();

    if (ourApp.hasMoreToUpload()) {
        BaseUploadContentOrReport upload = ourApp.getNextToUpload();

        int featureID = upload.hasFeatureID() ? upload.getFeatureID() : -1;

        // ---------- Start Ongoing Notification
        int icon = R.drawable.notification;
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, "Sending", when);

        Intent notificationIntent = new Intent(this, SendFeatureContentOrReportProgressActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        notification.setLatestEventInfo(getApplicationContext(),
                getString(R.string.send_feature_content_or_report_service_notification_content_title),
                getString(R.string.send_feature_content_or_report_service_notification_content_text),
                contentIntent);//from  w ww  . j  a v a 2 s . c  o  m
        notification.flags = Notification.DEFAULT_SOUND;
        notification.flags |= Notification.DEFAULT_VIBRATE;
        notification.flags |= Notification.DEFAULT_LIGHTS;
        notification.flags |= Notification.FLAG_ONGOING_EVENT;

        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(SendFeatureContentOrReportService.NOTIFICATION_ID, notification);

        //------------ Send
        if (upload instanceof UploadFeatureContent) {
            sendFeatureContent((UploadFeatureContent) upload);
        } else if (upload instanceof UploadFeatureReport) {
            sendFeatureReport((UploadFeatureReport) upload);
        }

        //----------- Remove from que
        ourApp.removeUploadFromQue(upload);

        // ---------- End Ongoing Notification
        if (!ourApp.hasMoreToUpload()) {
            mNotificationManager.cancel(SendFeatureContentOrReportService.NOTIFICATION_ID);
        }

    }

}

From source file:com.networkmanagerapp.RestartWifi.java

/**
 * Notifies the user of progress in the system notification area
 *///  ww  w  .  j av  a 2  s  .  c om
private void showNotification() {
    CharSequence text = getText(R.string.wifi_service_restarted);
    Notification notification = new Notification(R.drawable.ic_stat_networkman, text,
            System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, NetworkManagerMainActivity.class), 0);
    notification.setLatestEventInfo(this, text, text, contentIntent);
    mNM.notify(R.string.wifi_service_restarted, notification);
}

From source file:github.daneren2005.dsub.util.Notifications.java

public static void showPlayingNotification(final Context context, final DownloadService downloadService,
        final Handler handler, MusicDirectory.Entry song) {
    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(),
            System.currentTimeMillis());

    final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
    if (playing) {
        notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    }/* w w  w.j a va2  s .com*/
    boolean remote = downloadService.isRemoteEnabled();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        RemoteViews expandedContentView = new RemoteViews(context.getPackageName(),
                R.layout.notification_expanded);
        setupViews(expandedContentView, context, song, true, playing, remote);
        notification.bigContentView = expandedContentView;
        notification.priority = Notification.PRIORITY_HIGH;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notification.visibility = Notification.VISIBILITY_PUBLIC;
    }

    RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
    setupViews(smallContentView, context, song, false, playing, remote);
    notification.contentView = smallContentView;

    Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
    notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    playShowing = true;
    if (downloadForeground && downloadShowing) {
        downloadForeground = false;
        handler.post(new Runnable() {
            @Override
            public void run() {
                downloadService.stopForeground(true);
                showDownloadingNotification(context, downloadService, handler,
                        downloadService.getCurrentDownloading(),
                        downloadService.getBackgroundDownloads().size());
                downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification);
            }
        });
    } else {
        handler.post(new Runnable() {
            @Override
            public void run() {
                if (playing) {
                    downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification);
                } else {
                    playShowing = false;
                    persistentPlayingShowing = true;
                    NotificationManager notificationManager = (NotificationManager) context
                            .getSystemService(Context.NOTIFICATION_SERVICE);
                    downloadService.stopForeground(false);
                    notificationManager.notify(NOTIFICATION_ID_PLAYING, notification);
                }
            }
        });
    }

    // Update widget
    DSubWidgetProvider.notifyInstances(context, downloadService, playing);
}