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.fanfou.app.opensource.service.DownloadService.java

public static void notifyUpdate(final AppVersionInfo info, final Context context) {
    final String versionInfo = info.versionName;
    final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    final Notification notification = new Notification(R.drawable.ic_notify_icon,
            "?" + versionInfo, System.currentTimeMillis());

    final PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            DownloadService.getNewVersionIntent(context, info), 0);
    notification.setLatestEventInfo(context, "?" + versionInfo,
            "", contentIntent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    nm.notify(2, notification);// w ww  .j a v a 2s  .  c o  m

}

From source file:com.automated.taxinow.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from  w  w w .j av a2  s.c o  m*/
private void generateNotification(Context context, String message) {
    // System.out.println("this is message " + message);
    // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message);
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MainDrawerActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(0, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();
}

From source file:com.mowares.massagerexpressclient.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from w w w.j  a  v  a 2  s .  c o  m

private void generateNotification(Context context, String message) {
    // System.out.println("this is message " + message);
    // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message);
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MainDrawerActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    //notification.setLatestEventInfo(context, title, message, intent);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(0, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();
}

From source file:org.pixmob.droidlink.service.DeviceInitService.java

private static Notification createNotification(Context context, String account, PendingIntent pi) {
    final Notification n = new Notification(android.R.drawable.stat_notify_sync,
            context.getString(R.string.device_setup_running), System.currentTimeMillis());
    n.setLatestEventInfo(context.getApplicationContext(), context.getString(R.string.device_setup_running),
            account, pi);//from www .j  a va 2  s.c  om
    return n;
}

From source file:com.arifin.taxi.penumpang.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from  ww w . jav a  2  s .  c  o m*/
private void generateNotification(Context context, String message) {
    // System.out.println("this is message " + message);
    // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message);
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = new Notification(icon, message, when);

    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MainDrawerActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    notification = builder.setContentIntent(intent).setSmallIcon(icon).setTicker(message).setWhen(when)
            .setAutoCancel(true).setContentTitle(title).setContentText(message).build();
    // mNM.notify(NOTIFICATION, notification);

    /*notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;*/

    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(0, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();
}

From source file:com.cbtec.eliademy.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from  ww  w .  j  a va2s. c  o  m

private static void generateNotification(Context context, String message) {
    int icon = R.drawable.icon;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, Eliademy.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:be.vbsteven.bmtodesk.BackgroundSharingService.java

/**
 * shows the progress notification/* w w w.j  av a  2  s  .  c om*/
 */
private void showProgress() {
    Notification n = new Notification(R.drawable.icon, "Sending bookmark to server...",
            System.currentTimeMillis());
    Intent i = new Intent(this, MainActivity.class); // contentintent is required. so redirect to mainpage
    PendingIntent contentIntent = PendingIntent.getActivity(this, 1, i, 0);
    n.setLatestEventInfo(this, "Bookmark to Desktop", "Sending bookmark to server...", contentIntent);
    nManager.notify(2, n);
}

From source file:net.frygo.findmybuddy.GCMIntentService.java

private static void generateAcceptfriendNotification(Context context, String message, String status) {

    Random rand = new Random();
    int x = rand.nextInt();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, customlistview.class);
    if (status.equalsIgnoreCase("accept"))
        message = message + " added you as buddy";
    else/*from  w  ww .j  a  va 2s.c o m*/
        message = message + " rejected you as buddy";
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT);

    Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis());
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(x, notification);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock mWakelock = pm
            .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title);
    mWakelock.acquire();

    // Timer before putting Android Device to sleep mode.
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        public void run() {
            mWakelock.release();
        }
    };
    timer.schedule(task, 5000);

}

From source file:de.wikilab.android.friendica01.FileUploadService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.i("Andfrnd/UploadFile", "onHandleIntent exec");

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    //Instantiate the Notification:
    CharSequence tickerText = "Uploading...";
    Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_ONGOING_EVENT;

    //Define the Notification's expanded message and Intent:
    Context context = getApplicationContext();
    PendingIntent nullIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
    notification.setLatestEventInfo(context, "Upload in progress...", "You are notified here when it completes",
            nullIntent);//from   w  w w  .j a  va  2 s .c  om

    //Pass the Notification to the NotificationManager:
    mNotificationManager.notify(UPLOAD_PROGRESS_ID, notification);
    /*
    final TwLogin login = new TwLogin();
    login.initialize(FileUploadService.this);
    login.doLogin(FileUploadService.this, null, false);
            
    if (!login.isLoginOK()) {
       showFailMsg(FileUploadService.this, "Invalid login data or no network connection");
       return;
    }
    */
    Bundle intentPara = intent.getExtras();
    fileToUpload = (Uri) intentPara.getParcelable(Intent.EXTRA_STREAM);
    descText = intentPara.getString(EXTRA_DESCTEXT);
    subject = intentPara.getString(Intent.EXTRA_SUBJECT);

    if (targetFilename == null || targetFilename.equals(""))
        targetFilename = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + ".txt";

    String fileSpec = Max.getRealPathFromURI(FileUploadService.this, fileToUpload);

    String tempFile = Max.IMG_CACHE_DIR + "/imgUploadTemp_" + System.currentTimeMillis() + ".jpg";
    Max.resizeImage(fileSpec, tempFile, 1024, 768);

    try {
        Log.i("Andfrnd/UploadFile", "before uploadFile");
        final TwAjax uploader = new TwAjax(FileUploadService.this, true, true);
        uploader.addPostFile(new TwAjax.PostFile("media", targetFilename, tempFile));
        uploader.addPostData("status", descText);
        uploader.addPostData("title", subject);
        uploader.addPostData("source",
                "<a href='http://friendica-for-android.wiki-lab.net'>Friendica for Android</a>");
        uploader.uploadFile(Max.getServer(this) + "/api/statuses/update", null);
        Log.i("Andfrnd/UploadFile", "after uploadFile");
        Log.i("Andfrnd/UploadFile", "isSuccess() = " + uploader.isSuccess());
        Log.i("Andfrnd/UploadFile", "getError() = " + uploader.getError());

        mNotificationManager.cancel(UPLOAD_PROGRESS_ID);
        if (uploader.isSuccess() && uploader.getError() == null) {
            JSONObject result = null;
            try {
                Log.i("Andfrnd/UploadFile", "JSON RESULT: " + uploader.getHttpCode());
                result = (JSONObject) uploader.getJsonResult();

                String postedText = result.getString("text");
                showSuccessMsg(FileUploadService.this);

            } catch (Exception e) {
                String errMes = e.getMessage() + " | " + uploader.getResult();
                if (result != null)
                    try {
                        errMes = result.getString("error");
                    } catch (JSONException fuuuuJava) {
                    }

                showFailMsg(FileUploadService.this, errMes);

                e.printStackTrace();
            }
        } else if (uploader.getError() != null) {
            showFailMsg(FileUploadService.this, uploader.getError().toString());
        } else {
            showFailMsg(FileUploadService.this, uploader.getResult());
        }

    } finally {
        new File(tempFile).delete();
    }
}

From source file:com.google.android.apps.chrometophone.C2DMReceiver.java

private void generateNotification(Context context, String msg, String title, Intent intent) {
    int icon = R.drawable.status_icon;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, title, when);
    notification.setLatestEventInfo(context, title, msg, PendingIntent.getActivity(context, 0, intent, 0));
    notification.defaults = Notification.DEFAULT_SOUND;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    SharedPreferences settings = Prefs.get(context);
    int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(notificatonID, notification);

    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("notificationID", ++notificatonID % 32);
    editor.commit();//from  w w w . ja  v  a  2 s.co m
}