private void playSounds(boolean locked) { // User feedback for keyguard. if (mSuppressNextLockSound) { mSuppressNextLockSound = false; return; } final ContentResolver cr = mContext.getContentResolver(); if (Settings.System.getInt(cr, Settings.System.LOCKSCREEN_SOUNDS_ENABLED, 1) == 1) { final String whichSound = locked ? Settings.System.LOCK_SOUND : Settings.System.UNLOCK_SOUND; final String soundPath = Settings.System.getString(cr, whichSound); if (soundPath != null) { final Uri soundUri = Uri.parse("file://" + soundPath); if (soundUri != null) { final Ringtone sfx = RingtoneManager.getRingtone(mContext, soundUri); if (sfx != null) { sfx.setStreamType(AudioManager.STREAM_SYSTEM); sfx.play(); } else { Log.d(TAG, "playSounds: failed to load ringtone from uri: " + soundUri); } } else { Log.d(TAG, "playSounds: could not parse Uri: " + soundPath); } } else { Log.d(TAG, "playSounds: whichSound = " + whichSound + "; soundPath was null"); } } }
/** Plays a sound notification to alert the user. */ public void playNotification() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { } }
private void AlertNotify() { try { Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(ApplicationContextProvider.getContext(), sound); r.play(); } catch (Exception e) { } }
private void sonar() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
public static void playNotificationSound(Context context) { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }
public static void playNotificationSound(Context context) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (uri != null) { Ringtone rt = RingtoneManager.getRingtone(context, uri); if (rt != null) { rt.setStreamType(AudioManager.STREAM_NOTIFICATION); rt.play(); } } }
public void run() { try { if (notification == null) { notification = RingtoneManager.getRingtone(ctx, RingtoneManager.getDefaultUri(type)); } if (notification != null) { notification.play(); } } catch (Exception e) { Log.e(LCAT, "Error playing beep.", e); } }
private void displayData(String data) { if (data != null) { mDataField.setText(data); Log.d(TAG, "displaying: " + data); if (mDataRecievedSound != null) { mDataRecievedSound.play(); } mReturnIntent.putExtra(EXTRA_VALUE, data); setResult(Activity.RESULT_OK, mReturnIntent); // onPause(); } }
// Playing notification sound public void playNotificationSound() { try { Uri alarmSound = Uri.parse( ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + IsmartApp.getInstance().getApplicationContext().getPackageName() + "/raw/notification"); Ringtone r = RingtoneManager.getRingtone(IsmartApp.getInstance().getApplicationContext(), alarmSound); r.play(); } catch (Exception e) { e.printStackTrace(); } }
@Override public void onReceive(Context context, Intent intent) { // here you can get the extras you passed in when creating the alarm // intent.getBundleExtra(REMINDER_BUNDLE)); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, notification); r.play(); } catch (Exception e) { } Intent stop = new Intent(context, BusStopActivity.class); stop.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); stop.putExtras(intent.getExtras()); context.startActivity(stop); }
private void createNoifications(int icon, String endereco) { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); mBuilder = new NotificationCompat.Builder(TelaMaps.this) .setSmallIcon(icon) .setContentTitle("Dormi No Ponto") .setContentText(endereco); mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, mBuilder.build()); } catch (Exception e) { Log.e("ERROR", "" + e.getMessage()); } }
@SuppressWarnings("deprecation") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int notifID; NotificationManager nm; // Get the notification ID notifID = getIntent().getExtras().getInt("NotifID"); // Create the pending intent that will reference the intent to go when clicked Intent i = new Intent(this, MainActivity.class); i.putExtra("NotifID", notifID); PendingIntent detailsIntent = PendingIntent.getActivity(this, 0, i, 0); // Setup notification nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notif = new Notification(R.drawable.ic_launcher, "Food has expired!", System.currentTimeMillis()); // Hides status bar notification when clicked notif.flags |= Notification.FLAG_AUTO_CANCEL; CharSequence from = "RemindMe"; CharSequence message = "Food has expired!"; notif.setLatestEventInfo(this, from, message, detailsIntent); // ---100ms delay, vibrate for 250ms, pause for 100 ms and // then vibrate for 500ms--- notif.vibrate = new long[] {100, 250, 100, 500}; nm.notify(notifID, notif); // Added sound to notification try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); // this.setVolumeControlStream(AudioManager.STREAM_NOTIFICATION); r.setStreamType(AudioManager.STREAM_NOTIFICATION); r.play(); } catch (Exception e) { } // Destroy activity finish(); }
public void showNotification(Message message) { Intent intent = new Intent(this, Notification.class); boolean isGroup = message.getIsGroup(); int notificationID = isGroup ? message.getReceiver() : message.getIdFriend(); intent.putExtra("notificationID", notificationID); intent.putExtra("isGroup", isGroup); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); String name = ""; if (isGroup) { Group group = user.getGroupsHashMap().get(String.valueOf(notificationID)); name = group.getName(); } else { name = User.getInstance().getFriendsHashMap().get(String.valueOf(notificationID)).getNick(); } CharSequence ticker = message.getText(); CharSequence contentTitle = "Android Chat"; CharSequence contentText = "Message from " + name; NotificationCompat.Builder noti = new NotificationCompat.Builder(this) .setContentIntent(pendingIntent) .setTicker(ticker) .setContentTitle(contentTitle) .setContentText(contentText) // .setLights(Color.RED, 1, 0) .setSmallIcon(R.mipmap.ic_ini) .setPriority(android.app.Notification.PRIORITY_MAX) .setAutoCancel(true) .addAction(R.mipmap.ic_ini, ticker, pendingIntent) .setVibrate(new long[] {100, 250, 100, 500}); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(notificationID, noti.build()); ringtone.play(); }
@Override public void onReceive(Context context, Intent intent) { boolean iscloud = intent.getBooleanExtra("taskValue", false); if (iscloud) { String status = intent.getStringExtra("taskStatusValue"); selectedImage = intent.getStringExtra("selectedImage"); changeTaskStatus(status); } try { Uri notification = android.media.RingtoneManager.getDefaultUri( android.media.RingtoneManager.TYPE_NOTIFICATION); android.media.Ringtone r = android.media.RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { } }
public void run() { int event = nativeQaul.timedCheckAppEvent(); if (event == 0) { // nothing happened, no action to take } else if (event == 99) { Log.d(MSG_TAG, "qaulCheckEvents: quit app"); qaulQuit(); } else if (event == 100) { Log.d(MSG_TAG, "qaulCheckEvents: open file chooser"); qaulSelectFile(); } else if (event == 101) { Log.d(MSG_TAG, "qaulCheckEvents: open file"); qaulOpenFile(nativeQaul.getAppEventOpenPath()); } else if (event == 102) { Log.d(MSG_TAG, "qaulCheckEvents: open URL"); qaulOpenURL(nativeQaul.getAppEventOpenURL()); } else if (event == 103 || event == 104) { Log.d(MSG_TAG, "qaulCheckEvents: notify"); // Get instance of Vibrator from current Context Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 300 milliseconds v.vibrate(300); // play ring tone // fixme: seems not to work Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } else { Log.d(MSG_TAG, "qaulCheckEvents: unknown event " + event); } if (!qaulTimersStop) qaulStartHandler.postDelayed(qaulCheckEvents, 300); else Log.d(MSG_TAG, "qaulCheckEvents: stopped"); }
/** 手机震动和声音提示 */ public void viberateAndPlayTone(EMMessage message) { if (message != null) { if (EMChatManager.getInstance().isSlientMessage(message)) { return; } } com.easemob.applib.model.HXSDKModel model = HXSDKHelper.getInstance().getModel(); if (!model.getSettingMsgNotification()) { return; } if (System.currentTimeMillis() - lastNotifiyTime < 1000) { // received new messages within 2 seconds, skip play ringtone return; } try { lastNotifiyTime = System.currentTimeMillis(); // 判断是否处于静音模式 if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { EMLog.e(TAG, "in slient mode now"); return; } if (model.getSettingMsgVibrate()) { long[] pattern = new long[] {0, 180, 80, 120}; vibrator.vibrate(pattern, -1); } if (model.getSettingMsgSound()) { if (ringtone == null) { Uri notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); ringtone = RingtoneManager.getRingtone(appContext, notificationUri); if (ringtone == null) { EMLog.d(TAG, "cant find ringtone at:" + notificationUri.getPath()); return; } } if (!ringtone.isPlaying()) { String vendor = Build.MANUFACTURER; ringtone.play(); // for samsung S3, we meet a bug that the phone will // continue ringtone without stop // so add below special handler to stop it after 3s if // needed if (vendor != null && vendor.toLowerCase().contains("samsung")) { Thread ctlThread = new Thread() { public void run() { try { Thread.sleep(3000); if (ringtone.isPlaying()) { ringtone.stop(); } } catch (Exception e) { } } }; ctlThread.run(); } } } } catch (Exception e) { e.printStackTrace(); } }
@Override public void startSample() { if (mRingtone != null && !isSamplePlaying()) { mRingtone.play(); } }
protected final void notifyClient$1c42781f( String fromJid, String fromUserName, String message, boolean showNotification, boolean silent_notification) { Object obj; UserProvider userProvider; String str; String threadId = Utils.getUserIdFromXmppUserId(this.mConfig.jabberID) + "-" + Utils.getUserIdFromXmppUserId(fromJid); if (currentOpenedThreadId == null || !currentOpenedThreadId.equalsIgnoreCase(threadId)) { if (fromJid.equals("rabtcdn.com")) { Context context = SHAMChatApplication.getMyApplicationContext(); Intent intent = new Intent(context, BroadcastMessageActivity.class); intent.putExtra("Message", message); intent.setFlags(ClientDefaults.MAX_MSG_SIZE); context.startActivity(intent); } else if (showNotification) { int intValue; Notification notification; int notifyId; this.mWakeLock.acquire(); if (silent_notification && !this.notificationCount.containsKey(fromJid)) { silent_notification = false; } if (this.notificationCount.containsKey(fromJid)) { intValue = ((Integer) this.notificationCount.get(fromJid)).intValue(); } else { intValue = 0; } try { ((NotificationManager) getSystemService("notification")).cancelAll(); } catch (Exception e) { } String userIdFromXmppUserId = Utils.getUserIdFromXmppUserId(fromJid); String str2 = Utils.getUserIdFromXmppUserId(this.mConfig.jabberID) + "-" + userIdFromXmppUserId; if (currentOpenedThreadId == null || !currentOpenedThreadId.equalsIgnoreCase(str2)) { CharSequence charSequence; Object obj2; Cursor query; CharSequence charSequence2; PendingIntent activity; if (message.contains("http://")) { message = "New Media file"; } int i = intValue + 1; this.notificationCount.put(fromJid, Integer.valueOf(i)); if (fromUserName == null || fromUserName.length() == 0) { charSequence = "New message"; obj2 = null; } else { if (fromUserName.contains("_")) { int i2; String str3 = "New message "; query = getContentResolver() .query( UserProvider.CONTENT_URI_GROUP, new String[] {FriendGroup.DB_NAME}, FriendGroup.CHAT_ROOM_NAME + "=?", new String[] {fromJid}, null); if (query.getCount() > 0) { query.moveToFirst(); String string = query.getString(query.getColumnIndex(FriendGroup.DB_NAME)); if (!(string == null || string.isEmpty())) { charSequence = str3 + "from " + string; i2 = 1; } } obj = str3; i2 = 1; } else { try { Cursor query2 = getContentResolver() .query( Uri.parse( UserProvider.CONTENT_URI_USER.toString() + MqttTopic.TOPIC_LEVEL_SEPARATOR + Utils.getUserIdFromXmppUserId(fromJid)), null, null, null, null); query2.moveToFirst(); charSequence = query2.getString(query2.getColumnIndex("mobileNo")); if (charSequence != null) { ContactDetails conactExists = Utils.getConactExists(getApplicationContext(), charSequence); if (conactExists.isExist) { charSequence = conactExists.displayName; obj2 = null; } else { obj2 = null; } } else { try { charSequence = query2.getString(query2.getColumnIndex("name")); obj2 = null; } catch (Exception e2) { userProvider = new UserProvider(); str = UserProvider.getUserDetailsFromServer( Utils.getUserIdFromXmppUserId(fromJid)) .username; e2.printStackTrace(); obj = str; obj2 = null; } } } catch (Exception e22) { userProvider = new UserProvider(); str = UserProvider.getUserDetailsFromServer(Utils.getUserIdFromXmppUserId(fromJid)) .username; e22.printStackTrace(); obj = str; obj2 = null; } } } if (obj2 == null) { charSequence = getString(2131493237, new Object[] {charSequence}); } if (this.mConfig.ticker) { intValue = message.indexOf(10); if (intValue < 0) { intValue = 0; } if (intValue > 45 || message.length() > 45) { intValue = 45; } if (intValue > 0) { str = message.substring(0, intValue) + " [...]"; } else { str = message; } charSequence2 = charSequence + ":\n" + str; } else { charSequence2 = getString(2131493235); } SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("setting", 0); sp = sharedPreferences; switch (sharedPreferences.getInt("notif_icon", 1)) { case Logger.SEVERE /*1*/: this.mNotification = new Notification(2130837905, charSequence2, System.currentTimeMillis()); break; case Logger.WARNING /*2*/: this.mNotification = new Notification(2130837906, charSequence2, System.currentTimeMillis()); break; case Logger.INFO /*3*/: this.mNotification = new Notification(2130837907, charSequence2, System.currentTimeMillis()); break; case Logger.CONFIG /*4*/: this.mNotification = new Notification(2130837908, charSequence2, System.currentTimeMillis()); break; case Logger.FINE /*5*/: this.mNotification = new Notification(2130837909, charSequence2, System.currentTimeMillis()); break; case Logger.FINER /*6*/: this.mNotification = new Notification(2130837910, charSequence2, System.currentTimeMillis()); break; case Logger.FINEST /*7*/: this.mNotification = new Notification(2130837911, charSequence2, System.currentTimeMillis()); break; case C0473R.styleable.SwitchButton_thumb_width /*8*/: this.mNotification = new Notification(2130837912, charSequence2, System.currentTimeMillis()); break; case C0473R.styleable.SwitchButton_thumb_height /*9*/: this.mNotification = new Notification(2130837913, charSequence2, System.currentTimeMillis()); break; default: this.mNotification = new Notification(2130837905, charSequence2, System.currentTimeMillis()); break; } this.mNotification.defaults = 0; Uri parse = Uri.parse(fromJid); this.mNotificationIntent.setData(parse); this.mNotificationGroupIntent.setData(parse); if (obj2 == null) { this.mNotificationIntent.putExtra( ChatActivity.INTENT_EXTRA_USER_ID, userIdFromXmppUserId); this.mNotificationIntent.putExtra( ChatInitialForGroupChatActivity.INTENT_EXTRA_THREAD_ID, str2); this.mNotificationIntent.setFlags(536870912); activity = PendingIntent.getActivity(this, 0, this.mNotificationIntent, 134217728); } else { this.mNotificationGroupIntent.putExtra( ChatInitialForGroupChatActivity.INTENT_EXTRA_GROUP_ID, userIdFromXmppUserId); this.mNotificationGroupIntent.putExtra( ChatInitialForGroupChatActivity.INTENT_EXTRA_THREAD_ID, str2); this.mNotificationGroupIntent.setFlags(536870912); activity = PendingIntent.getActivity(this, 0, this.mNotificationGroupIntent, 134217728); } long currentTimeMillis = System.currentTimeMillis(); Intent intent2 = new Intent(this, MainWindow.class); intent2.setFlags(67108864); PendingIntent.getActivity(this, 0, intent2, 134217728); Builder builder = new Builder(this); builder .setAutoCancel(true) .setContentTitle(charSequence) .setContentIntent(activity) .setContentText(message) .setTicker(charSequence2) .setWhen(currentTimeMillis) .setSmallIcon(2130837905); Notification build = builder.build(); build.flags = 8; ((NotificationManager) getSystemService("notification")).notify(1, build); if (i > 1) { this.mNotification.number = i; } this.mNotification.flags = 16; query = getContentResolver() .query( UserProvider.CONTENT_URI_NOTIFICATION, null, "user_id=?", new String[] {this.mConfig.userId}, null); query.moveToFirst(); UserProvider.userNotificationFromCursor(query); SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Editor edit = defaultSharedPreferences.edit(); try { Uri parse2; int i3 = sp.getInt("sound", 1); Log.i("Notify", "Sound " + i3); switch (i3) { case Logger.SEVERE /*1*/: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034112"); break; case Logger.WARNING /*2*/: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034113"); break; case Logger.INFO /*3*/: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034114"); break; case Logger.CONFIG /*4*/: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034116"); break; case Logger.FINE /*5*/: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034118"); break; default: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034112"); break; } Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), parse2); if (System.currentTimeMillis() - Long.valueOf(defaultSharedPreferences.getLong("Notification", 3100)) .longValue() > 2000 && !ringtone.isPlaying()) { ringtone.play(); edit.putLong("Notification", System.currentTimeMillis()); edit.commit(); } } catch (Exception e3) { } } if (this.mConfig.isLEDNotify) { this.mNotification.ledARGB = -65281; this.mNotification.ledOnMS = 300; this.mNotification.ledOffMS = 1000; notification = this.mNotification; notification.flags |= 1; } if (!silent_notification) { this.mNotification.sound = this.mConfig.notifySound; } if (this.notificationId.containsKey(fromJid)) { notifyId = ((Integer) this.notificationId.get(fromJid)).intValue(); } else { this.lastNotificationId++; notifyId = this.lastNotificationId; this.notificationId.put(fromJid, Integer.valueOf(notifyId)); } if (!silent_notification && "SYSTEM".equals(this.mConfig.vibraNotify)) { notification = this.mNotification; notification.defaults |= 2; } SharedPreferences sharedPreferences2 = SHAMChatApplication.getMyApplicationContext().getSharedPreferences("setting", 0); sp = sharedPreferences2; int shakes = sharedPreferences2.getInt("shakee", 1); Log.i("Notify", "Vibrate " + shakes); if (shakes != 0) { this.mNotificationMGR.notify(notifyId, this.mNotification); this.mVibrator.vibrate(400); } this.mWakeLock.release(); } else if (!silent_notification) { try { if (!Uri.EMPTY.equals(this.mConfig.notifySound)) { RingtoneManager.getRingtone(getApplicationContext(), this.mConfig.notifySound).play(); } } catch (NullPointerException e4) { } } } }