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:no.ntnu.wifimanager.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from  w w  w  .  j a va  2 s .co m
private static void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_stat_gcm;
    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, ClientListActivity.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:com.piusvelte.sonet.core.PhotoUploadService.java

private void start(Intent intent) {
    if (intent != null) {
        String action = intent.getAction();
        if (Sonet.ACTION_UPLOAD.equals(action)) {
            if (intent.hasExtra(Accounts.TOKEN) && intent.hasExtra(Statuses.MESSAGE)
                    && intent.hasExtra(Widgets.INSTANT_UPLOAD)) {
                String place = null;
                if (intent.hasExtra(Splace))
                    place = intent.getStringExtra(Splace);
                String tags = null;
                if (intent.hasExtra(Stags))
                    tags = intent.getStringExtra(Stags);
                // upload a photo
                Notification notification = new Notification(R.drawable.notification, "uploading photo",
                        System.currentTimeMillis());
                notification.setLatestEventInfo(getBaseContext(), "photo upload", "uploading",
                        PendingIntent.getActivity(PhotoUploadService.this, 0,
                                (Sonet.getPackageIntent(PhotoUploadService.this, About.class)), 0));
                ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID,
                        notification);//from  w  w w  . j av  a 2s .  c  om
                (new AsyncTask<String, Void, String>() {

                    @Override
                    protected String doInBackground(String... params) {
                        String response = null;
                        if (params.length > 2) {
                            Log.d(TAG, "upload file: " + params[2]);
                            HttpPost httpPost = new HttpPost(String.format(FACEBOOK_PHOTOS, FACEBOOK_BASE_URL,
                                    Saccess_token, mSonetCrypto.Decrypt(params[0])));
                            MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                            File file = new File(params[2]);
                            ContentBody fileBody = new FileBody(file);
                            entity.addPart(Ssource, fileBody);
                            HttpClient httpClient = SonetHttpClient
                                    .getThreadSafeClient(getApplicationContext());
                            try {
                                entity.addPart(Smessage, new StringBody(params[1]));
                                if (params[3] != null)
                                    entity.addPart(Splace, new StringBody(params[3]));
                                if (params[4] != null)
                                    entity.addPart(Stags, new StringBody(params[4]));
                                httpPost.setEntity(entity);
                                response = SonetHttpClient.httpResponse(httpClient, httpPost);
                            } catch (UnsupportedEncodingException e) {
                                Log.e(TAG, e.toString());
                            }
                        }
                        return response;
                    }

                    @Override
                    protected void onPostExecute(String response) {
                        // notify photo success
                        String message = getString(response != null ? R.string.success : R.string.failure);
                        Notification notification = new Notification(R.drawable.notification,
                                "photo upload " + message, System.currentTimeMillis());
                        notification.setLatestEventInfo(getBaseContext(), "photo upload", message,
                                PendingIntent.getActivity(PhotoUploadService.this, 0,
                                        (Sonet.getPackageIntent(PhotoUploadService.this, About.class)), 0));
                        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID,
                                notification);
                        stopSelfResult(mStartId);
                    }

                }).execute(intent.getStringExtra(Accounts.TOKEN), intent.getStringExtra(Statuses.MESSAGE),
                        intent.getStringExtra(Widgets.INSTANT_UPLOAD), place, tags);
            }
        }
    }
}

From source file:com.tanlet.annotation.system.SystemFragment.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
void showNotifications() {
    Notification notification;//from w ww .j  a v  a  2 s  .co m
    if (Build.VERSION.SDK_INT >= 11) {
        notification = new Notification.Builder(getActivity()).setSmallIcon(R.drawable.help)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
                .setContentTitle("AndroidAnnotations")
                .setContentText("https://github.com/excilys/androidannotations/wiki/AvailableAnnotations")
                .build();
    } else {
        notification = new Notification(R.drawable.ic_launcher, "AndroidAnnotations", 0);
        PendingIntent contentIntent = PendingIntent.getActivity(getActivity(), 0, new Intent(), 0);
        notification.setLatestEventInfo(getActivity(), "My notification", "Hello World!", contentIntent);
    }

    notificationManager.notify(1, notification);

}

From source file:com.shafiq.myfeedle.core.PhotoUploadService.java

private void start(Intent intent) {
    if (intent != null) {
        String action = intent.getAction();
        if (Myfeedle.ACTION_UPLOAD.equals(action)) {
            if (intent.hasExtra(Accounts.TOKEN) && intent.hasExtra(Statuses.MESSAGE)
                    && intent.hasExtra(Widgets.INSTANT_UPLOAD)) {
                String place = null;
                if (intent.hasExtra(Splace))
                    place = intent.getStringExtra(Splace);
                String tags = null;
                if (intent.hasExtra(Stags))
                    tags = intent.getStringExtra(Stags);
                // upload a photo
                Notification notification = new Notification(R.drawable.notification, "uploading photo",
                        System.currentTimeMillis());
                notification.setLatestEventInfo(getBaseContext(), "photo upload", "uploading",
                        PendingIntent.getActivity(PhotoUploadService.this, 0,
                                (Myfeedle.getPackageIntent(PhotoUploadService.this, About.class)), 0));
                ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID,
                        notification);//from   w  w w. j  a v  a 2 s.co  m
                (new AsyncTask<String, Void, String>() {

                    @Override
                    protected String doInBackground(String... params) {
                        String response = null;
                        if (params.length > 2) {
                            Log.d(TAG, "upload file: " + params[2]);
                            HttpPost httpPost = new HttpPost(String.format(FACEBOOK_PHOTOS, FACEBOOK_BASE_URL,
                                    Saccess_token, mMyfeedleCrypto.Decrypt(params[0])));
                            MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                            File file = new File(params[2]);
                            ContentBody fileBody = new FileBody(file);
                            entity.addPart(Ssource, fileBody);
                            HttpClient httpClient = MyfeedleHttpClient
                                    .getThreadSafeClient(getApplicationContext());
                            try {
                                entity.addPart(Smessage, new StringBody(params[1]));
                                if (params[3] != null)
                                    entity.addPart(Splace, new StringBody(params[3]));
                                if (params[4] != null)
                                    entity.addPart(Stags, new StringBody(params[4]));
                                httpPost.setEntity(entity);
                                response = MyfeedleHttpClient.httpResponse(httpClient, httpPost);
                            } catch (UnsupportedEncodingException e) {
                                Log.e(TAG, e.toString());
                            }
                        }
                        return response;
                    }

                    @Override
                    protected void onPostExecute(String response) {
                        // notify photo success
                        String message = getString(response != null ? R.string.success : R.string.failure);
                        Notification notification = new Notification(R.drawable.notification,
                                "photo upload " + message, System.currentTimeMillis());
                        notification.setLatestEventInfo(getBaseContext(), "photo upload", message,
                                PendingIntent.getActivity(PhotoUploadService.this, 0,
                                        (Myfeedle.getPackageIntent(PhotoUploadService.this, About.class)), 0));
                        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID,
                                notification);
                        stopSelfResult(mStartId);
                    }

                }).execute(intent.getStringExtra(Accounts.TOKEN), intent.getStringExtra(Statuses.MESSAGE),
                        intent.getStringExtra(Widgets.INSTANT_UPLOAD), place, tags);
            }
        }
    }
}

From source file:com.etime.TimeAlarmService.java

/**
 * Send a notification to the user with the message 'notificationString'
 * @param notifcationString    The message to notify the user with.
 *//*from  ww  w  .j  av a 2 s. c o m*/
private void notification(String notifcationString) {
    CharSequence from = "ETime";
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    Notification notif = new Notification(R.drawable.icon, notifcationString, System.currentTimeMillis());

    notif.flags |= Notification.DEFAULT_LIGHTS;
    notif.defaults |= Notification.DEFAULT_VIBRATE;

    notif.setLatestEventInfo(this, from, notifcationString, contentIntent);
    nm.notify("ETime", APP_ID, notif);
}

From source file:com.unlockdisk.android.opengl.MainGLActivity.java

public void generateNotification(int id, String notificationTitle, String notificationMessage) {
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.ic_launcher, "A New Message!",
            System.currentTimeMillis());

    Intent notificationIntent = new Intent(this, MainGLActivity.class);
    // Intent notificationIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com"));

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

    notification.setLatestEventInfo(MainGLActivity.this, notificationTitle, notificationMessage, pendingIntent);

    //Setting Notification Flags
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.flags |= Notification.DEFAULT_SOUND;
    //Adding the Custom Sound
    notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
    String uri = "android.resource://org.openmobster.notify.android.app/"
            + MainGLActivity.this.findSoundId(MainGLActivity.this, "beep");
    notification.sound = Uri.parse(uri);
    //  notification.sound = Uri.fromFile(new File(R.raw.a));
    notificationManager.notify(id, notification);
}

From source file:org.liberty.android.fantastischmemo.service.AnyMemoService.java

@SuppressWarnings("deprecation")
private void showNotification() {
    try {//  w  w w.ja  va  2  s.  c  om
        DatabaseInfo dbInfo = new DatabaseInfo(this);
        if (dbInfo.getRevCount() < 10) {
            return;
        }
        Intent myIntent = new Intent(this, AnyMemo.class);
        myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Notification notification = new Notification(R.drawable.anymemo_notification_icon,
                getString(R.string.app_name), System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        PendingIntent pIntent = PendingIntent.getActivity(this, NOTIFICATION_REQ, myIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        notification.setLatestEventInfo(this, dbInfo.getDbName(),
                getString(R.string.stat_scheduled) + " " + dbInfo.getRevCount(), pIntent);

        notificationManager.notify(NOTIFICATION_ID, notification);
        Log.v(TAG, "Notification Invoked!");
    } catch (Exception e) {
        /* Do not show notification when AnyMemo can not
         * fetch the into
         */
    }
}

From source file:org.rti.rcd.ict.lgug.C2DMReceiver.java

@Override
protected void onMessage(Context context, Intent intent) {
    //String accountName = intent.getExtras().getString(Config.C2DM_ACCOUNT_EXTRA);
    String accountName = intent.getStringExtra("account");
    String message = intent.getExtras().getString(Config.C2DM_MESSAGE_EXTRA);
    Log.d(TAG, "Messaging request received for account " + accountName);
    //        CoconutActivity c = CoconutActivity.getRef();
    //        c.displayMessage( message );
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    int icon = R.drawable.icon;
    CharSequence tickerText = "Olutindo";
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;

    notification.flags = Notification.FLAG_AUTO_CANCEL;

    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0xff00ff00;//w  w  w.ja  va 2  s  . c om
    notification.ledOnMS = 300;
    notification.ledOffMS = 1000;

    //Context context = getApplicationContext();
    Log.d(TAG, "Triggering once_off replication upon receipt of notification: " + message);
    Properties properties = new Properties();
    try {
        InputStream rawResource = getResources().openRawResource(R.raw.coconut);
        properties.load(rawResource);
        System.out.println("The properties are now loaded");
        System.out.println("properties: " + properties);
    } catch (Resources.NotFoundException e) {
        System.err.println("Did not find raw resource: " + e);
    } catch (IOException e) {
        System.err.println("Failed to open microlog property file");
    }
    String localDb = "http://localhost:" + properties.getProperty("local_couch_app_port") + "/"
            + properties.getProperty("app_db");
    Log.d(TAG, "localDb: " + localDb);

    //       String localReplicationDbUrl = "http://localhost:" + properties.getProperty("local_couch_app_port") +"/_replicate";
    //       String replicationMasterUrl = "http://" + properties.getProperty("master_server") + "/coconut";
    //       String replicationDataFromMaster = "{\"_id\": \"once_off_from_master\",\"target\":\"" + localDb + "\",\"source\":\"" + replicationMasterUrl + "\"}";
    //       String replicationDataToMaster = "{\"_id\": \"once_off_to_master\",\"target\":\"" + replicationMasterUrl + "\",\"source\":\"" + localDb + "\"}";
    //    
    //       try {
    //         HTTPRequest.post(localReplicationDbUrl, replicationDataFromMaster);
    //      } catch (JSONException e) {
    //         Log.d(TAG, "Problem installing replication target FromMaster. replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage());
    //         e.printStackTrace();
    //      } catch (ConnectException e) {
    //         Log.d(TAG, "Unable to connect to replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage());
    //      }
    //       try {
    //          HTTPRequest.post(localReplicationDbUrl, replicationDataToMaster);
    //       } catch (JSONException e) {
    //          Log.d(TAG, "Problem installing replication target ToMaster. replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage());
    //          e.printStackTrace();
    //       } catch (ConnectException e) {
    //          Log.d(TAG, "Unable to connect to replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage());
    //      }
    CharSequence contentTitle = "New Olutindo Message";
    //CharSequence contentText = "Hello World!";
    Intent notificationIntent = new Intent(this, CoconutActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

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

    mNotificationManager.notify(HELLO_ID, notification);
}

From source file:com.tcnr14.example.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 */// www  . ja v a  2  s  . c  om
private static void generateNotification(Context context, String 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, MainActivity.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:vcc.mobile.pega.gcm.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*  ww w . j a  va  2 s  . co m*/
@SuppressWarnings("deprecation")
private static void generateNotification(Context context, String... message) {
    String content = message[0];
    String source = message[1];
    String id = message[2];
    int idInt = 0;
    try {
        idInt = Integer.valueOf(id);
    } catch (Exception e) {
        e.printStackTrace();
    }

    int icon = R.drawable.icon_launcher;
    long when = System.currentTimeMillis();
    String title = context.getString(R.string.app_name);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, content, when);

    Intent notificationIntent = new Intent(context, NotificationActivity.class);
    // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
    // Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationIntent.putExtra(NotificationActivity.PARAM_SOURCE, source);
    notificationIntent.putExtra(NotificationActivity.PARAM_ID, id);

    PendingIntent intent = PendingIntent.getActivity(context, idInt, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, content, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(idInt, notification);
}