List of usage examples for android.media Ringtone play
public void play()
From source file:com.coinblesk.client.KeyboardFragment.java
private void playNotificationSound() { try {/*from w ww. jav a 2 s . com*/ Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getActivity(), notification); r.play(); } catch (Exception e) { Log.e(TAG, "Error playing notification.", e); } }
From source file:com.remobile.dialogs.Notification.java
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification *///from w ww . j a va 2 s. co m public void beep(final long count) { final Activity activity = this.cordova.getActivity(); this.cordova.getThreadPool().execute(new Runnable() { public void run() { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(activity.getBaseContext(), ringtone); // If phone is not set to silent mode if (notification != null) { for (long i = 0; i < count; ++i) { notification.play(); long timeout = 5000; while (notification.isPlaying() && (timeout > 0)) { timeout = timeout - 100; try { Thread.sleep(100); } catch (InterruptedException e) { } } } } } }); }
From source file:com.microsoft.projectoxford.face.samples.ui.Camera2BasicFragment.java
private void detectAndFrame() { final Bitmap bm = BitmapFactory .decodeFile(getActivity().getExternalFilesDir(null).getAbsolutePath() + "/pic.jpg"); final Bitmap bitm = Bitmap.createScaledBitmap(bm, bm.getWidth() / 8, bm.getHeight() / 8, true); final Bitmap bn = BitmapFactory .decodeFile(getActivity().getExternalFilesDir(null).getAbsolutePath() + "/pic_l.jpg"); final Bitmap bitn = Bitmap.createScaledBitmap(bn, bn.getWidth() / 8, bn.getHeight() / 8, true); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); bitm.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final AsyncTask<UUID, String, IdentifyResult[]> identifyTask = new AsyncTask<UUID, String, IdentifyResult[]>() { private boolean mSucceed = true; private String mPersonGroupId = getString(R.string.group_id); @Override/* w ww. j a va 2s . c o m*/ protected IdentifyResult[] doInBackground(UUID... params) { try { // Start identification. return faceServiceClient.identity(this.mPersonGroupId, /* personGroupId */ params, /* faceIds */ 1); /* maxNumOfCandidatesReturned */ } catch (Exception e) { mSucceed = false; return null; } } @Override protected void onPostExecute(IdentifyResult[] result) { // Show the result on screen when detection is done. if (result == null) { showToast("error"); return; } if (result[0].candidates.size() > 0) { showToast("pass"); plu.unlock(); } else { showToast("no such user"); } } }; AsyncTask<InputStream, String, Face[]> detectTask = new AsyncTask<InputStream, String, Face[]>() { @Override protected Face[] doInBackground(InputStream... params) { try { publishProgress("Detecting..."); result = faceServiceClient.detect(params[0], true, // returnFaceId true, // returnFaceLandmarks null // returnFaceAttributes: a string like "age, gender" ); if (result == null) { publishProgress("Detection Finished. Nothing detected"); return null; } publishProgress(String.format("Detection Finished. %d face(s) detected", result.length)); return result; } catch (Exception e) { publishProgress("Detection failed"); return null; } } @Override protected void onPreExecute() { } @Override protected void onProgressUpdate(String... progress) { } @Override protected void onPostExecute(Face[] result) { if (result == null || result.length == 0) { showToast("No Face"); return; } if (result.length > 1) { showToast("More than one Face"); return; } if (checkb(bitm, bitn) && checkl(bitm, bitn, result[0].faceLandmarks.eyeLeftOuter.x, result[0].faceLandmarks.eyeLeftTop.y, result[0].faceLandmarks.eyeLeftInner.x, result[0].faceLandmarks.eyeLeftBottom.y) && checkl(bitm, bitn, result[0].faceLandmarks.eyeRightInner.x, result[0].faceLandmarks.eyeRightTop.y, result[0].faceLandmarks.eyeRightOuter.x, result[0].faceLandmarks.eyeRightBottom.y)) { List<UUID> faceIds = new ArrayList<>(); for (Face face : result) { faceIds.add(face.faceId); } identifyTask.execute(faceIds.toArray(new UUID[faceIds.size()])); //showToast("Human"); } else { showToast("Photo"); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getActivity().getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } } } }; detectTask.execute(inputStream); }
From source file:org.cryptsecure.Utility.java
/** * Notfiy alarm. alarmType == RingtoneManager.TYPE_ALARM | * RingtoneManager.TYPE_NOTIFICATION | RingtoneManager.TYPE_RINGTONE * // ww w. j a v a 2 s. co m * @param context * the context * @param alarmType * the alarm type */ public static void notfiyAlarm(Context context, final int alarmType) { final Ringtone ringtone = RingtoneManager.getRingtone(context, RingtoneManager.getDefaultUri(alarmType)); new Thread(new Runnable() { public void run() { ringtone.play(); } }).start(); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Plays the default system notification ringtone. * /*from ww w. ja va 2 s . c o m*/ * @param context */ public static void media_soundPlayNotificationDefault(Context context) { try { Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, soundUri); r.play(); } catch (Exception e) { if (LOG_ENABLE) { Log.e(TAG, "Error playing default notification sound (" + e.getMessage() + ")", e); } } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Plays the specified ringtone from the application raw folder. * /* ww w .j av a 2 s . co m*/ * @param appPackage Application package. (you can get it by using: * AppVigilant.thiz.getApplicationContext().getPackageName()) * @param soundResourceId Sound resource id */ public static void media_soundPlayFromRawFolder(Context context, String appPackage, int soundResourceId) { try { Uri soundUri = Uri.parse("android.resource://" + appPackage + "/" + soundResourceId); Ringtone r = RingtoneManager.getRingtone(context, soundUri); r.play(); } catch (Exception e) { if (LOG_ENABLE) { Log.e(TAG, "Error playing sound with resource id: '" + soundResourceId + "' (" + e.getMessage() + ")", e); } } }
From source file:edu.rit.csh.androidwebnews.UpdaterService.java
/** * The IntentService calls this method from the default worker thread with * the intent that started the service. When this method returns, IntentService * stops the service, as appropriate./*from w ww .j a v a2 s .c o m*/ */ @Override protected void onHandleIntent(Intent intent) { Vibrator mVibrator; Uri notification; Ringtone r; SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); HttpsConnector hc = new HttpsConnector(this); int[] statuses; try { statuses = hc.getUnreadCount(); // throws all the errors // if there are WebNews new posts and that number is different than last time the update ran if (statuses[0] != 0 && statuses[0] != sharedPref.getInt("number_of_unread", 0)) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("number_of_unread", statuses[0]); editor.commit(); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(getString(R.string.app_name)); builder.setSmallIcon(R.drawable.notification_icon); builder.setAutoCancel(true); if (statuses[2] != 0) { if (statuses[2] == 1) { builder.setContentText(statuses[2] + " reply to your post"); } else { builder.setContentText(statuses[2] + " reply to your posts"); } } else if (statuses[1] != 0) { if (statuses[1] == 1) { builder.setContentText(statuses[1] + " unread post in your thread"); } else { builder.setContentText(statuses[1] + " unread posts in your thread"); } } else { if (statuses[0] == 1) { builder.setContentText(statuses[0] + " unread post"); } else { builder.setContentText(statuses[0] + " unread posts"); } } if (sharedPref.getBoolean("vibrate_service", true)) { mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); mVibrator.vibrate(500); } if (sharedPref.getBoolean("ring_service", false)) { notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } // Creates an explicit intent for an Activity in your app /* 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. */ // notification is selected Intent notificationIntent = new Intent(this, RecentActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); // Add as notification NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(0, builder.build()); } else if (statuses[0] == 0) { // if all post have been read /* if a user reads all the posts, the notification is removed */ NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.cancel(0); } } catch (InvalidKeyException e) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle(getString(R.string.app_name)); mBuilder.setSmallIcon(R.drawable.notification_icon); mBuilder.setContentText("Invalid API Key"); mBuilder.setAutoCancel(true); Intent resultIntent = new Intent(this, SettingsActivity.class); TaskStackBuilder stackBuilder; try { stackBuilder = TaskStackBuilder.create(this); } catch (Exception e1) { return; } // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(SettingsActivity.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) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } catch (NoInternetException e) { // do nothing if there is no internet for the background service } catch (InterruptedException e) { // normally never hit } catch (ExecutionException e) { // normally never hit } }
From source file:edu.mit.viral.shen.DroidFish.java
/** * Plays device's default notification sound * *//* ww w . java2 s . c om*/ public void playBeep() { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { e.printStackTrace(); } }