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:br.com.recidev.gamethis.util.GcmIntentService.java
private void sendNotification(String msg, String tipoNotificacao, Bundle extras) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = null;/*from www.j a va2s. c o m*/ if (tipoNotificacao.equals("Novo Usuario")) { Usuario usuario = new Usuario(); usuario.setNome(extras.getString("nome")); usuario.setEmail(extras.getString("email")); usuario.setSenha(extras.getString("senha")); usuario.setAvatar(Integer.parseInt(extras.getString("avatar"))); usuario.setNome(extras.getString("syncStatus")); usuario.setGcm_id(extras.getString("gcm_id")); contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, HomeActivity.class), 0); } if (tipoNotificacao.equals("Novo Jogo")) { //TODO Ajustar depois o encaminhamento para meus jogos contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, HomeActivity.class), 0); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.game_this_2).setContentTitle("GameThis") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.toasty); mBuilder.setSound(sound); int defaults = 0; defaults = defaults | Notification.DEFAULT_LIGHTS; defaults = defaults | Notification.DEFAULT_VIBRATE; //defaults = defaults | Notification.DEFAULT_SOUND; mBuilder.setDefaults(defaults); mBuilder.setAutoCancel(true); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.hedgehog.smdb.ActionBarControlScrollViewActivity.java
private void showNotification() { Notification notification = null; Intent toLive = new Intent(this, ActionBarControlScrollViewActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), toLive, 0); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { notification = new Notification.Builder(this).setContentTitle("Time to Check the new Show!") .setContentInfo("").setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pIntent) .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_VIBRATE) .setAutoCancel(true).setOnlyAlertOnce(true) // .setTicker("Show running!") // .addAction(R.mipmap.ic_launcher, "View", pIntent) .build();/*from www . j a v a 2s. c om*/ } NotificationManager NM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notification.flags |= Notification.FLAG_AUTO_CANCEL; NM.notify(0, notification); }
From source file:me.acristoffers.tracker.AlarmReceiver.java
@Override public void statusUpdated(final Package pkg) { final String code = pkg.getCod(); final int count = pkg.getSteps().size(); if (countSteps.get(code) < count) { pkg.save();/*from ww w .jav a2s. c o m*/ final NotificationManager notificationManager = (NotificationManager) context.get() .getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { final String title = context.get().getString(R.string.notification_package_updated_title, pkg.getName()); final String message = context.get().getString(R.string.notification_package_updated_body, pkg.getName()); final Intent intent = new Intent(context.get(), PackageDetailsActivity.class); intent.putExtra(PackageDetailsActivity.PACKAGE_CODE, code); final PendingIntent pendingIntent = PendingIntent.getActivity(context.get(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); final Bitmap icon = BitmapFactory.decodeResource(context.get().getResources(), R.mipmap.ic_launcher); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context.get()); builder.setTicker(title).setContentTitle(title).setContentText(message) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setContentIntent(pendingIntent).setSmallIcon(R.mipmap.ic_launcher).setLargeIcon(icon) .setWhen(System.currentTimeMillis()).setAutoCancel(true); final Notification notification = builder.build(); final NotificationManager nm = (NotificationManager) context.get() .getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(pkg.getId(), notification); } } }
From source file:de.azapps.mirakel.reminders.ReminderAlarm.java
private static void createNotification(final Context context, final Task task) { Log.w(TAG, task.getName());/*from w w w .ja v a2 s . c om*/ final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final Optional<Class<?>> main = Helpers.getMainActivity(); if (!main.isPresent()) { return; } final Intent openIntent = new Intent(context, main.get()); final Bundle withTask = new Bundle(); withTask.putParcelable(DefinitionsHelper.EXTRA_TASK, task); openIntent.setAction(DefinitionsHelper.SHOW_TASK_REMINDER); openIntent.putExtra(DefinitionsHelper.EXTRA_TASK_REMINDER, task); openIntent.putExtra(String.valueOf(task.getId()), task.getId()); openIntent.setData(Uri.parse(openIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent pOpenIntent = PendingIntent.getActivity(context, 0, openIntent, 0); final Intent doneIntent = new Intent(context, TaskService.class); doneIntent.setAction(TaskService.TASK_DONE); doneIntent.putExtra(DefinitionsHelper.BUNDLE_WRAPPER, withTask); doneIntent.putExtra(String.valueOf(task.getId()), task.getId()); doneIntent.setData(Uri.parse(doneIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent pDoneIntent = PendingIntent.getService(context, 0, doneIntent, 0); final Intent laterIntent = new Intent(context, TaskService.class); laterIntent.setAction(TaskService.TASK_LATER); laterIntent.putExtra(DefinitionsHelper.BUNDLE_WRAPPER, withTask); laterIntent.putExtra(String.valueOf(task.getId()), task.getId()); laterIntent.setData(Uri.parse(laterIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent pLaterIntent = PendingIntent.getService(context, 0, laterIntent, 0); final boolean persistent = MirakelCommonPreferences.usePersistentReminders(); // Build Notification final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle(context.getString(R.string.reminder_notification_title, task.getName())) .setContentText(task.getContent()).setSmallIcon(R.drawable.ic_mirakel) .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, context)).setContentIntent(pOpenIntent) .setPriority(NotificationCompat.PRIORITY_HIGH).setLights(Color.BLUE, 1500, 300) .setOngoing(persistent).setDefaults(Notification.DEFAULT_VIBRATE) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .addAction(R.drawable.ic_checkmark_holo_light, context.getString(R.string.reminder_notification_done), pDoneIntent) .addAction(android.R.drawable.ic_menu_close_clear_cancel, context.getString(R.string.reminder_notification_later), pLaterIntent); final NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); final String priority = ((task.getPriority() > 0) ? ("+" + task.getPriority()) : String.valueOf(task.getPriority())); final CharSequence due; if (!task.getDue().isPresent()) { due = context.getString(R.string.no_date); } else { due = DateTimeHelper.formatDate(context, task.getDue()); } inboxStyle.addLine(context.getString(R.string.reminder_notification_list, task.getList().getName())); inboxStyle.addLine(context.getString(R.string.reminder_notification_priority, priority)); inboxStyle.addLine(context.getString(R.string.reminder_notification_due, due)); builder.setStyle(inboxStyle); // Build notification if (!allReminders.contains(task.getId())) { allReminders.add(task.getId()); nm.notify(DefinitionsHelper.NOTIF_REMINDER + (int) task.getId(), builder.build()); } }
From source file:org.yuttadhammo.BodhiTimer.TimerReceiver.java
@Override public void onReceive(Context context, Intent pintent) { Log.v(TAG, "ALARM: received alarm"); NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (player != null) { Log.v(TAG, "Releasing media player..."); try {/* ww w . j a v a 2 s. co m*/ player.release(); player = null; } catch (Exception e) { e.printStackTrace(); player = null; } finally { // do nothing } } // Cancel notification and return... if (CANCEL_NOTIFICATION.equals(pintent.getAction())) { Log.v(TAG, "Cancelling notification..."); mNM.cancelAll(); return; } // ...or display a new one Log.v(TAG, "Showing notification..."); player = new MediaPlayer(); int setTime = pintent.getIntExtra("SetTime", 0); String setTimeStr = TimerUtils.time2humanStr(context, setTime); Log.v(TAG, "Time: " + setTime); CharSequence text = context.getText(R.string.Notification); CharSequence textLatest = String.format(context.getString(R.string.timer_for_x), setTimeStr); // Load the settings SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean led = prefs.getBoolean("LED", true); boolean vibrate = prefs.getBoolean("Vibrate", true); String notificationUri = ""; boolean useAdvTime = prefs.getBoolean("useAdvTime", false); String advTimeString = prefs.getString("advTimeString", ""); String[] advTime = null; int advTimeIndex = 1; if (useAdvTime && advTimeString.length() > 0) { advTime = advTimeString.split("\\^"); advTimeIndex = prefs.getInt("advTimeIndex", 1); String[] thisAdvTime = advTime[advTimeIndex - 1].split("#"); // will be of format timeInMs#pathToSound if (thisAdvTime.length == 3) notificationUri = thisAdvTime[1]; if (notificationUri.equals("sys_def")) notificationUri = prefs.getString("NotificationUri", "android.resource://org.yuttadhammo.BodhiTimer/" + R.raw.bell); } else notificationUri = prefs.getString("NotificationUri", "android.resource://org.yuttadhammo.BodhiTimer/" + R.raw.bell); Log.v(TAG, "notification uri: " + notificationUri); if (notificationUri.equals("system")) notificationUri = prefs.getString("SystemUri", ""); else if (notificationUri.equals("file")) notificationUri = prefs.getString("FileUri", ""); else if (notificationUri.equals("tts")) { notificationUri = ""; final String ttsString = prefs.getString("tts_string", context.getString(R.string.timer_done)); Intent ttsIntent = new Intent(context, TTSService.class); ttsIntent.putExtra("spoken_text", ttsString); context.startService(ttsIntent); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context.getApplicationContext()) .setSmallIcon(R.drawable.notification).setContentTitle(text).setContentText(textLatest); Uri uri = null; // Play a sound! if (!notificationUri.equals("")) uri = Uri.parse(notificationUri); // Vibrate if (vibrate && uri == null) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } // Have a light if (led) { mBuilder.setLights(0xff00ff00, 300, 1000); } mBuilder.setAutoCancel(true); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, TimerActivity.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(TimerActivity.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); // Create intent for cancelling the notification Context appContext = context.getApplicationContext(); Intent intent = new Intent(appContext, TimerReceiver.class); intent.setAction(CANCEL_NOTIFICATION); // Cancel the pending cancellation and create a new one PendingIntent pendingCancelIntent = PendingIntent.getBroadcast(appContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); if (uri != null) { //remove notification sound mBuilder.setSound(null); try { if (player != null && player.isPlaying()) { player.release(); player = new MediaPlayer(); } int currVolume = prefs.getInt("tone_volume", 0); if (currVolume != 0) { float log1 = (float) (Math.log(100 - currVolume) / Math.log(100)); player.setVolume(1 - log1, 1 - log1); } player.setDataSource(context, uri); player.prepare(); player.setLooping(false); player.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub mp.release(); } }); player.start(); if (vibrate) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(1000); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (prefs.getBoolean("AutoClear", false)) { // Determine duration of notification sound int duration = 5000; if (uri != null) { MediaPlayer cancelPlayer = new MediaPlayer(); try { cancelPlayer.setDataSource(context, uri); cancelPlayer.prepare(); duration = Math.max(duration, cancelPlayer.getDuration() + 2000); } catch (java.io.IOException ex) { Log.e(TAG, "Cannot get sound duration: " + ex); duration = 30000; // on error, default to 30 seconds } finally { cancelPlayer.release(); } cancelPlayer.release(); } Log.v(TAG, "Notification duration: " + duration + " ms"); // Schedule cancellation AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmMgr.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + duration, pendingCancelIntent); } if (useAdvTime && advTimeString.length() > 0) { Intent broadcast = new Intent(); SharedPreferences.Editor editor = prefs.edit(); if (advTimeIndex < advTime.length) { editor.putInt("advTimeIndex", advTimeIndex + 1); String[] thisAdvTime = advTime[advTimeIndex].split("#"); // will be of format timeInMs#pathToSound int time = Integer.parseInt(thisAdvTime[0]); broadcast.putExtra("time", time); // Save new time editor.putLong("TimeStamp", new Date().getTime() + time); editor.putInt("LastTime", time); // editor.putString("NotificationUri", thisAdvTime[1]); mNM.cancelAll(); Log.v(TAG, "Starting next iteration of the timer service ..."); Intent rintent = new Intent(context, TimerReceiver.class); rintent.putExtra("SetTime", time); PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, rintent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager mAlarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mAlarmMgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + time, mPendingIntent); } else { broadcast.putExtra("stop", true); editor.putInt("advTimeIndex", 1); } broadcast.setAction(BROADCAST_RESET); context.sendBroadcast(broadcast); editor.apply(); } else if (prefs.getBoolean("AutoRestart", false)) { int time = pintent.getIntExtra("SetTime", 0); if (time != 0) { mNM.cancel(0); Log.v(TAG, "Restarting the timer service ..."); Intent rintent = new Intent(context, TimerReceiver.class); rintent.putExtra("SetTime", time); PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, rintent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager mAlarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mAlarmMgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + time, mPendingIntent); // Save new time SharedPreferences.Editor editor = prefs.edit(); editor.putLong("TimeStamp", new Date().getTime() + time); editor.putInt("LastTime", time); editor.apply(); Intent broadcast = new Intent(); broadcast.putExtra("time", time); broadcast.setAction(BROADCAST_RESET); context.sendBroadcast(broadcast); } } mNotificationManager.notify(0, mBuilder.build()); Log.d(TAG, "ALARM: alarm finished"); }
From source file:graaby.app.wallet.services.GcmIntentService.java
private void sendNotification(final String msg) { try {//from w w w. ja va 2 s. co m JSONObject object = new JSONObject(msg); PendingIntent pendingIntent = null; String notificationTitle, smallContentText, smallContentInfo = ""; int notificationImageResource = R.drawable.ic_noty_point, notificationID, uniquePendingId = (int) (System.currentTimeMillis() & 0xfffffff); SharedPreferences pref = getSharedPreferences("pref_notification", Activity.MODE_PRIVATE); Uri noty_sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (!TextUtils.isEmpty(pref.getString("notifications_new_message_ringtone", ""))) { noty_sound = Uri.parse(pref.getString("notifications_new_message_ringtone", "")); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSound(noty_sound) .setLights(0xff2ECC71, 300, 1000).setAutoCancel(Boolean.TRUE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_SOCIAL); if (pref.getBoolean("notifications_new_message_vibrate", true)) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } Intent activityIntent = new Intent(); switch (NotificationType.getType(object.getInt(getString(R.string.field_gcm_msg_type)))) { case SHARE_POINTS: //user received points from contact String sender = object.getString(getString(R.string.field_gcm_name)); int amount = object.getInt(getString(R.string.contact_send_amount)); notificationTitle = getString(R.string.gcm_message_recieved_points); smallContentText = String.format(getString(R.string.gcm_message_recieved_points_content), sender, amount); smallContentInfo = String.valueOf(amount); notificationImageResource = R.drawable.ic_noty_point; notificationID = getRandomInt(0, 50); mBuilder.setColor(getResources().getColor(R.color.alizarin)); activityIntent.setClass(this, PointReceivedActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_POINTS); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(PointReceivedActivity.class); stackBuilder.addNextIntent(activityIntent); Intent broadcastIntent = new Intent(this, GraabyBroadcastReceiver.class); broadcastIntent.setAction(GraabyBroadcastReceiver.ACTION_THANK); broadcastIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); broadcastIntent.putExtra(Helper.NOTIFICATIONID, notificationID); PendingIntent pendingBroadcastIntent = PendingIntent.getBroadcast(this, uniquePendingId, broadcastIntent, 0); mBuilder.addAction(R.drawable.ic_action_accept, "Say thanks", pendingBroadcastIntent); pendingIntent = stackBuilder.getPendingIntent(uniquePendingId, PendingIntent.FLAG_ONE_SHOT); break; case TRANSACTION: //user made a transaction amount = object.getInt(getString(R.string.contact_send_amount)); String outlet = object.getString(getString(R.string.field_business_name)); notificationTitle = getString(R.string.gcm_message_transaction); smallContentText = String.format(getString(R.string.gcm_message_transaction_content), amount, outlet); smallContentInfo = String.valueOf(amount); notificationImageResource = R.drawable.ic_noty_point; notificationID = getRandomInt(51, 100); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(smallContentText)); mBuilder.setColor(getResources().getColor(R.color.alizarin)); activityIntent.setClass(this, PointReceivedActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_TX); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); activityIntent.putExtra(Helper.NOTIFICATIONID, notificationID); pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_ONE_SHOT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_STATUS); break; case NEW_VOUCHER: //new marketplace voucher has appeared outlet = object.getString(getString(R.string.field_business_name)); notificationTitle = getString(R.string.gcm_message_market); if (object.has("msg")) smallContentText = object.getString("msg") + " @ " + outlet; else smallContentText = String.format(getString(R.string.gcm_message_market_content), outlet); smallContentInfo = ""; notificationImageResource = R.drawable.ic_gcm_discount; notificationID = NOTIFICATION_ID_NEW_MARKET; mBuilder.setStyle(new NotificationCompat.BigTextStyle() .bigText(String.format(getString(R.string.gcm_message_market_content), outlet))); mBuilder.setColor(getResources().getColor(R.color.sunflower)); activityIntent.setClass(this, MarketActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_NEW_DISCOUNT); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); activityIntent.putExtra(Helper.NOTIFICATIONID, NOTIFICATION_ID_NEW_MARKET); activityIntent.putExtra(Helper.MY_DISCOUNT_ITEMS_FLAG, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_PROMO); break; case NEW_FEED: notificationTitle = "New message"; smallContentText = object.getString("msg"); notificationImageResource = R.drawable.ic_noty_announcement; notificationID = NOTIFICATION_ID_FEED; activityIntent.setClass(this, FeedActivity.class); activityIntent.putExtra(Helper.NOTIFICATIONID, NOTIFICATION_ID_FEED); activityIntent.setAction(NOTIFICATION_ACTION_FEED); mBuilder.setColor(getResources().getColor(R.color.alizarin)); pendingIntent = TaskStackBuilder.create(this).addNextIntentWithParentStack(activityIntent) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); break; case THANK_CONTACT: //contact thanks you for sending points String thanksString = object.getString(getString(R.string.field_gcm_name)); notificationTitle = getString(R.string.gcm_message_thanked); smallContentText = String.format(getString(R.string.gcm_message_thanked_small_content), thanksString); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(smallContentText)); notificationImageResource = R.drawable.ic_noty_thank; notificationID = NOTIFICATION_ID_THANKED; mBuilder.setColor(getResources().getColor(R.color.belizehole)); break; case CHECKIN: //checkin notification outlet = object.getString(getString(R.string.field_gcm_name)); notificationTitle = getString(R.string.gcm_message_checkin_title); smallContentText = String.format(getString(R.string.gcm_message_checkin_small_content), outlet); notificationImageResource = R.drawable.ic_gcm_checkin; notificationID = NOTIFICATION_ID_CHECKIN; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setCategory(Notification.CATEGORY_STATUS); mBuilder.setColor(getResources().getColor(R.color.wisteria)); break; case INFO_NEEDED: notificationTitle = getString(R.string.gcm_message_meta_info_title); smallContentText = getString(R.string.gcm_message_meta_info_title); notificationImageResource = R.drawable.ic_noty_information; notificationID = NOTIFICATION_ID_INFO; mBuilder.setColor(getResources().getColor(R.color.emarald)); activityIntent.setClass(this, ExtraInfoActivity.class); activityIntent.setAction(NOTIFICATION_ACTION_INFO); activityIntent.putExtra(Helper.INTENT_CONTAINER_INFO, msg); activityIntent.putExtra(Helper.NOTIFICATIONID, notificationID); pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); break; case NONE: default: notificationTitle = ""; smallContentText = ""; smallContentInfo = ""; notificationID = 0; } if (pendingIntent == null) pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); mBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), notificationImageResource)) .setSmallIcon(R.drawable.ic_noty_graaby).setContentTitle(notificationTitle) .setContentText(smallContentText).setContentInfo(smallContentInfo) .setContentIntent(pendingIntent); mNotificationManager.notify(notificationID, mBuilder.build()); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.anysoftkeyboard.ChewbaccaUncaughtExceptionHandler.java
public void uncaughtException(Thread thread, Throwable ex) { Log.e(TAG, "Caught an unhandled exception!!!", ex); boolean ignore = false; // https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/15 //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/433 String stackTrace = Log.getStackTrace(ex); if (ex instanceof NullPointerException) { if (stackTrace.contains( "android.inputmethodservice.IInputMethodSessionWrapper.executeMessage(IInputMethodSessionWrapper.java") || stackTrace.contains(// w w w.ja v a 2 s .co m "android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java")) { Log.w(TAG, "An OS bug has been adverted. Move along, there is nothing to see here."); ignore = true; } } else if (ex instanceof java.util.concurrent.TimeoutException) { if (stackTrace.contains(".finalize")) { Log.w(TAG, "An OS bug has been adverted. Move along, there is nothing to see here."); ignore = true; } } if (!ignore && AnyApplication.getConfig().useChewbaccaNotifications()) { String appName = DeveloperUtils.getAppDetails(mApp); final CharSequence utcTimeDate = DateFormat.format("kk:mm:ss dd.MM.yyyy", new Date()); final String newline = DeveloperUtils.NEW_LINE; String logText = "Hi. It seems that we have crashed.... Here are some details:" + newline + "****** UTC Time: " + utcTimeDate + newline + "****** Application name: " + appName + newline + "******************************" + newline + "****** Exception type: " + ex.getClass().getName() + newline + "****** Exception message: " + ex.getMessage() + newline + "****** Trace trace:" + newline + stackTrace + newline; logText += "******************************" + newline + "****** Device information:" + newline + DeveloperUtils.getSysInfo(mApp); if (ex instanceof OutOfMemoryError || (ex.getCause() != null && ex.getCause() instanceof OutOfMemoryError)) { logText += "******************************\n" + "****** Memory:" + newline + getMemory(); } logText += "******************************" + newline + "****** Log-Cat:" + newline + Log.getAllLogLines(); String crashType = ex.getClass().getSimpleName() + ": " + ex.getMessage(); Intent notificationIntent = new Intent(mApp, SendBugReportUiActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Parcelable reportDetailsExtra = new SendBugReportUiActivity.BugReportDetails(ex, logText); notificationIntent.putExtra(SendBugReportUiActivity.EXTRA_KEY_BugReportDetails, reportDetailsExtra); PendingIntent contentIntent = PendingIntent.getActivity(mApp, 0, notificationIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(mApp); builder.setSmallIcon( Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? R.drawable.notification_error_icon : R.drawable.ic_notification_error) .setColor(ContextCompat.getColor(mApp, R.color.notification_background_error)) .setTicker(mApp.getText(R.string.ime_crashed_ticker)) .setContentTitle(mApp.getText(R.string.ime_name)) .setContentText(mApp.getText(R.string.ime_crashed_sub_text)) .setSubText(BuildConfig.TESTING_BUILD ? crashType : null/*not showing the type of crash in RELEASE mode*/) .setWhen(System.currentTimeMillis()).setContentIntent(contentIntent).setAutoCancel(true) .setOnlyAlertOnce(true).setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE); // notifying NotificationManager notificationManager = (NotificationManager) mApp .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(R.id.notification_icon_app_error, builder.build()); } // and sending to the OS if (!ignore && mOsDefaultHandler != null) { Log.i(TAG, "Sending the exception to OS exception handler..."); mOsDefaultHandler.uncaughtException(thread, ex); } Thread.yield(); //halting the process. No need to continue now. I'm a dead duck. System.exit(0); }
From source file:com.akop.bach.service.XboxLiveServiceClient.java
private void notifyMessages(XboxLiveAccount account, long[] unreadMessages, List<Long> lastUnreadList) { NotificationManager mgr = getNotificationManager(); Context context = getContext(); int notificationId = 0x1000000 | ((int) account.getId() & 0xffffff); if (App.getConfig().logToConsole()) { String s = ""; for (Object unr : lastUnreadList) s += unr.toString() + ","; App.logv("Currently unread (%d): %s", lastUnreadList.size(), s); s = "";//from w ww .ja va 2 s . c om for (Object unr : unreadMessages) s += unr.toString() + ","; App.logv("New unread (%d): %s", unreadMessages.length, s); } if (unreadMessages.length > 0) { int unreadCount = 0; for (Object unread : unreadMessages) { if (!lastUnreadList.contains(unread)) unreadCount++; } if (App.getConfig().logToConsole()) App.logv("%d computed new", unreadCount); if (unreadCount > 0) { String tickerTitle; String tickerText; if (unreadMessages.length == 1) { tickerTitle = context.getString(R.string.new_message); tickerText = context.getString(R.string.notify_message_pending_f, account.getScreenName(), Messages.getSender(context, unreadMessages[0])); } else { tickerTitle = context.getString(R.string.new_messages); tickerText = context.getString(R.string.notify_messages_pending_f, account.getScreenName(), unreadMessages.length, account.getDescription()); } Notification notification = new Notification(R.drawable.xbox_stat_notify_message, tickerText, System.currentTimeMillis()); Intent intent = new Intent(context, MessageList.class); intent.putExtra("account", account); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS; if (unreadMessages.length > 1) notification.number = unreadMessages.length; notification.ledOnMS = DEFAULT_LIGHTS_ON_MS; notification.ledOffMS = DEFAULT_LIGHTS_OFF_MS; notification.ledARGB = DEFAULT_LIGHTS_COLOR; notification.sound = account.getRingtoneUri(); if (account.isVibrationEnabled()) notification.defaults |= Notification.DEFAULT_VIBRATE; notification.setLatestEventInfo(context, tickerTitle, tickerText, contentIntent); mgr.notify(notificationId, notification); } } else // No unread messages { mgr.cancel(notificationId); } }
From source file:com.neighbor.ex.tong.GcmIntentService.java
private void NotiMessage(String message, Uri uri) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(this, LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Common.PUSH_NOIT, Common.PUSH_NOIT); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()); mBuilder.setSmallIcon(R.drawable.icon); mBuilder.setTicker(":" + message); mBuilder.setWhen(System.currentTimeMillis()); mBuilder.setContentTitle(""); mBuilder.setContentText(message);/* ww w . j a v a 2s .com*/ mBuilder.setContentIntent(pendingIntent); mBuilder.setAutoCancel(true); mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); mBuilder.setSound(uri); mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); nm.notify(0, mBuilder.build()); }
From source file:com.automated.taxinow.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// ww w . ja v a 2 s.c om private void generateNotification(Context context, String message) { // System.out.println("this is message " + message); // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + 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, MainDrawerActivity.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(0, 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(); }