Example usage for android.app Notification DEFAULT_SOUND

List of usage examples for android.app Notification DEFAULT_SOUND

Introduction

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

Prototype

int DEFAULT_SOUND

To view the source code for android.app Notification DEFAULT_SOUND.

Click Source Link

Document

Use the default notification sound.

Usage

From source file:com.example.mego.adas.utils.NotificationUtils.java

/**
 * Helper Method to create and display waring notification
 *
 * @param context//from   w  w w. j  a  va 2 s .c o m
 * @param notificationBody the content text with in notification
 */
public static void showWarningNotification(Context context, String notificationBody) {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(largeIcon(context)).setContentTitle(context.getString(R.string.notification_waring))
            .setContentText(notificationBody)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBody))
            .setDefaults(Notification.DEFAULT_VIBRATE).setDefaults(Notification.DEFAULT_SOUND)
            .setContentIntent(contentIntent(context)).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
    }

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(ADAS_WARNING_NOTIFICATION_ID, notificationBuilder.build());
}

From source file:com.amlcurran.messages.notifications.NotificationBuilder.java

NotificationCompat.Builder getDefaultBuilder(boolean shouldSoundAndVibrate) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context)
            .setContentIntent(notificationIntentFactory.createLaunchActivityIntent()).setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_notify_sms).setCategory(NotificationCompat.CATEGORY_MESSAGE)
            .setColor(notificationColor).setDefaults(Notification.DEFAULT_LIGHTS);

    if (shouldSoundAndVibrate) {
        if (preferenceStore.hasRingtoneUri()) {
            builder.setSound(Uri.parse(preferenceStore.getRingtoneUri().toString()));
        } else {/*w  w w.ja v a  2s  . c  o m*/
            builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS);
        }
        builder.setVibrate(VIBRATE_PATTERN);
    }

    return builder;
}

From source file:com.andrada.sitracker.tasks.receivers.UpdateStatusNotificationReceiver.java

private void sendNotification(int number, List<String> updatedAuthorNames, @NotNull Context context) {

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    int maxLines = 4;
    if (updatedAuthorNames.size() < maxLines) {
        maxLines = updatedAuthorNames.size();
    }/*w w  w  .  j  av a2  s . c  o  m*/
    for (int i = 0; i < maxLines; i++) {
        inboxStyle.addLine(updatedAuthorNames.get(i));
    }
    if (updatedAuthorNames.size() > 4) {
        inboxStyle.setSummaryText(
                context.getString(R.string.notification_more_summary, updatedAuthorNames.size() - 4));
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.notification)
            .setContentTitle(context.getResources().getString(R.string.notification_title))
            .setContentText(context.getResources().getQuantityString(R.plurals.authors_updated, number, number))
            .setAutoCancel(true).setOnlyAlertOnce(true)
            .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND).setNumber(number)
            .setStyle(inboxStyle);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, HomeActivity_.class);
    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(HomeActivity_.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(UPDATE_SUCCESS_NOTIFICATION_ID, mBuilder.build());
}

From source file:zemin.notification.NotificationRemoteCallback.java

/**
 * Create a new {@link android.app.Notification} object.
 *
 * @param remote//from  w  w  w.j  av  a  2 s. c  o m
 * @param entry
 * @param layoutId
 * @return Notification
 */
public Notification makeStatusBarNotification(NotificationRemote remote, NotificationEntry entry,
        int layoutId) {

    final int entryId = entry.ID;
    final CharSequence title = entry.title;
    final CharSequence text = entry.text;
    CharSequence tickerText = entry.tickerText;

    NotificationCompat.Builder builder = new NotificationCompat.Builder(remote.getContext());
    if (entry.smallIconRes > 0) {
        builder.setSmallIcon(entry.smallIconRes);
    } else {
        Log.w(TAG, "***************** small icon not set.");
    }

    if (tickerText == null) {
        Log.w(TAG, "***************** tickerText not set.");
        tickerText = title + ": " + text;
    }

    if (entry.largeIconBitmap != null) {
        builder.setLargeIcon(entry.largeIconBitmap);
    }

    builder.setTicker(tickerText);
    builder.setContentTitle(title);
    builder.setContentText(text);
    builder.setShowWhen(entry.showWhen);

    if (entry.showWhen && entry.whenLong > 0) {
        builder.setWhen(entry.whenLong);
    }

    PendingIntent deleteIntent = remote.getDeleteIntent(entryId);
    builder.setDeleteIntent(deleteIntent);

    PendingIntent contentIntent = remote.getContentIntent(entryId, entry.activityClass, entry.extra,
            entry.autoCancel);
    builder.setContentIntent(contentIntent);
    builder.setAutoCancel(entry.autoCancel);

    builder.setOngoing(entry.ongoing);

    if (entry.useSystemEffect) {
        int defaults = 0;
        if (entry.playRingtone) {
            if (entry.ringtoneUri != null) {
                builder.setSound(entry.ringtoneUri);
            } else {
                defaults |= Notification.DEFAULT_SOUND;
            }
        }

        if (entry.useVibration) {
            if (entry.vibratePattern != null) {
                builder.setVibrate(entry.vibratePattern);
            } else {
                defaults |= Notification.DEFAULT_VIBRATE;
            }
        }

        if (defaults != 0) {
            builder.setDefaults(defaults);
        }
    }

    return builder.build();
}

From source file:com.example.google.location.GeoFenceIntentReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (!intent.getAction().equals(LocationActivity.ACTION_GEOFENCE)) {
        return;/*from  www.  j  av a2  s.  com*/
    }
    boolean hasError = LocationClient.hasError(intent);
    if (hasError) {
        // This is an intent that indicates error.
        Log.v(LocationActivity.TAG, "hasError == true");
        return;
    }
    int transition = LocationClient.getGeofenceTransition(intent);
    List<Geofence> list = LocationClient.getTriggeringGeofences(intent);
    if (transition == -1 || list == null) {
        Log.v(LocationActivity.TAG, "list == null OR " + transition);
        return;
    }
    Log.v(LocationActivity.TAG, "geo_fence transition == " + transition);
    ArrayList<String> requestIds = new ArrayList<String>();
    for (Geofence geoFence : list) {
        requestIds.add(geoFence.getRequestId());
    }
    Bundle bundle = new Bundle();
    bundle.putStringArrayList("request_ids", requestIds);

    // Create a new intent and set extra arguments which contain the
    // request_ids of geofences triggered and corresponding transition.
    Intent myIntent = new Intent(context, LocationActivity.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    myIntent.putExtra("RECEIVER_STARTED", true);
    myIntent.putExtra("geo_fences", bundle);
    myIntent.putExtra("transition", transition);

    if (LocationActivity.isAppForeground) {
        context.startActivity(myIntent);
    } else {
        // Send a notification when the app is in the background
        String transitionText = transition == Geofence.GEOFENCE_TRANSITION_ENTER
                ? context.getResources().getString(R.string.enter)
                : context.getResources().getString(R.string.leave);

        Bitmap genFenceBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.geofence);

        Notification n = new NotificationCompat.Builder(context)
                .setContentTitle(context.getResources().getString(R.string.app_name))
                .setSmallIcon(R.drawable.ic_notify).setDefaults(Notification.DEFAULT_SOUND)
                .setStyle(new NotificationCompat.BigPictureStyle()
                        .bigPicture(genFenceBitmap).setSummaryText(transitionText))
                .setContentText(transitionText)
                .setContentIntent(
                        PendingIntent.getActivity(context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT))
                .setAutoCancel(true).build();

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.notify(1, n);
    }
}

From source file:com.ubikod.urbantag.NotificationHelper.java

/**
 * Notify a new content(place or event)//  ww w. jav a2s .  c  o  m
 * @param contentId Id of content
 * @param content Content name
 * @param placeName Place name it will happend
 * @param type type of notification
 */
private void notify(int contentId, String content, String placeName, int type) {

    String title = content;
    String text = placeName;
    int icon = content_icon;
    if (type == NEW_PLACE_NOTIF) {
        title = placeName;
        text = mContext.getResources().getString(R.string.new_place);
        icon = place_icon;
    }
    /* Modify intent to transmit id */
    Intent intent;
    intent = new Intent(mContext, ContentViewerActivity.class);
    intent.putExtra(ContentViewerActivity.CONTENT_ID, contentId);

    /* Add the from notification extra info and create the pending intent */
    intent.putExtra(FROM_NOTIFICATION, type);
    PendingIntent activity = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    /* Create notification */
    Notification newNotification = new NotificationCompat.Builder(mContext).setSmallIcon(icon)
            .setContentText(text).setContentTitle(title).setContentIntent(activity).setTicker(title)
            .getNotification();

    // newNotification.contentView = contentView;
    newNotification.flags |= Notification.FLAG_AUTO_CANCEL;
    newNotification.defaults |= Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;

    /* notify */
    mNotificationManager.notify(type, newNotification);
}

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;/*from  w w  w. ja v a 2s. c o  m*/
    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:org.androidpn.client.Notifier.java

public void notify(String notificationId, String apiKey, String title, String message, String uri,
        String imageUrl) {//from w ww  .  j  a  va 2  s.c o  m
    Log.d(LOGTAG, "notify()...");

    Log.d(LOGTAG, "notificationId=" + notificationId);
    Log.d(LOGTAG, "notificationApiKey=" + apiKey);
    Log.d(LOGTAG, "notificationTitle=" + title);
    Log.d(LOGTAG, "notificationMessage=" + message);
    Log.d(LOGTAG, "notificationUri=" + uri);

    if (isNotificationEnabled()) {
        // Show the toast
        if (isNotificationToastEnabled()) {
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
        }
        mBuilder.setWhen(System.currentTimeMillis())//?
                .setPriority(Notification.PRIORITY_DEFAULT)//
                //            .setAutoCancel(true)//?????
                .setOngoing(false)//ture???,??(?)???,?(,??,)
                .setDefaults(Notification.DEFAULT_VIBRATE)//???????defaults??
                //Notification.DEFAULT_ALL  Notification.DEFAULT_SOUND  // requires VIBRATE permission
                .setSmallIcon(getNotificationIcon());

        mBuilder.setAutoCancel(true)//?
                .setContentTitle(title).setContentText(message).setTicker(message);
        // Notification
        if (isNotificationSoundEnabled()) {
            mBuilder.setDefaults(Notification.DEFAULT_SOUND);
        }
        if (isNotificationVibrateEnabled()) {
            mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        }
        mBuilder.setOnlyAlertOnce(true);

        //            Intent intent;
        //            if (uri != null
        //                    && uri.length() > 0
        //                    && (uri.startsWith("http:") || uri.startsWith("https:")
        //                            || uri.startsWith("tel:") || uri.startsWith("geo:"))) {
        //                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        //            } else {
        //                String callbackActivityPackageName = sharedPrefs.getString(
        //                        Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, "");
        //                String callbackActivityClassName = sharedPrefs.getString(
        //                        Constants.CALLBACK_ACTIVITY_CLASS_NAME, "");
        //                intent = new Intent().setClassName(callbackActivityPackageName,
        //                        callbackActivityClassName);
        //                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            }

        Intent intent = new Intent(context, NotificationDetailsActivity.class);
        intent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        intent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        intent.putExtra(Constants.NOTIFICATION_TITLE, title);
        intent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
        intent.putExtra(Constants.NOTIFICATION_URI, uri);
        intent.putExtra(Constants.NOTIFICATION_IMAGE_URL, imageUrl);

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent contentIntent = PendingIntent.getActivity(context, random.nextInt(), intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(contentIntent);
        notificationManager.notify(random.nextInt(), mBuilder.build());

    } else {
        Log.w(LOGTAG, "Notificaitons disabled.");
    }
}

From source file:org.enbyted.android.zseinfo.view.NotificationManager.java

public static void notifyNewReplacements() {
    if (builderNewReplacements == null) {
        builderNewReplacements = new NotificationCompat.Builder(getContext());
        builderNewReplacements.setSmallIcon(R.drawable.ic_launcher);
    }//ww w  .j a va 2 s  .  co  m

    builderNewReplacements.setContentTitle("Nowe zastpstwa!");
    builderNewReplacements.setContentText("Zastpstwa na jutro s ju dostpne!");
    builderNewReplacements.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);

    Intent resultIntent = new Intent(getContext(), MainActivity.class);
    resultIntent.putExtra("tab", "TAB_REPLACEMENTS");
    resultIntent.putExtra("my_class", false);
    resultIntent.putExtra("TYPE", ID_NEW_REPLACEMENT);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext());

    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    builderNewReplacements.setContentIntent(resultPendingIntent);

    getManager().notify(ID_NEW_REPLACEMENT, builderNewReplacements.build());
}

From source file:com.franmontiel.fcmnotificationhandler.RemoteMessageToNotificationMapper.java

/**
 * Map a FCM remote message into a System Notification Builder mimicking the default notification format and behavior applied when the app is in background
 *
 * @param remoteMessage FCM remote message
 * @return The notification builder configured with the notification information of the remote message
 * @throws IllegalArgumentException if the remote message does not contain notification information
 *///from  ww  w .  j av a 2s. com
public NotificationCompat.Builder mapToNotificationBuilder(RemoteMessage remoteMessage)
        throws IllegalArgumentException {
    RemoteMessage.Notification fcmNotification = remoteMessage.getNotification();

    if (fcmNotification == null)
        throw new IllegalArgumentException(ErrorMessages.NO_NOTIFICATION_MSG);

    String body = parseBody(fcmNotification);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle(parseTitle(fcmNotification)).setContentText(body)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(body))
            .setSmallIcon(parseIcon(fcmNotification)).setAutoCancel(true);

    Integer color;
    if ((color = parseColor(fcmNotification)) != null) {
        builder.setColor(color);
    }

    int soundFileResId;
    if (fcmNotification.getSound() != null && !fcmNotification.getSound().equals("default")
            && (soundFileResId = context.getResources().getIdentifier(fcmNotification.getSound(), "raw",
                    context.getPackageName())) != 0) {

        builder.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + soundFileResId));

    } else if (fcmNotification.getSound() != null) {
        builder.setDefaults(Notification.DEFAULT_SOUND);
    }

    builder.setContentIntent(createNotificationPendingItent(remoteMessage));

    return builder;
}