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:ro.astazi.andrapp.GcmIntentService.java

private void sendNotification(String title, String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.putExtra("NotificationTitle", title);
    notificationIntent.putExtra("NotificationMessage", msg);
    Log.i(TAG, "NotificationMessage=" + msg);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    //PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);       

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setDefaults(/*from   w w  w.j a va  2  s.co m*/
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
            .setTicker(title).setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(title).setAutoCancel(true)
    //.setContentText("B" + title)
    ;

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    /*NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this.getApplicationContext());
    notificationBuilder.setContentTitle("GCM Notification");
     notificationBuilder.setContentText(msg);
     notificationBuilder.setTicker("New GCM Notification");
     notificationBuilder.setWhen(System.currentTimeMillis());
     notificationBuilder.setSmallIcon(R.drawable.ic_stat_gcm);
             
     Intent notificationIntent = new Intent(this.getApplicationContext(), MainActivity.class);
     notificationIntent.putExtra("gabor", msg);
     PendingIntent contentIntent = PendingIntent.getActivity(this.getApplicationContext(), 1,notificationIntent, 0);
     notificationBuilder.setContentIntent(contentIntent);
     notificationBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
             
     mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
     Notification notification = notificationBuilder.build();
     notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
     mNotificationManager.notify(NOTIFICATION_ID, notification);*/
}

From source file:com.projects.utils.GcmIntentService.java

private void sendNotification(String msg, Bundle extras) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent thisintent = new Intent(this, SyncActivity.class);
    thisintent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            // .setSmallIcon(R.drawable.ic_stat_gcm)
            .setContentTitle("Treckon").setSmallIcon(R.drawable.ic_launcher)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setAutoCancel(true);/*w  ww  .  j  a  v a 2s. co  m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, thisintent,
                PendingIntent.FLAG_UPDATE_CURRENT, extras);
        mBuilder.setContentIntent(contentIntent);
    }

    Notification nf = mBuilder.build();
    nf.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
    mNotificationManager.notify(NOTIFICATION_ID, nf);

}

From source file:com.bevyios.gcm.BevyGcmListenerService.java

private void sendNotification(Bundle bundle) {
    Resources resources = getApplication().getResources();
    String packageName = getApplication().getPackageName();
    Class intentClass = getMainActivityClass();
    if (intentClass == null) {
        return;//  w  w w.j  av  a2 s. co  m
    }

    if (applicationIsRunning()) {
        Intent i = new Intent("BevyGCMReceiveNotification");
        i.putExtra("bundle", bundle);
        sendBroadcast(i);
        return;
    }

    int resourceId = resources.getIdentifier(bundle.getString("largeIcon"), "mipmap", packageName);

    Intent intent = new Intent(this, intentClass);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    //Bitmap largeIcon = BitmapFactory.decodeResource(resources, resourceId);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            //.setLargeIcon(largeIcon)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("title").setContentText("content")
            .setAutoCancel(false).setSound(defaultSoundUri)
            //.setTicker(bundle.getString("ticker"))
            .setCategory(NotificationCompat.CATEGORY_CALL).setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
            .setPriority(NotificationCompat.PRIORITY_HIGH).setContentIntent(pendingIntent);

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

    Notification notif = notificationBuilder.build();
    notif.defaults |= Notification.DEFAULT_VIBRATE;
    notif.defaults |= Notification.DEFAULT_SOUND;
    notif.defaults |= Notification.DEFAULT_LIGHTS;

    notificationManager.notify(0, notif);
}

From source file:com.lhtechnologies.DoorApp.AuthenticatedReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.e(this.getClass().getSimpleName(), "Received Broadcast!");
    if (intent.getAction().equals(AuthenticationFinishedBroadCast)) {
        String reason;//from w w  w.j  ava2s .  co  m
        mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        //Start the notification
        NotificationCompat.Builder notiBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_launcher).setContentTitle(context.getString(R.string.app_name));

        if (intent.hasExtra(AuthenticatorReturnCode)) {
            String returnCode = intent.getStringExtra(AuthenticatorReturnCode);
            if (returnCode.equals(ServerReturnSuccess)) {
                if (intent.hasExtra(FlatDoor)) {
                    notiBuilder.setContentText(context.getString(R.string.StatusBuzzing)).setOngoing(true)
                            .setDefaults(Notification.FLAG_SHOW_LIGHTS).setLights(0xFF00FF00, 1000, 1000);

                    mNotificationManager.notify(BuzzingNotificationId, notiBuilder.build());

                    class RemoveBuzzingNotification extends TimerTask {
                        public void run() {
                            mNotificationManager.cancel(BuzzingNotificationId);
                            timer.cancel(); //Terminate the timer thread
                        }
                    }

                    timer = new Timer();
                    timer.schedule(new RemoveBuzzingNotification(), buzzerTimeout * 1000);
                } else {
                    notiBuilder.setContentText(context.getString(R.string.StatusAuthenticated)).setOngoing(true)
                            .setDefaults(Notification.FLAG_SHOW_LIGHTS).setLights(0xFF00FF00, 1000, 1000);

                    mNotificationManager.notify(SuccessNotificationId, notiBuilder.build());

                    class RemoveSuccessNotification extends TimerTask {
                        public void run() {
                            mNotificationManager.cancel(SuccessNotificationId);
                            timer.cancel(); //Terminate the timer thread
                        }
                    }

                    timer = new Timer();
                    timer.schedule(new RemoveSuccessNotification(), timeout * 1000);
                }
            } else {
                String result = intent.getStringExtra(AuthenticatorReturnCode);
                if (result.equals(ServerReturnAuthFailure))
                    reason = context.getString(R.string.AuthFailureExplanantion);
                else if (result.equals(ServerReturnInternalFailure))
                    reason = context.getString(R.string.InternalFailureExplanantion);
                else if (result.equals(ServerReturnRegistrationStarted))
                    reason = context.getString(R.string.RegistrationStartedExplanantion);
                else if (result.equals(ServerReturnRegistrationPending))
                    reason = context.getString(R.string.RegistrationPendingExplanantion);
                else if (result.equals(ClientErrorUndefined))
                    reason = context.getString(R.string.ClientErrorExplanantion) + "\n"
                            + intent.getStringExtra(AuthenticatorErrorDescription);
                else if (result.equals(ClientErrorMalformedURL))
                    reason = context.getString(R.string.MalformedURLExplanation);
                else
                    reason = context.getString(R.string.UnknownErrorExplanation);

                notiBuilder
                        .setContentText(reason).setOngoing(false).setDefaults(Notification.FLAG_SHOW_LIGHTS
                                | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                        .setLights(0xFFFF0000, 500, 500);

                // Creates an explicit intent for an Activity in your app
                Intent resultIntent = new Intent(context, MainActivity.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(MainActivity.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);
                notiBuilder.setContentIntent(resultPendingIntent);

                mNotificationManager.notify(FailureNotificationId, notiBuilder.build());
            }
        } else {
            reason = context.getString(R.string.AuthFailureExplanantion) + "\n" + "NO_EXTRA";

            notiBuilder
                    .setContentText(reason).setOngoing(false).setDefaults(Notification.FLAG_SHOW_LIGHTS
                            | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                    .setLights(0xFFFF0000, 500, 500);

            // Creates an explicit intent for an Activity in your app
            Intent resultIntent = new Intent(context, MainActivity.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(MainActivity.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);
            notiBuilder.setContentIntent(resultPendingIntent);

            mNotificationManager.notify(FailureNotificationId, notiBuilder.build());
        }
        abortBroadcast();
    }
}

From source file:com.rocketsingh.biker.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from  w  w  w  .  j a  v a 2  s.com*/
public 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, MapActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // 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,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();

}

From source file:jp.co.ipublishing.esnavi.impl.gcm.GcmIntentService.java

/**
 * Notification??//  www.j  a  v  a2s.  co m
 *
 * @param alert 
 */
private void sendNotification(@NonNull Alert alert) {
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    final Intent resultIntent = new Intent(this, MapActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent contentIntent = PendingIntent.getActivity(this, 1, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final Notification.Builder builder = new Notification.Builder(this).setWhen(System.currentTimeMillis())
            .setContentIntent(contentIntent)
            .setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS)
            .setAutoCancel(true).setTicker(alert.getHeadlineBody()).setContentText(alert.getHeadlineBody());

    onPreSendNotification(builder, alert);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notificationManager.notify(NOTIFICATION_ID, builder.build());
    } else {
        notificationManager.notify(NOTIFICATION_ID, builder.getNotification());
    }
}

From source file:com.cellasoft.univrapp.gcm.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///  ww w.  jav a2s  .  c  om
private void displayNotification(Context context, String message) {
    if (!Settings.isEnabledNotificationUnivrApp()) {
        return;
    }

    LOGI(TAG, "displayNotification: " + message);
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    long[] vibraPattern = { 0, 500, 250, 500 };
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(
            Config.GCM_NOTIFICATION_ID,
            new NotificationCompat.Builder(context).setWhen(when).setSmallIcon(icon).setTicker(message)
                    .setContentTitle(context.getString(R.string.app_name)).setContentText(message)
                    .setContentIntent(PendingIntent.getActivity(context, 0,
                            new Intent(context, ChannelListActivity.class).setFlags(
                                    Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP),
                            0))
                    .setAutoCancel(true).setVibrate(vibraPattern).setDefaults(Notification.DEFAULT_SOUND)
                    .getNotification());
}

From source file:ws.logv.trainmonitor.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from   www  . j av  a 2  s .c  o m
public static void generateTrainLateNotification(Context context, String trainId, int delay) {

    SharedPreferences pref = context.getSharedPreferences(Constants.Settings.PERF, 0);

    if (!pref.getBoolean(Constants.Settings.NOTIFICATION_ON, true))
        return;

    int icon = R.drawable.notification;
    long when = System.currentTimeMillis();
    String message = context.getString(R.string.notification_message, trainId);
    String subText = context.getString(R.string.notification_detail, String.valueOf(delay));

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

    String title = context.getString(R.string.app_name);

    Intent notificationIntent = new Intent(context, Train.class);
    notificationIntent.putExtra(Constants.IntentsExtra.Train, trainId);
    // 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);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentText(message)
            .setContentTitle(title).setSmallIcon(icon).setWhen(when).setAutoCancel(true).setSubText(subText)
            .setContentIntent(intent);
    builder.setDefaults(
            Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS);

    Notification notification = builder.build();

    notificationManager.notify(trainId.hashCode(), notification);
}

From source file:pj.rozkladWKD.C2DMReceiver.java

public void showNotification(String ticker, String contentTitle, String contentText, PendingIntent intent,
        int number) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    int icon = R.drawable.ic_launcher_wkd;
    CharSequence tickerText = ticker;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    Context context = getApplicationContext();
    notification.number = Prefs.getNotificationMessageNextNumber(context);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    SharedPreferences prefs = Prefs.get(context);
    if (prefs.getBoolean(Prefs.NOTIFICATION_SOUND, true))
        notification.defaults |= Notification.DEFAULT_SOUND;
    if (prefs.getBoolean(Prefs.NOTIFICATION_VIBRATION, true))
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_LIGHTS;

    notification.setLatestEventInfo(context, contentTitle, contentText, intent);

    mNotificationManager.notify(NOTIFICATION_ID, notification);

}

From source file:com.ssm.broadcast.GcmIntentService.java

private void sendNotification(String msg) {

    //msg? ?? ? ?? ? ? ?.

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

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, DemoActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setTicker("PeopleTree").setContentTitle("PeopleTree")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            //.setWhen(System.currentTimeMillis())
            .setContentText(msg);/*from   ww  w. j  a v  a2  s  . c om*/

    AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

    /* Even if the mode is set to "Sound & Vibration" in the phone, 
     * the status code that getRingerMode() returns is RINGER_MODE_NORMAL.
     */
    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_VIBRATE:
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
        break;
    default:
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    }

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}