List of usage examples for android.media Ringtone play
public void play()
From source file:es.gaedr_space.puntogpsqr.QRVisorFragment.java
/** * Mtodo que se lanza cada vez que se encuentra un resultado para su manejo * * @param result que contiene el contenido del QR *///from w w w . j av a 2 s .com @Override public void handleResult(Result result) { try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getActivity().getApplicationContext(), notification); r.play(); } catch (Exception e) { Log.d(TAG, getContext().getString(R.string.error_sound) + " : " + e.getMessage()); } if (transforStringToCoordinates(result.getText())) { GPS = new GPSService(getActivity()); if (GPS.canGetLocation()) { mSiteLocation.save(); DialogFragment dialog = new DialogFragment() { @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(getString(R.string.dialog_message, mSiteLocation.getLatitude(), mSiteLocation.getLongitude())); builder.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (!mSiteLocation.isEmpty()) { startActivity(mapsLauncher(mSiteLocation, GPS.getSiteLocation())); } mSiteLocation = null; dismiss(); } }); builder.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { mSiteLocation = null; dismiss(); } }); builder.setCancelable(false); return builder.create(); } @Override public void onPause() { mSiteLocation = null; super.onPause(); } @Override public void onDetach() { mSiteLocation = null; super.onDetach(); } }; dialog.show(getActivity().getSupportFragmentManager(), "dialog"); } else { showSettingsAlert(getActivity()); } } mScannerView.resumeCameraPreview(this); }
From source file:com.tessoft.nearhere.GcmIntentService.java
private void sendNotification(Bundle extras) { String title = extras.getString("title"); String type = extras.getString("type"); String msg = extras.getString("message"); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setAutoCancel(true);//ww w.j a v a 2s.c o m Intent intent = null; boolean isActive = false; // check if background // ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE ); // List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses(); // for(int i = 0; i < procInfos.size(); i++) // { // if(procInfos.get(i).processName.equals("com.tessoft.nearhere")) // isActive = true; // } // check if foreground ActivityManager activityManager = (ActivityManager) getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> services = activityManager.getRunningTasks(Integer.MAX_VALUE); if (services.get(0).topActivity.getPackageName().toString() .equalsIgnoreCase(getApplicationContext().getPackageName().toString())) { isActive = true; } if (isActive) { intent = new Intent("updateUnreadCount"); intent.putExtra("type", type); if ("message".equals(type)) { intent.putExtra("fromUserID", extras.getString("fromUserID")); Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(500); } else if ("postReply".equals(type)) { intent.putExtra("postID", extras.getString("postID")); Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(500); } getApplicationContext().sendBroadcast(intent); } else { if ("message".equals(type)) { intent = new Intent(this, UserMessageActivity.class); HashMap hash = new HashMap(); hash.put("fromUserID", extras.getString("fromUserID")); hash.put("userID", extras.getString("toUserID")); intent.putExtra("messageInfo", hash); mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); mBuilder.setVibrate(new long[] { 1000, 1000 }); } else if ("postReply".equals(type)) { intent = new Intent(this, TaxiPostDetailActivity.class); intent.putExtra("postID", extras.getString("postID")); mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); mBuilder.setVibrate(new long[] { 1000, 1000 }); } else if ("newPostByDistance".equals(type)) { intent = new Intent(this, TaxiPostDetailActivity.class); intent.putExtra("postID", extras.getString("postID")); } else if ("event".equals(type)) { intent = new Intent(this, EventViewerActivity.class); intent.putExtra("eventSeq", extras.getString("eventSeq")); intent.putExtra("pushNo", extras.getString("pushNo")); if ("on".equals(extras.getString("sound"))) mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); if ("on".equals(extras.getString("vibrate"))) mBuilder.setVibrate(new long[] { 1000, 1000 }); } else if ("eventssl".equals(type)) { intent = new Intent(this, EventViewerActivity.class); intent.putExtra("eventSeq", extras.getString("eventSeq")); intent.putExtra("pushNo", extras.getString("pushNo")); intent.putExtra("ssl", "true"); if ("on".equals(extras.getString("sound"))) mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); if ("on".equals(extras.getString("vibrate"))) mBuilder.setVibrate(new long[] { 1000, 1000 }); } else { intent = new Intent(this, MainActivity.class); } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } }
From source file:com.example.android.pantry.scanner.BarcodeScannerActivity.java
@Override public void handleResult(Result rawResult) { try {/*from ww w .ja v a 2 s . co m*/ Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play(); } catch (Exception e) { Log.e(TAG, e.getMessage()); e.printStackTrace(); } mLastBarcodeValue = rawResult.getText(); mLastBarcodeType = rawResult.getBarcodeFormat().toString(); PantryDbHelper dbHelper = new PantryDbHelper(this); mDb = dbHelper.getWritableDatabase(); String productInfo = ""; String quantityString = ""; mLastInventoryItem = null; Barcode barcode = BarcodesTable.getBarcodeByValue(mDb, mLastBarcodeValue); if (barcode == null) { String message = "Product not found.\nSearch the big product database?"; showSearchDialog(message); } else { productInfo = barcode.getProduct().getBrand() + " " + barcode.getProduct().getName(); long productId = barcode.getProduct().getProductId(); buildInventoryItemAndShowMessageDialog(productInfo, barcode.getProduct(), productId); } }
From source file:com.ariesmcrae.mymemories.ui.story.StoryViewFragment.java
public void setUiToStoryData(long getUniqueKey) throws RemoteException { Log.d(LOG_TAG, "setUiToStoryData"); storyData = resolver.getStoryDataViaRowID(getUniqueKey); if (storyData == null) { getView().setVisibility(View.GONE); } else { // else it just displays empty screen Log.d(LOG_TAG, "setUiToStoryData + storyData:" + storyData.toString()); titleTV.setText(String.valueOf(storyData.title).toString()); bodyTV.setText(String.valueOf(storyData.body).toString()); audioButton.setOnClickListener(new OnClickListener() { @Override/*from w w w . jav a 2 s .co m*/ public void onClick(View v) { String audioLinkPath = String.valueOf(storyData.audioLink).toString(); if (audioLinkPath != null && audioLinkPath.length() > 0) { Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), Uri.parse(audioLinkPath)); if (!ringtone.isPlaying()) { ringtone.play(); } } } }); // Display the video String videoLinkPath = String.valueOf(storyData.videoLink).toString(); if (videoLinkPath != null && videoLinkPath.length() > 0) { MediaController mediaController = new MediaController(getActivity()); mediaController.setAnchorView(videoLinkView); videoLinkView.setMediaController(mediaController); videoLinkView.setVideoURI(Uri.parse(videoLinkPath)); if (!videoLinkView.isPlaying()) { videoLinkView.start(); } } // Display the image data imageNameTV.setText(String.valueOf(storyData.imageName).toString()); String imageMetaDataPath = String.valueOf(storyData.imageLink).toString(); imageMetaDataView.setImageURI(Uri.parse(imageMetaDataPath)); Long time = Long.valueOf(storyData.storyTime); storyTimeTV.setText(StoryData.FORMAT.format(time)); latitudeTV.setText(Double.valueOf(storyData.latitude).toString()); longitudeTV.setText(Double.valueOf(storyData.longitude).toString()); } }
From source file:de.j4velin.chess.Main.java
@Override public void onTurnBasedMatchReceived(final TurnBasedMatch match) { if (BuildConfig.DEBUG) Logger.log("Main onTurnBasedMatchReceived: " + match.getMatchId()); if (match.getTurnStatus() == TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN && match.getStatus() == TurnBasedMatch.MATCH_STATUS_ACTIVE) { final Ringtone tone = RingtoneManager.getRingtone(this, RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION)); tone.setStreamType(AudioManager.STREAM_NOTIFICATION); tone.play(); }//from w w w . ja v a 2s. co m if (startFragment != null && startFragment.isVisible()) { startFragment.loadMatches(); } if (gameFragment != null && gameFragment.isVisible() && match.getMatchId().equals(gameFragment.currentMatch)) { if (Game.load(match.getData(), match, mGoogleApiClient)) { gameFragment.update(match.getStatus() != TurnBasedMatch.MATCH_STATUS_ACTIVE && match.getStatus() != TurnBasedMatch.MATCH_STATUS_AUTO_MATCHING); } else { updateApp(); } } }
From source file:com.phonegap.Notification.java
/** * Beep plays the default notification ringtone. * /*from w w w . java2 s . c om*/ * @param count Number of times to play notification */ public void beep(long count) { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(this.ctx, 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:org.skt.runtime.original.Notification.java
/** * Beep plays the default notification ringtone. * // ww w . j a va 2s .c o m * @param count Number of times to play notification */ public void beep(long count) { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(this.ctx.getContext(), 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.getkickbak.plugin.NotificationPlugin.java
/** * Beep plays the default notification ringtone. * /* w w w .ja v a 2s. c om*/ * @param count * Number of times to play notification */ public void beep(long count) { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(this.cordova.getActivity().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:shetye.prathamesh.notifyme.Utilities.java
public void generateNotification(Context context, int ID, String title, String message, boolean isOngoing) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, NotifyMe.class); notificationIntent.setData(Uri.parse(Integer.toString(ID))); notificationIntent.putExtra(Utilities.NOTIF_EXTRA_ID_KEY, ID); notificationIntent.putExtra(Utilities.NOTIF_EXTRA_KEY, message); notificationIntent.putExtra(Utilities.NOTIF_EXTRA_TITLE_KEY, title); Intent laterIntent = new Intent(context, NotificationDetail.class); laterIntent.setData(Uri.parse(Integer.toString(ID))); laterIntent.putExtra(Utilities.NOTIF_EXTRA_ID_KEY, ID); laterIntent.putExtra(Utilities.NOTIF_EXTRA_DONE_LATER_KEY, true); Intent doneIntent = new Intent(context, RecieveAndNotify.class); doneIntent.setData(Uri.parse(Integer.toString(ID))); doneIntent.setAction(NOTIF_SERVICE_DONE_ACTION); doneIntent.putExtra(Utilities.NOTIF_EXTRA_ID_KEY, ID); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent remindLaterIntent = PendingIntent.getActivity(context, 0, laterIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent completedIntent = PendingIntent.getBroadcast(context, 0, doneIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String newTitle;/*from ww w . j av a 2 s . co m*/ if (title == null || title.isEmpty()) newTitle = context.getResources().getString(R.string.app_name); else newTitle = title; inboxStyle.setBigContentTitle(newTitle); inboxStyle.addLine(message); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notif).setContentTitle(newTitle).setContentText(message) .setPriority(NotificationCompat.PRIORITY_MAX).setContentIntent(resultPendingIntent) .addAction(R.drawable.ic_restore, "Later", remindLaterIntent) .addAction(R.drawable.ic_done, "Done", completedIntent).setStyle(inboxStyle); Log.d(LOG_TAG, "Notifying for ID : " + ID); notificationManager.notify(ID, mBuilder.build()); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, notification); Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 300 milliseconds v.vibrate(200); r.play(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.cordova.dialogs.Notification.java
/** * Beep plays the default notification ringtone. * * @param count Number of times to play notification *//*from w w w . ja va 2 s.c o m*/ public void beep(final long count) { cordova.getThreadPool().execute(new Runnable() { public void run() { Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone notification = RingtoneManager.getRingtone(cordova.getActivity().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) { } } } } } }); }