List of usage examples for android.app Notification DEFAULT_VIBRATE
int DEFAULT_VIBRATE
To view the source code for android.app Notification DEFAULT_VIBRATE.
Click Source Link
From source file:com.manuelmazzuola.speedtogglebluetooth.service.MonitorSpeed.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { running = Boolean.TRUE;/*from w w w .java2 s .com*/ lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); provider = lm.NETWORK_PROVIDER; oldLocation = lm.getLastKnownLocation(provider); IntentFilter filters = new IntentFilter(); // When to turn off bluetooth filters.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); // When hold bluetooth on filters.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); // When user directly turn on or off bluetooth filters.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); registerReceiver(bluetoothListener, filters); lm.requestLocationUpdates(provider, 45 * 1000, 0f, this); Intent stopIntent = new Intent(this, MainActivity.class); stopIntent.putExtra("close", "close"); PendingIntent stopPendingIntent = PendingIntent.getActivity(this, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder note = new NotificationCompat.Builder(getApplicationContext()) .setContentTitle(DEFAULT_TITLE).setContentText(DEFAULT_MESSAGE) .setDefaults(Notification.DEFAULT_VIBRATE).setAutoCancel(true).setContentIntent(stopPendingIntent) .setSmallIcon(R.drawable.ic_action_bluetooth); note.getNotification().flags |= Notification.FLAG_AUTO_CANCEL; Notification notification = note.build(); notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; startForeground(intentId, note.build()); return START_NOT_STICKY; }
From source file:com.moxtra.moxiechat.GcmIntentService.java
private void sendMoxtraNotification(String msg, Uri uri, Intent intent) { Log.d(TAG, "Got notification: msg = " + msg + ", uri = " + uri); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = MXNotificationManager.getMXNotificationIntent(this, intent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_mc_notification) .setContentTitle(getString(getApplicationInfo().labelRes)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setAutoCancel(true).setDefaults( Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); if (uri != null) { mBuilder.setSound(uri);/*from w w w. j a v a 2s.co m*/ } mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
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;//from w w w . j av a 2 s. c o 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.scoreflex.ScoreflexGcmClient.java
protected static Notification buildNotification(String text, Context context, int iconResource, PendingIntent pendingIntent) {/*from w ww . ja v a 2 s . c om*/ final PackageManager pm = context.getApplicationContext().getPackageManager(); ApplicationInfo ai; try { ai = pm.getApplicationInfo(context.getPackageName(), 0); } catch (final NameNotFoundException e) { ai = null; } final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)"); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setContentTitle(applicationName).setContentText(text).setSmallIcon(iconResource); mBuilder.setContentIntent(pendingIntent); Notification notification = mBuilder.build(); notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE; notification.flags = Notification.FLAG_AUTO_CANCEL; return 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 w w .j a v a 2 s .c o 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: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 .ja v a 2 s . c o 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:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java
private void buildPushNotification(Context context, Intent intent, PushDataInfo dataInfo) { String title = dataInfo.getTitle(); String body = dataInfo.getAlert(); String message = dataInfo.getPushDataString(); Builder builder = new Builder(context); builder.setAutoCancel(true);/* www .j a va 2s. co m*/ builder.setContentTitle(title); // builder.setContentText(body); // builder.setTicker(body); // ?? String[] remindType = dataInfo.getRemindType(); if (remindType != null) { if (remindType.length == 3) { builder.setDefaults(Notification.DEFAULT_ALL); } else { int defaults = 0; for (int i = 0; i < remindType.length; i++) { if ("sound".equalsIgnoreCase(remindType[i])) { defaults = Notification.DEFAULT_SOUND; continue; } if ("shake".equalsIgnoreCase(remindType[i])) { defaults = defaults | Notification.DEFAULT_VIBRATE; continue; } if ("breathe".equalsIgnoreCase(remindType[i])) { defaults = defaults | Notification.DEFAULT_LIGHTS; continue; } } builder.setDefaults(defaults); } } Resources res = context.getResources(); int icon = res.getIdentifier("icon", "drawable", intent.getPackage()); builder.setSmallIcon(icon); builder.setWhen(System.currentTimeMillis()); // String iconUrl = dataInfo.getIconUrl(); boolean isDefaultIcon = !TextUtils.isEmpty(iconUrl) && "default".equalsIgnoreCase(iconUrl); Bitmap bitmap = null; if (!isDefaultIcon) { bitmap = getIconBitmap(context, iconUrl); } String fontColor = dataInfo.getFontColor(); RemoteViews remoteViews = null; if (!TextUtils.isEmpty(fontColor)) { int color = BUtility.parseColor(fontColor); int alphaColor = parseAlphaColor(fontColor); remoteViews = new RemoteViews(intent.getPackage(), EUExUtil.getResLayoutID("push_notification_view")); // Title remoteViews.setTextViewText(EUExUtil.getResIdID("notification_title"), title); remoteViews.setTextColor(EUExUtil.getResIdID("notification_title"), color); // Body remoteViews.setTextViewText(EUExUtil.getResIdID("notification_body"), body); remoteViews.setTextColor(EUExUtil.getResIdID("notification_body"), alphaColor); // LargeIcon if (bitmap != null) { remoteViews.setImageViewBitmap(EUExUtil.getResIdID("notification_largeIcon"), bitmap); } else { remoteViews.setImageViewResource(EUExUtil.getResIdID("notification_largeIcon"), EUExUtil.getResDrawableID("icon")); } // Time SimpleDateFormat format = new SimpleDateFormat("HH:mm"); remoteViews.setTextViewText(EUExUtil.getResIdID("notification_time"), format.format(System.currentTimeMillis())); remoteViews.setTextColor(EUExUtil.getResIdID("notification_time"), alphaColor); builder.setContent(remoteViews); } Intent notiIntent = new Intent(context, EBrowserActivity.class); notiIntent.putExtra("ntype", F_TYPE_PUSH); notiIntent.putExtra("data", body); notiIntent.putExtra("message", message); Bundle bundle = new Bundle(); bundle.putSerializable(PushReportConstants.PUSH_DATA_INFO_KEY, dataInfo); notiIntent.putExtras(bundle); PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationNB, notiIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = builder.build(); // Android v4bug2.3?Builder?NotificationRemoteView?? if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && remoteViews != null) { notification.contentView = remoteViews; } manager.notify(notificationNB, notification); notificationNB++; }
From source file:ws.logv.trainmonitor.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w ww .j ava 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: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;// w w w. ja v a 2 s .c o 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.neatier.shell.notification.FCMListenerService.java
/** * Create and show a simple notification containing the received FCM remoteMessage. * * @param remoteMessage FCM remoteMessage body received. *//*ww w . j av a 2 s . c o m*/ private void sendNotification(RemoteMessage remoteMessage) { RemoteMessage.Notification noti = remoteMessage.getNotification(); KeyValuePairs<String, String> data = new KeyValuePairs<>(); String title = getString(R.string.app_name); String message = getString(R.string.fcm_message_default); StringBuffer contentText = new StringBuffer(); if (noti != null) { title = TextUtils.isEmpty(noti.getTitle()) ? getString(R.string.app_name) : noti.getTitle(); contentText.append( TextUtils.isEmpty(noti.getBody()) ? getString(R.string.fcm_message_default) : noti.getBody()); } if (remoteMessage.getData() != null) { data.putAll(remoteMessage.getData()); title = data.getOrDefault("title", getString(R.string.app_name)); contentText.append(data.getOrDefault("message", getString(R.string.fcm_message_default))); } Context context = this; Intent intent = new Intent(this, NotificationActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); int requestCode = (int) (System.currentTimeMillis() & 0xfffffff); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack //stackBuilder.addParentStack(NotificationActivity.class); stackBuilder.addNextIntentWithParentStack(new Intent(context, MainActivity.class)); stackBuilder.addNextIntent(intent); // Adds the Intent to the top of the stack //stackBuilder.addNextIntent(intent); // Gets a PendingIntent containing the entire back stack //Need to set PendingIntent.FLAG_UPDATE_CURRENT to work with the starting intent. //See issue: http://goo.gl/lJrMNg PendingIntent resultPendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); //PendingIntent resultPendingIntent = // stackBuilder.getPendingIntent(requestCode, PendingIntent.FLAG_UPDATE_CURRENT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_neat_logo).setContentTitle(title).setContentText(contentText.toString()) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(resultPendingIntent) .setDefaults(Notification.DEFAULT_VIBRATE); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(requestCode, notificationBuilder.build()); }