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.pixmob.r2droid.DeviceRegistrationService.java

private void onC2DMUnregistered() {
    final String regId = Preferences.getRegistrationId(getApplicationContext());
    if (DEV) {/* w  w  w.  j  av  a  2s  .  c o m*/
        Log.i(TAG, "Device unregistered from C2DM");
    }

    int event = DISCONNECTED_EVENT;
    String error = null;

    try {
        final String url = "https://r2droidhq.appspot.com/api/1/unregister?regid=" + urlEncode(regId);
        if (DEV) {
            Log.d(TAG, "Unregister URL: " + url);
        }
        final HttpGet req = new HttpGet(url);
        if (!configureClient()) {
            event = CONNECTED_EVENT;
            error = AUTH_FAILED_ERROR;
        } else {
            final int statusCode = gaeClient.execute(req).getStatusLine().getStatusCode();
            if (statusCode == HTTP_SC_OK) {
                Preferences.setAccount(getApplicationContext(), null);
            } else {
                if (DEV) {
                    Log.w(TAG, "Failed to unregister device: statusCode=" + statusCode);
                }
                event = CONNECTED_EVENT;
                error = DEVICE_UNREGISTRATION_ERROR;
            }
        }
    } catch (AppEngineAuthenticationException e) {
        if (e.isAuthenticationPending()) {
            if (DEV) {
                Log.i(TAG, "User must give permission to use authentication token: " + "unregistration aborted",
                        e);
            }
            event = CONNECTED_EVENT;
            error = AUTH_PENDING;
        } else {
            if (DEV) {
                Log.w(TAG, "Authentication error", e);
            }
            event = CONNECTED_EVENT;
            error = AUTH_FAILED_ERROR;
        }
    } catch (IOException e) {
        if (DEV) {
            Log.w(TAG, "Network error", e);
        }
        event = CONNECTED_EVENT;
        error = NETWORK_ERROR;
    } catch (Exception e) {
        Log.wtf(TAG, "Unexpected error", e);
        event = CONNECTED_EVENT;
        error = DEVICE_UNREGISTRATION_ERROR;
    }

    fireEvent(event, error);

    int ticketRes = R.string.device_is_offline;
    if (event != DISCONNECTED_EVENT) {
        ticketRes = R.string.updating_device_failed;
    }
    final Notification notification = new Notification(R.drawable.ic_stat_icon, getString(ticketRes),
            System.currentTimeMillis());
    notification.setLatestEventInfo(this, getString(R.string.app_name), getString(ticketRes), dashboardIntent);
    nm.notify(STATUS_UPDATE_DONE, notification);
}

From source file:com.siahmsoft.soundroid.sdk7.services.UploadService.java

/**
 * Show a notification while this service is running.
 *//*from   w w  w  .  j  a v  a  2s .  com*/
private void showNotification(String text) {
    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.uploadtocloud, text, System.currentTimeMillis());

    // The PendingIntent to launch our activity if the user selects this notification
    Intent i = new Intent(this, MeActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    /*Bundle bundle = new Bundle();
    bundle.putInt("idTrack", soundcloudTrack.getmIdTrack());
    i.putExtras(bundle);*/

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(this, "Uploading...", text, contentIntent);

    // We show this for as long as our service is processing a command.
    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL;
    notification.number = totalUploads;

    // Send the notification.
    // We use a string id because it is a unique number.  We use it later to cancel.
    mNM.notify(777, notification);
}

From source file:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java

@SuppressWarnings("deprecation")
public void setServiceForeground(Context mContext) {
    final int myID = 9999;

    // The intent to launch when the user clicks the expanded notification
    Intent mIntent = new Intent(mContext, BackgroundActivity.class);
    mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendIntent = PendingIntent.getActivity(mContext, 0, mIntent, 0);

    // This constructor is deprecated. Use Notification.Builder instead
    Notification mNotification = new Notification(R.drawable.ic_launcher, getString(R.string.app_name),
            System.currentTimeMillis());

    // This method is deprecated. Use Notification.Builder instead.
    mNotification.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.notification),
            pendIntent);//from  w  ww  .jav a  2  s.c om

    mNotification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(myID, mNotification);
}

From source file:dk.microting.softkeyboard.autoupdateapk.AutoUpdateApk.java

private void raise_notification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    String update_file = preferences.getString(UPDATE_FILE, "");
    if (update_file.length() > 0) {
        // raise notification
        Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_NO_CLEAR;

        CharSequence contentTitle = appName + " update available";
        CharSequence contentText = "Select to install";
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setDataAndType(
                Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file),
                ANDROID_PACKAGE);//from  w  ww . j a  v a  2  s . co  m
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        nm.notify(NOTIFICATION_ID, notification);
    } else {
        nm.cancel(NOTIFICATION_ID);
    }
}

From source file:org.mythdroid.util.UpdateService.java

private void checkMDD(String addr) {

    if (MDDVer == null)
        return;//from  w ww.  jav  a  2 s.  co m

    Version currentVer;
    try {
        currentVer = new Version(MDDManager.getVersion(addr), null);
    } catch (NumberFormatException e) {
        ErrUtil.logErr(e);
        return;
    } catch (IOException e) {
        ErrUtil.logErr(e);
        return;
    }

    if (currentVer.compareTo(MDDVer) >= 0) {
        LogUtil.debug("MDD on " + addr + " is already the latest version" //$NON-NLS-1$ //$NON-NLS-2$
        );
        return;
    }

    LogUtil.debug("MDD ver " + MDDVer.toString() + " is available (current ver on " + //$NON-NLS-1$ //$NON-NLS-2$
            addr + " is " + currentVer.toString() + ")" //$NON-NLS-1$ //$NON-NLS-2$
    );

    if (MDVer != null && MDVer.compareTo(MDDVer) != 0) {
        LogUtil.warn("Version mismatch:" + " MythDroid is " + MDVer.toString() + //$NON-NLS-1$ //$NON-NLS-2$
                ", MDD on " + addr + " is " + MDDVer.toString() //$NON-NLS-1$ //$NON-NLS-2$ 
        );
    }

    final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    final Notification notification = new Notification(R.drawable.logo,
            Messages.getString("UpdateService.0") + "MDD" + //$NON-NLS-1$ //$NON-NLS-2$
                    Messages.getString("UpdateService.1"), //$NON-NLS-1$
            System.currentTimeMillis());

    notification.flags = Notification.FLAG_AUTO_CANCEL;

    final Intent intent = new Intent(MDDACTION);
    intent.putExtra(ADDR, addr);
    intent.putExtra(VER, MDDVer.toString());
    intent.putExtra(URL, MDDVer.url.toString());

    notification.setLatestEventInfo(getApplicationContext(), "MDD" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$
            MDDVer.toString() + Messages.getString("UpdateService.1") + //$NON-NLS-1$ 
                    Messages.getString("UpdateService.3"), //$NON-NLS-1$
            PendingIntent.getBroadcast(this, 0, intent, 0));

    nm.notify(CHECKMDD, notification);

}

From source file:edu.sage.spark.service.XmppConnectionAdapter.java

/**
 * Update the notification for the Beem status.
 * @param status the status to display.//  ww  w  .  j ava  2  s .c  o m
 * @param text the text to display.
 */
@SuppressWarnings("deprecation")
private void updateNotification(int status, String text) {
    String mNotificationText = "Spark Status"; //almyz125 added this

    Notification mStatusNotification;
    mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text,
            System.currentTimeMillis());
    mStatusNotification.defaults = Notification.DEFAULT_LIGHTS;
    mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    mStatusNotification.setLatestEventInfo(mService, mNotificationText, text, //almyz125 added mNotificationText variable
            PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0));
    // bypass the preferences for notification
    mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
}

From source file:com.beem.project.beem.service.XmppConnectionAdapter.java

/**
 * Update the notification for the Beem status.
 * @param status the status to display./*from   ww w  .j  a v a 2s  .  co m*/
 * @param text the text to display.
 */
private void updateNotification(int status, String text) {
    Notification mStatusNotification;
    mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text,
            System.currentTimeMillis());
    mStatusNotification.defaults = Notification.DEFAULT_LIGHTS;
    mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    mStatusNotification.setLatestEventInfo(mService, "Beem Status", text,
            PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0));
    // bypass the preferences for notification
    mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
}

From source file:com.detroitteatime.autocarfinder.Main.java

@Override
public void onClick(View v) {

    int id = v.getId();
    if (id == R.id.start) {
        serviceStopped = data1.getBoolean("shut_down_service", true);
        if (serviceStopped) {
            makeSureGPSIsOn(this);
            startService(new Intent(Main.this, SensorService.class));

            start.setText("Stop monitoring");
            monitor.setBackgroundColor(Color.GREEN);

            nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            String body = "Monitoring";
            String titleString = "Car Finder Service";
            n = new Notification(R.drawable.car_notification, body, System.currentTimeMillis());

            n.setLatestEventInfo(this, titleString, body, pi);

            nm.notify(UNIQUE_ID, n);//from w  w w . ja va  2s . c  o  m

            // Log.i("My Code", "Start Service clicked");

            editor1.putBoolean("shut_down_service", false);
            editor1.commit();
        } else {

            stopMonitoring();

        }
    } else if (id == R.id.manual) {
        new CarTask().execute();
        Intent intent = new Intent(Main.this, Main.class);
        startActivity(intent);
    } else if (id == R.id.navigate) {
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?" + "saddr=" + lat
                + "," + longi + "&daddr=" + carLat + "," + carLongi));
        startActivity(i);
    } else if (id == R.id.satellite) {
        if (mapType == GoogleMap.MAP_TYPE_NORMAL) {

            editor1.putInt("map_type", GoogleMap.MAP_TYPE_HYBRID);
            editor1.commit();

        } else {

            editor1.putInt("map_type", GoogleMap.MAP_TYPE_NORMAL);
            editor1.commit();

        }
        Intent intent1 = new Intent(Main.this, Main.class);
        startActivity(intent1);
    }
}

From source file:name.setup.dance.StepService.java

/**
 * Show a notification while this service is running.
 *//*from w ww  . j  a  v a2s .co m*/
private void showNotification() {
    CharSequence text = getText(R.string.app_name);
    Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    Intent DanceStepAppIntent = new Intent();
    DanceStepAppIntent.setComponent(new ComponentName(this, DanceStepApp.class));
    DanceStepAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, DanceStepAppIntent, 0);
    notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent);

    mNM.notify(R.string.app_name, notification);
}