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:ro.weednet.contactssync.syncadapter.SyncAdapter.java

@SuppressWarnings("deprecation")
public void showNotificationMessage(String tickerText, String title, String desc) {
    if (!ContactsSync.getInstance().getShowNotifications()) {
        return;//from  w w  w  .  j  av a 2  s  .  c o  m
    }

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

    Notification notification = new Notification(R.drawable.icon, tickerText, System.currentTimeMillis());
    Context context = ContactsSync.getInstance().getApplicationContext();
    Intent notificationIntent = new Intent(context, Preferences.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    notification.setLatestEventInfo(context, title, desc, contentIntent);
    mNotificationManager.notify(1, notification);
}

From source file:com.pixmob.r2droid.DeviceRegistrationService.java

private void onC2DMRegistered() {
    final String regId = Preferences.getRegistrationId(getApplicationContext());
    if (DEV) {/*from   ww w  .java 2 s .  com*/
        Log.i(TAG, "Device registered to C2DM with id " + regId);
    }

    int event = CONNECTED_EVENT;
    String error = null;

    // TODO get device name
    final String deviceName = "Unknown Device";
    try {
        final String url = "https://r2droidhq.appspot.com/api/1/register?regid=" + urlEncode(regId) + "&name="
                + urlEncode(deviceName);
        if (DEV) {
            Log.d(TAG, "Register URL: " + url);
        }
        final HttpGet req = new HttpGet(url);
        if (!configureClient()) {
            event = DISCONNECTED_EVENT;
            error = AUTH_FAILED_ERROR;
        } else {
            final int statusCode = gaeClient.execute(req).getStatusLine().getStatusCode();
            if (statusCode != HTTP_SC_OK) {
                if (DEV) {
                    Log.w(TAG, "Failed to register device: statusCode=" + statusCode);
                }
                event = DISCONNECTED_EVENT;
                error = DEVICE_REGISTRATION_ERROR;
            }
        }
    } catch (AppEngineAuthenticationException e) {
        if (e.isAuthenticationPending()) {
            if (DEV) {
                Log.i(TAG, "User must give permission to use authentication token: " + "registration aborted");
            }
            event = DISCONNECTED_EVENT;
            error = AUTH_PENDING;
        } else {
            if (DEV) {
                Log.w(TAG, "Authentication error", e);
            }
            event = DISCONNECTED_EVENT;
            error = AUTH_FAILED_ERROR;
        }
    } catch (IOException e) {
        if (DEV) {
            Log.w(TAG, "Network error", e);
        }
        event = DISCONNECTED_EVENT;
        error = NETWORK_ERROR;
    } catch (Exception e) {
        Log.wtf(TAG, "Unexpected error", e);
        event = DISCONNECTED_EVENT;
        error = DEVICE_REGISTRATION_ERROR;
    }

    fireEvent(event, error);

    int ticketRes = R.string.device_is_online;
    if (event != CONNECTED_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.pixmob.r2droid.DeviceRegistrationService.java

private void onC2DMUnregistered() {
    final String regId = Preferences.getRegistrationId(getApplicationContext());
    if (DEV) {//from   w w w  .  j  av  a 2 s. com
        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:org.liberty.android.fantastischmemo.service.AnyMemoService.java

@SuppressWarnings("deprecation")
private void showNotification() {
    try {//from w w w  .  j av  a  2  s . c o  m
        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:be.vbsteven.bmtodesk.BackgroundSharingService.java

/**
 * shows notification when the sending failed
 *
 * @param message/*  w w w . j a  v a  2 s . c  o m*/
 */
private void showFailedSend(String message) {
    Notification n = new Notification(R.drawable.icon, "Sending bookmark failed", System.currentTimeMillis());
    n.flags = Notification.FLAG_AUTO_CANCEL;
    Intent i = new Intent(this, ShareActivity.class);
    i.putExtra(Global.EXTRA_TITLE, title);
    i.putExtra(Global.EXTRA_URL, url);
    PendingIntent p = PendingIntent.getActivity(this, 4, i, 0);
    n.setLatestEventInfo(this, "Sending bookmark failed", message, p);
    nManager.notify(3, n);
}

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:com.mutu.gpstracker.streaming.CustomUpload.java

private void notifyError(Context context, Exception e) {
    Log.e(TAG, "Custom upload failed", e);
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

    int icon = R.drawable.ic_maps_indicator_current_position;
    CharSequence tickerText = context.getText(R.string.customupload_failed);
    long when = System.currentTimeMillis();
    Notification notification = new Notification(icon, tickerText, when);

    Context appContext = context.getApplicationContext();
    CharSequence contentTitle = tickerText;
    CharSequence contentText = e.getMessage();
    Intent notificationIntent = new Intent(context, CustomUpload.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(appContext, contentTitle, contentText, contentIntent);
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    mNotificationManager.notify(NOTIFICATION_ID, notification);
}

From source file:org.klnusbaum.udj.network.PlaylistSyncService.java

private void alertException(Account account, Intent originalIntent, int titleRes, int contentRes,
        int notificationId) {

    PendingIntent pe = PendingIntent.getService(this, 0, originalIntent, 0);
    Notification notification = new Notification(R.drawable.udjlauncher, "", System.currentTimeMillis());
    notification.setLatestEventInfo(this, getString(titleRes), getString(contentRes), pe);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(notificationId, notification);
}

From source file:com.maass.android.imgur_uploader.ImgurUpload.java

private void handleResponse() {
    Log.i(this.getClass().getName(), "in handleResponse()");
    // close progress notification
    mNotificationManager.cancel(NOTIFICATION_ID);

    String notificationMessage = getString(R.string.upload_success);

    // notification intent with result
    final Intent notificationIntent = new Intent(getBaseContext(), ImageDetails.class);

    if (mImgurResponse == null) {
        notificationMessage = getString(R.string.connection_failed);
    } else if (mImgurResponse.get("error") != null) {
        notificationMessage = getString(R.string.unknown_error) + mImgurResponse.get("error");
    } else {/*from   w ww.  ja  v a2  s  . c  om*/
        // create thumbnail
        if (mImgurResponse.get("image_hash").length() > 0) {
            createThumbnail(imageLocation);
        }

        // store result in database
        final HistoryDatabase histData = new HistoryDatabase(getBaseContext());
        final SQLiteDatabase data = histData.getWritableDatabase();

        final HashMap<String, String> dataToSave = new HashMap<String, String>();
        dataToSave.put("delete_hash", mImgurResponse.get("delete_hash"));
        dataToSave.put("image_url", mImgurResponse.get("original"));
        final Uri imageUri = Uri
                .parse(getFilesDir() + "/" + mImgurResponse.get("image_hash") + THUMBNAIL_POSTFIX);
        dataToSave.put("local_thumbnail", imageUri.toString());
        dataToSave.put("upload_time", "" + System.currentTimeMillis());

        for (final Map.Entry<String, String> entry : dataToSave.entrySet()) {
            final ContentValues content = new ContentValues();
            content.put("hash", mImgurResponse.get("image_hash"));
            content.put("key", entry.getKey());
            content.put("value", entry.getValue());
            data.insert("imgur_history", null, content);
        }

        //set intent to go to image details
        notificationIntent.putExtra("hash", mImgurResponse.get("image_hash"));
        notificationIntent.putExtra("image_url", mImgurResponse.get("original"));
        notificationIntent.putExtra("delete_hash", mImgurResponse.get("delete_hash"));
        notificationIntent.putExtra("local_thumbnail", imageUri.toString());

        data.close();
        histData.close();

        // if the main activity is already open then refresh the gridview
        sendBroadcast(new Intent(BROADCAST_ACTION));
    }

    //assemble notification
    final Notification notification = new Notification(R.drawable.icon, notificationMessage,
            System.currentTimeMillis());
    notification.setLatestEventInfo(this, getString(R.string.app_name), notificationMessage, PendingIntent
            .getActivity(getBaseContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT));
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(NOTIFICATION_ID, 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);//  w  w w .j av a  2s .  c om

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