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.makotosan.vimeodroid.TransferService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    counter++;//from ww  w  .  jav  a2 s . c  o  m
    transfer = new Transfer();
    final String videoUri = intent.getStringExtra("videouri");
    final TransferType transferType = TransferType.valueOf(intent.getStringExtra("transferType"));
    final String fileName = intent.getStringExtra("fileName");
    Bitmap bitmapThumbnail = null;
    int transferIcon = android.R.drawable.stat_sys_download;

    if (transferType == TransferType.Upload) {
        // Get the resource ID for the video
        final long resourceId = ContentUris.parseId(Uri.parse(videoUri));

        bitmapThumbnail = android.provider.MediaStore.Video.Thumbnails.getThumbnail(getContentResolver(),
                resourceId, android.provider.MediaStore.Video.Thumbnails.MICRO_KIND, null);
        transfer.setIcon(bitmapThumbnail);
        transferIcon = android.R.drawable.stat_sys_upload;
    }

    // Initialize our notification
    final Notification notification = new Notification(transferIcon, "Transferring...",
            System.currentTimeMillis());
    notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = new RemoteViews(this.getPackageName(), R.layout.transferprogress);

    final Intent manageIntent = new Intent(this, ManageTransfersActivity.class);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, manageIntent, 0);

    notification.contentIntent = pendingIntent;
    if (bitmapThumbnail != null) {
        notification.contentView.setImageViewBitmap(R.id.transferprogressIcon, bitmapThumbnail);
    } else {
        notification.contentView.setImageViewResource(R.id.transferprogressIcon, R.drawable.icon);
    }

    notification.contentView.setProgressBar(R.id.transferprogressBar, 100, 0, false);
    notification.contentView.setTextViewText(R.id.transferprogressText, "Transferring... ");
    notification.contentView.setOnClickPendingIntent(R.layout.transferprogress, pendingIntent);

    // Add it to the collection of notifications
    notifications.put(counter, notification);

    // Add our notification to the notification tray
    notificationManager.notify(counter, notification);

    // Initialize our asynchronous transfer task
    final TransferTask task = new TransferTask(counter, transferType);

    task.execute(videoUri, fileName);
    return Service.START_STICKY;
}

From source file:com.ad.mediasharing.ADUploadMediaTask.java

@SuppressWarnings("deprecation")
protected void onPreExecute() {

    Intent intent = new Intent();
    pendingIntent = PendingIntent.getActivity(mActivity, 0, intent, 0);

    contentTitle = "Uploading Story...";
    CharSequence contentText = uploadProgress + "% complete";

    // Show the notification progress 
    if (isPreferenceProgressEnabled) {
        notification = new Notification(R.drawable.ic_launcher_ctv, contentTitle, System.currentTimeMillis());
        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
        notification.contentIntent = pendingIntent;
        notification.setLatestEventInfo(mActivity, contentTitle, contentText, pendingIntent);

        notificationManager.notify(NOTIFICATION_ID, notification);
    }//from   www. j  a v  a2 s .  c o m

    // Show the alert progress bar 
    if (isProgressBarEnabled) {
        pd = new ProgressDialog(mActivity);
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setMessage(contentTitle);
        pd.setCancelable(false);
        pd.show();
    }
}

From source file:com.afrolkin.samplepushclient.GCMIntentService.java

private static void generateNotification(Context context, String message) {
    int icon = R.mipmap.ic_announcement_black_48dp;
    long when = System.currentTimeMillis();
    String title = context.getString(R.string.app_name);
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, "Push Message", when);
    notification.sound = soundUri;/*from  ww w . ja  v  a 2  s. com*/

    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.putExtra("message", message);
    // 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_CANCEL_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:pt.up.fe.cmov.propertymarket.C2DMReceiver.java

@Override
protected void onMessage(Context context, Intent intent) {
    mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = R.drawable.icon;
    String type = intent.getStringExtra(C2DM_DATA_TYPE);
    String name = intent.getStringExtra(C2DM_DATA_NAME);
    String city = intent.getStringExtra(C2DM_DATA_CITY);
    int id = Integer.parseInt(intent.getStringExtra(C2DM_DATA_ID));
    int price = Integer.parseInt(intent.getStringExtra(C2DM_DATA_PRICE));
    String status = intent.getStringExtra(C2DM_DATA_NUM) + " props!";

    String title = city + " - " + price + "";
    String message = name + " is now available in Property Market!";

    if (type.equals("apartment"))
        icon = R.drawable.apartment_icon;
    else if (type.equals("castle"))
        icon = R.drawable.castle_icon;//w w w .j  a  va  2  s .  c  o  m
    else if (type.equals("home"))
        icon = R.drawable.home_icon;

    PropertyMarketActivity.selectedPropertyID = id;

    Intent viewIntent = new Intent(this, PropertyTabMenuActivity.class);

    viewIntent.putExtra("yourpackage.notifyId", id);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 1, viewIntent, 0);

    Notification notification = new Notification(icon, status, System.currentTimeMillis());
    notification.setLatestEventInfo(this, title, message, contentIntent);

    mManager.notify(APP_ID, notification);
}

From source file:org.andicar.service.UpdateCheckService.java

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    if (getSharedPreferences(StaticValues.GLOBAL_PREFERENCE_NAME, Context.MODE_MULTI_PROCESS)
            .getBoolean("SendCrashReport", true))
        Thread.setDefaultUncaughtExceptionHandler(
                new AndiCarExceptionHandler(Thread.getDefaultUncaughtExceptionHandler(), this));

    try {/*from   www  .j  a v  a  2s .c o  m*/
        Bundle extras = intent.getExtras();
        if (extras == null || extras.getBoolean("setJustNextRun") || !extras.getBoolean("AutoUpdateCheck")) {
            setNextRun();
            stopSelf();
        }

        URL updateURL = new URL(StaticValues.VERSION_FILE_URL);
        URLConnection conn = updateURL.openConnection();
        if (conn == null)
            return;
        InputStream is = conn.getInputStream();
        if (is == null)
            return;
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }

        /* Convert the Bytes read to a String. */
        String s = new String(baf.toByteArray());
        /* Get current Version Number */
        int curVersion = getPackageManager().getPackageInfo("org.andicar.activity", 0).versionCode;
        int newVersion = Integer.valueOf(s);

        /* Is a higher version than the current already out? */
        if (newVersion > curVersion) {
            //get the whats new message
            updateURL = new URL(StaticValues.WHATS_NEW_FILE_URL);
            conn = updateURL.openConnection();
            if (conn == null)
                return;
            is = conn.getInputStream();
            if (is == null)
                return;
            bis = new BufferedInputStream(is);
            baf = new ByteArrayBuffer(50);
            current = 0;
            while ((current = bis.read()) != -1) {
                baf.append((byte) current);
            }

            /* Convert the Bytes read to a String. */
            s = new String(baf.toByteArray());

            mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notification = null;
            Intent i = new Intent(this, WhatsNewDialog.class);
            i.putExtra("UpdateMsg", s);
            PendingIntent contentIntent = PendingIntent.getActivity(UpdateCheckService.this, 0, i, 0);

            CharSequence title = getText(R.string.Notif_UpdateTitle);
            String message = getString(R.string.Notif_UpdateMsg);
            notification = new Notification(R.drawable.icon_sys_info, message, System.currentTimeMillis());
            notification.flags |= Notification.DEFAULT_LIGHTS;
            notification.flags |= Notification.DEFAULT_SOUND;
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notification.setLatestEventInfo(UpdateCheckService.this, title, message, contentIntent);
            mNM.notify(StaticValues.NOTIF_UPDATECHECK_ID, notification);
            setNextRun();
        }
        stopSelf();
    } catch (Exception e) {
        Log.i("UpdateService", "Service failed.");
        e.printStackTrace();
    }
}

From source file:com.BeatYourRecord.AssignmentSyncService.java

public void sendNotification(String ytdDomain, String assignmentId) {
    int notificationId = 1;

    Intent assignmentIntent = new Intent(this, DetailsActivity.class);
    assignmentIntent.putExtra(DbHelper.YTD_DOMAIN, ytdDomain);
    assignmentIntent.putExtra(DbHelper.ASSIGNMENT_ID, assignmentId);
    assignmentIntent.putExtra("notificationId", notificationId);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, assignmentIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Notification n = new Notification(R.drawable.icon, "Update from YouTube Direct",
            System.currentTimeMillis());
    n.setLatestEventInfo(getApplicationContext(), "Update from YouTube Direct",
            "For " + SettingActivity.getYtdDomains(this).get(this.ytdDomain), pendingIntent);
    n.defaults |= Notification.DEFAULT_LIGHTS;
    nm.notify(notificationId, n);//from w w w . j  ava2 s  .  c om
}

From source file:vn.easycare.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*  www  .jav a  2s . com*/
private void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_launcher;
    long when = 0;//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, NotificationReceivingActivity.class);

    // set intent so it does not start a new activity
    //         notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent intent = PendingIntent.getActivity(context, (int) when, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.flags |= Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify((int) when, notification);

}

From source file:pj.rozkladWKD.C2DMReceiver.java

public void showNotification(String ticker, String contentTitle, String contentText, PendingIntent intent,
        int number) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    int icon = R.drawable.ic_launcher_wkd;
    CharSequence tickerText = ticker;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    Context context = getApplicationContext();
    notification.number = Prefs.getNotificationMessageNextNumber(context);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    SharedPreferences prefs = Prefs.get(context);
    if (prefs.getBoolean(Prefs.NOTIFICATION_SOUND, true))
        notification.defaults |= Notification.DEFAULT_SOUND;
    if (prefs.getBoolean(Prefs.NOTIFICATION_VIBRATION, true))
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_LIGHTS;

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

    mNotificationManager.notify(NOTIFICATION_ID, notification);

}

From source file:uk.ac.horizon.ubihelper.service.Service.java

@Override
public void onCreate() {
    // One-time set-up...
    Log.d(TAG, "onCreate()");
    // TODO//  w w w.  ja v  a2s. c om
    super.onCreate();
    // handler for requests
    mHandler = new Handler();
    // create taskbar notification
    int icon = R.drawable.service_notification_icon;
    CharSequence tickerText = getText(R.string.notification_start_message);
    long when = System.currentTimeMillis();

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

    Context context = this;
    CharSequence contentTitle = getText(R.string.notification_title);
    CharSequence contentText = getText(R.string.notification_description);
    Intent notificationIntent = new Intent(this, MainPreferences.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

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

    startForeground(RUNNING_ID, notification);

    channelManager = new ChannelManager(peerChannelFactory);
    // sensors
    if (!isEmulator()) {
        Log.d(TAG, "Create sensor channels...");

        SensorChannel magnetic = new SensorChannel("magnetic", this, Sensor.TYPE_MAGNETIC_FIELD);
        channelManager.addChannel(magnetic);
        SensorChannel accelerometer = new SensorChannel("accelerometer", this, Sensor.TYPE_ACCELEROMETER);
        channelManager.addChannel(accelerometer);
        SensorChannel gyro = new SensorChannel("gyro", this, Sensor.TYPE_GYROSCOPE);
        channelManager.addChannel(gyro);
        SensorChannel light = new SensorChannel("light", this, Sensor.TYPE_LIGHT);
        channelManager.addChannel(light);
        SensorChannel pressure = new SensorChannel("pressure", this, Sensor.TYPE_PRESSURE);
        channelManager.addChannel(pressure);
        SensorChannel proximity = new SensorChannel("proximity", this, Sensor.TYPE_PROXIMITY);
        channelManager.addChannel(proximity);
        SensorChannel temperature = new SensorChannel("temperature", this, Sensor.TYPE_TEMPERATURE);
        channelManager.addChannel(temperature);

        try {
            Field f = Sensor.class.getField("TYPE_AMBIENT_TEMPERATURE");
            SensorChannel sc = new SensorChannel("ambientTemperature", this, f.getInt(null));
            channelManager.addChannel(sc);
        } catch (Exception e) {
            Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE");
        }
        try {
            Field f = Sensor.class.getField("TYPE_RELATIVE_HUMIDITY");
            SensorChannel sc = new SensorChannel("relativeHumidity", this, f.getInt(null));
            channelManager.addChannel(sc);
        } catch (Exception e) {
            Log.d(TAG, "Could not get field Sensor.TYPE_AMBIENT_TEMPERATURE");
        }

        // all sensors by full name
        SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        if (sensorManager != null) {
            List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
            for (Sensor sensor : sensors) {
                SensorChannel sc = new SensorChannel("sensor." + sensor.getName(), this, sensor);
                channelManager.addChannel(sc);
            }
        }
        BluetoothDiscoveryChannel btchannel = new BluetoothDiscoveryChannel(this, mHandler, "bluetooth");
        channelManager.addChannel(btchannel);
        WifiScannerChannel wifichannel = new WifiScannerChannel(this, mHandler, "wifi");
        channelManager.addChannel(wifichannel);
        GpsStatusChannel gpsstatus = new GpsStatusChannel("gpsstatus", this);
        channelManager.addChannel(gpsstatus);
        CellLocationChannel cellchannel = new CellLocationChannel(mHandler, this, "cell.location", false);
        channelManager.addChannel(cellchannel);
        CellLocationChannel cellchannel2 = new CellLocationChannel(mHandler, this, "cell.neighbors", true);
        channelManager.addChannel(cellchannel2);
        CellStrengthChannel cellchannel3 = new CellStrengthChannel(this, "cell.strength");
        channelManager.addChannel(cellchannel3);
    }
    channelManager.addChannel(new TimeChannel(mHandler, "time"));
    List<String> locationProviders = LocationChannel.getAllProviders(this);
    for (String provider : locationProviders) {
        LocationChannel locchannel = new LocationChannel("location." + provider, this, provider);
        channelManager.addChannel(locchannel);
    }

    channelManager.addChannel(new MicChannel(mHandler, "mic"));

    Log.d(TAG, "Create http server...");

    // http server
    httpPort = getPort();

    httpListener = new HttpListener(this, httpPort);
    httpListener.start();

    // peer communication
    peerManager = new PeerManager(this);
    int serverPort = peerManager.getServerPort();

    channelManager.addChannel(new EnabledPeersChannel(this, peerManager, "peers"));

    // wifi discovery
    wifiDiscoveryManager = new WifiDiscoveryManager(this);
    wifiDiscoverable = getWifiDiscoverable();
    wifiDiscoveryManager.setServerPort(serverPort);
    wifiDiscoveryManager.setEnabled(wifiDiscoverable);

    bluetooth = BluetoothAdapter.getDefaultAdapter();
    if (bluetooth != null)
        btmac = bluetooth.getAddress();

    telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    if (telephony != null)
        imei = telephony.getDeviceId();

    logManager = new LogManager(this, channelManager);
    logManager.checkPreferences();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefs.registerOnSharedPreferenceChangeListener(onRunChangeListener);

    Log.d(TAG, "onCreate() finished");
}

From source file:com.bakhtiyor.android.tumblr.TumblrService.java

private void showUploadingNotification(int id) {
    long when = System.currentTimeMillis();
    Notification notification = new Notification(R.drawable.icon, APP_TITLE, when);
    Intent notificationIntent = new Intent(this, TumblrService.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(getApplicationContext(), APP_TITLE, "Uploading ...", contentIntent);
    notificationManager.notify(id, notification);
}