Example usage for android.app Notification setLatestEventInfo

List of usage examples for android.app Notification setLatestEventInfo

Introduction

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

Prototype

@Deprecated
public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText,
        PendingIntent contentIntent) 

Source Link

Document

Sets the #contentView field to be a view with the standard "Latest Event" layout.

Usage

From source file:jieehd.villain.updater.checkInBackground.java

public void notifyUser() {
    final NotificationManager nm;
    nm = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence from = "Villain Updater";
    CharSequence message = "New Updates!";
    PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, new Intent(), 0);
    Notification notif = new Notification(R.drawable.updates, "New updates!", System.currentTimeMillis());
    notif.setLatestEventInfo(mContext, from, message, contentIntent);
    nm.notify(1, notif);//w  w  w.j a  v  a2s  .com
}

From source file:net.ben.subsonic.androidapp.util.Util.java

public static void showPlayingNotification(final Context context, Handler handler, MusicDirectory.Entry song) {

    // Use the same text for the ticker and the expanded notification
    String title = song.getTitle();

    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.stat_notify_playing, title,
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, FragActivity.class),
            0);//from   ww w.j  a va 2 s  . co m

    String text = song.getArtist();
    notification.setLatestEventInfo(context, title, text, contentIntent);

    // Send the notification.
    handler.post(new Runnable() {
        @Override
        public void run() {
            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(Constants.NOTIFICATION_ID_PLAYING, notification);
        }
    });

    // Update widget
    DownloadService service = DownloadServiceImpl.getInstance();
    if (service != null) {
        SubsonicAppWidgetProvider.getInstance().notifyChange(context, service, true);
    }
}

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 . ja v  a  2s  .c o m*/
}

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 a v a  2 s  .c o  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, 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.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  . ja v a 2  s.c  o 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.networkmanagerapp.RestartWifi.java

/**
 * Notifies the user of progress in the system notification area
 *//*from   w ww  . j  a v a 2  s .c  o  m*/
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:com.jiee.smartplug.services.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  w  w  w  .  ja va2s . com*/
 */
private void sendNotification(String message) {

    System.out.println(message);

    NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notify = new Notification(R.drawable.svc_0_small_off, "title", System.currentTimeMillis());
    PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);

    notify.setLatestEventInfo(getApplicationContext(), "Subject", message, pending);
    notif.notify(0, notify);

    //        Intent intent = new Intent(this, MainActivity.class);
    //        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
    //                PendingIntent.FLAG_ONE_SHOT);
    //
    //        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    //        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
    //                .setSmallIcon(R.drawable.ic_stat_ic_notification)
    //                .setContentTitle("GCM Message")
    //                .setContentText(message)
    //                .setAutoCancel(true)
    //                .setSound(defaultSoundUri)
    //                .setContentIntent(pendingIntent);
    //
    //        NotificationManager notificationManager =
    //                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    //
    //        notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

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);
}

From source file:com.networkmanagerapp.SettingBackgroundUploader.java

/**
 * Create a notification to inform the user of progress in the system notification area
 *//*from  w  ww.j av  a 2s. c o  m*/
private void showNotification() {
    CharSequence text = getText(R.string.upload_service_started);
    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.upload_service_started, notification);
}

From source file:org.transdroid.service.UpdateService.java

private void newNotification(String ticker, String title, String text, String downloadUrl, int notifyID) {

    // Use the alarm service settings for the notification sound/vibrate/colour
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    AlarmSettings settings = Preferences.readAlarmSettings(prefs);

    // Set up an intent that will initiate a download of the new version
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadUrl));

    // Create a new notification
    Notification newNotification = new Notification(R.drawable.icon_notification, ticker,
            System.currentTimeMillis());
    newNotification.flags = Notification.FLAG_AUTO_CANCEL;
    newNotification.setLatestEventInfo(getApplicationContext(), title, text,
            PendingIntent.getActivity(getApplicationContext(), notifyID, i, 0));

    // Get the system notification manager, if not done so previously
    if (notificationManager == null) {
        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    }// www .j av a  2s.c  om

    // If sound enabled add to notification
    if (settings.getAlarmPlaySound() && settings.getAlarmSoundURI() != null) {
        newNotification.sound = Uri.parse(settings.getAlarmSoundURI());
    }

    // If vibration enabled add to notification
    if (settings.getAlarmVibrate()) {
        newNotification.defaults = Notification.DEFAULT_VIBRATE;
    }

    // Add coloured light; defaults to 0xff7dbb21
    newNotification.ledARGB = settings.getAlarmColour();
    newNotification.ledOnMS = 600;
    newNotification.ledOffMS = 1000;
    newNotification.flags |= Notification.FLAG_SHOW_LIGHTS;

    // Send notification
    notificationManager.notify(notifyID, newNotification);

}