List of usage examples for android.media RingtoneManager TYPE_ALARM
int TYPE_ALARM
To view the source code for android.media RingtoneManager TYPE_ALARM.
Click Source Link
From source file:net.xisberto.work_schedule.alarm.AlarmMessageActivity.java
private Uri getAlarmUri() { String ringtone = settings.getRingtone(); Uri alert = null;//from www .j a v a 2 s . c o m if (ringtone != null) { alert = Uri.parse(ringtone); } else { alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (alert == null) { alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); } } } return alert; }
From source file:com.licenta.android.licenseapp.location.GeofenceTransitionsService.java
private void sendNotification(String msg) { NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); Intent intentDismiss = new Intent(this, MainTabActivity.class); intentDismiss.putExtra(Constants.KEY_NOTIFICATION_ID, Constants.ALARM_ID); intentDismiss.putExtra(Constants.KEY_DISMISS_ALARM, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intentDismiss, PendingIntent.FLAG_UPDATE_CURRENT); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("HellO") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setCategory(Notification.CATEGORY_ALARM).setSound(alarmSound); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); mBuilder.setSound(Uri.parse(prefs.getString("alarm_ringtone", ""))); if (prefs.getBoolean("alarm_vibrate", false)) mBuilder.setVibrate(new long[] { 1000, 1000 }); mBuilder.addAction(0, getString(R.string.check_in), pendingIntent); mBuilder.addAction(R.drawable.ic_stat_action_alarm_off_notif, getString(R.string.dismiss_alarm), pendingIntent);/*from ww w . ja v a2 s . c om*/ //mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(Constants.ALARM_ID, mBuilder.build()); }
From source file:com.meiste.tempalarm.ui.Alarm.java
@Override protected void onResume() { super.onResume(); final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // do not play alarms if stream volume is 0 (typically because ringer mode is silent). if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) { final Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); mMediaPlayer = new MediaPlayer(); mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { public boolean onError(final MediaPlayer mp, final int what, final int extra) { Timber.e("Error occurred while playing audio."); mp.stop();/*ww w . j av a 2s . c o m*/ mp.reset(); mp.release(); mMediaPlayer = null; return true; } }); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); try { mMediaPlayer.setDataSource(this, alert); mMediaPlayer.setLooping(true); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (final IOException e) { Timber.e("Failed to play alarm tone: %s", e); } } mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); mVibrator.vibrate(sVibratePattern, 0); mPlaying = true; mHandler.sendEmptyMessageDelayed(KILLER, ALARM_TIMEOUT); }
From source file:nl.johndekroon.dma.GCMIntentService.java
@Override protected void onMessage(Context context, Intent intent) { prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); prefs.getBoolean("muteAll", false); String data = intent.getStringExtra("message"); JSONObject datajson;// ww w .j a va 2 s . c o m try { datajson = new JSONObject(data); String message = datajson.get("message").toString(); String type = datajson.get("type").toString(); String monitor = datajson.get("monitor").toString(); DatabaseDAO datasource = new DatabaseDAO(this); datasource.open(); //On getting a warning or an OK if (type.equals("WARNING") || type.equals("OK")) { if (prefs.getBoolean("muteAll", false) != true) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 500, 200, 200 }; // Only perform this pattern one time (-1 means "do not repeat") v.vibrate(pattern, -1); Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { // I can't see this ever being null (as always have a default notification) but just incase // alert backup is null, using 2nd backup alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alert); r.play(); } datasource.updateScenario(monitor, type); generateNotification(context, message); } //on receiving an error else if (type.equals("ERROR")) { System.out.println("bbbrrrrrrr brrrrrr"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 1000, 50, 200, 50, 200, 50, 1200 }; // Only perform this pattern one time (-1 means "do not repeat") v.vibrate(pattern, -1); if (prefs.getBoolean("muteAll", false) != true) { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alert); r.play(); } datasource.updateScenario(monitor, type); generateNotification(context, message); } //on register, make a new scenario. else if (type.equals("REGISTER")) { datasource.createScenario(monitor); } System.out.println(intent.getStringExtra("message")); Log.i(TAG, "Received message"); //No idea why this part isn't working. It should. // if(type.equals("ERROR")) // { // displayMessage(context, message, "error"); // } // else // { displayMessage(context, message); // } } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:nl.hnogames.domoticz.Utils.NotificationUtil.java
public static void sendSimpleNotification(String title, String text, final Context context) { if (UsefulBits.isEmpty(title) || UsefulBits.isEmpty(text) || context == null) return;// w w w. jav a 2 s.c o m if (prefUtil == null) prefUtil = new SharedPrefUtil(context); prefUtil.addUniqueReceivedNotification(text); prefUtil.addLoggedNotification(new SimpleDateFormat("yyyy-MM-dd hh:mm ").format(new Date()) + text); List<String> suppressedNot = prefUtil.getSuppressedNotifications(); List<String> alarmNot = prefUtil.getAlarmNotifications(); try { if (prefUtil.isNotificationsEnabled() && suppressedNot != null && !suppressedNot.contains(text)) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.domoticz_white) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher)) .setContentTitle(alarmNot != null && alarmNot.contains(text) ? context.getString(R.string.alarm) + ": " + title : title) .setContentText(alarmNot != null && alarmNot.contains(text) ? context.getString(R.string.alarm) + ": " + text : text) .setGroupSummary(true).setGroup(GROUP_KEY_NOTIFICATIONS).setAutoCancel(true); if (!prefUtil.OverWriteNotifications()) NOTIFICATION_ID = text.hashCode(); if (prefUtil.getNotificationVibrate()) builder.setDefaults(NotificationCompat.DEFAULT_VIBRATE); if (!UsefulBits.isEmpty(prefUtil.getNotificationSound())) builder.setSound(Uri.parse(prefUtil.getNotificationSound())); Intent targetIntent = new Intent(context, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); if (prefUtil.isNotificationsEnabled() && alarmNot != null && alarmNot.contains(text)) { Intent stopAlarmIntent = new Intent(context, StopAlarmButtonListener.class); PendingIntent pendingAlarmIntent = PendingIntent.getBroadcast(context, 78578, stopAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(android.R.drawable.ic_delete, "Stop", pendingAlarmIntent); } if (prefUtil.showAutoNotifications()) { builder.extend(new NotificationCompat.CarExtender() .setUnreadConversation(getUnreadConversation(context, text))); } NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, builder.build()); if (prefUtil.isNotificationsEnabled() && alarmNot != null && alarmNot.contains(text)) { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (alert == null) { alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); } if (alert != null) { Intent ringtoneServiceStartIntent = new Intent(context, RingtonePlayingService.class); ringtoneServiceStartIntent.putExtra("ringtone-uri", alert.toString()); context.startService(ringtoneServiceStartIntent); if (prefUtil.getAlarmTimer() > 0) { Thread.sleep(prefUtil.getAlarmTimer() * 1000); Intent stopIntent = new Intent(context, RingtonePlayingService.class); context.stopService(stopIntent); } } } } } catch (Exception ex) { Log.i("NOTIFY", ex.getMessage()); } }
From source file:com.apps.howard.vicissitude.services.NotificationService.java
private Uri getAlarmTone() { return Uri.parse(prefs.getString(getString(R.string.pref_sound_alarm_tone_key), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM).toString())); }
From source file:jp.realglobe.sugo.actor.android.hitoe.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ?? actor ID ?? final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final String actorSuffix = preferences.getString(getString(R.string.key_actor_suffix), null); if (actorSuffix == null) { preferences.edit().putString(getString(R.string.key_actor_suffix), String.valueOf(Math.abs((new Random(System.nanoTime())).nextInt()))).apply(); }/* w w w. j av a2 s .c om*/ this.vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); this.ringtone = RingtoneManager.getRingtone(this, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)); this.googleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(@Nullable Bundle bundle) { if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } LocationServices.FusedLocationApi.requestLocationUpdates(MainActivity.this.googleApiClient, LocationRequest.create().setInterval(LOCATION_INTERVAL) .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY), location -> { MainActivity.this.location = location; Log.d(LOG_TAG, "Location changed to " + location); }); Log.d(LOG_TAG, "Location monitor started"); } @Override public void onConnectionSuspended(int i) { Log.d(LOG_TAG, "Location monitor suspended"); } }).addOnConnectionFailedListener(connectionResult -> { final String warning = "Location detection error: " + connectionResult; MainActivity.this.warningView.post(() -> setWarning(warning)); Log.w(LOG_TAG, warning); }).build(); hitoe = new HitoeWrapper(HitoeSdkAPIImpl.getInstance(this.getApplicationContext())); hitoe.setHeartrateReceiver(() -> { synchronized (this) { // ?? hitoe ??????? if (!this.hitoeReady) { this.hitoeReady = true; handler.post(() -> { synchronized (this) { if (this.hitoeReady) { this.disableHitoeSetting(); } } }); } } }, (date, heartrate) -> { this.heartrate = new Pair<>(date, heartrate); this.heartrateView.post(() -> this.heartrateView.setText(String.format(Locale.US, "%d", heartrate))); }); hitoe.setDisconnectCallback(() -> { synchronized (this) { // ?? hitoe ??????? this.hitoeReady = false; handler.post(() -> { synchronized (this) { if (!this.hitoeReady) { this.enableHitoeSetting(); } } }); } }); this.handler = new Handler(); this.timer = new Handler(); this.heartrate = new Pair<>(0L, 0); // ?? reset(); // ??????????? checkPermission(); }
From source file:it.interfree.leonardoce.bootreceiver.AlarmKlaxon.java
private void play() { // stop() checks to see if we are already playing. stop();/*from ww w. ja v a 2s. c om*/ if (LOGV) { Log.v(LTAG, "AlarmKlaxon.play() "); } Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); if (LOGV) { Log.v(LTAG, "Using default alarm: " + alert.toString()); } // TODO: Reuse mMediaPlayer instead of creating a new one and/or use // RingtoneManager. mMediaPlayer = new MediaPlayer(); mMediaPlayer.setOnErrorListener(new OnErrorListener() { public boolean onError(MediaPlayer mp, int what, int extra) { Log.e(LTAG, "Error occurred while playing audio."); mp.stop(); mp.release(); mMediaPlayer = null; return true; } }); try { // Check if we are in a call. If we are, use the in-call alarm // resource at a low volume to not disrupt the call. mMediaPlayer.setDataSource(this, alert); startAlarm(mMediaPlayer); } catch (Exception ex) { Log.v(LTAG, "Non trovo la suoneria dell'allarme???"); } /* Start the vibrator after everything is ok with the media player */ mVibrator.vibrate(sVibratePattern, 0); mPlaying = true; mStartTime = System.currentTimeMillis(); enableKiller(); }
From source file:org.cyanogenmod.theme.chooser.AudiblePreviewFragment.java
private void loadAudibles() { mContent.removeAllViews();//from www .jav a 2 s . c om if (ThemeConfig.SYSTEM_DEFAULT.equals(mPkgName)) { loadSystemAudible(RingtoneManager.TYPE_ALARM); loadSystemAudible(RingtoneManager.TYPE_NOTIFICATION); loadSystemAudible(RingtoneManager.TYPE_RINGTONE); } else { try { final Context themeCtx = getActivity().createPackageContext(mPkgName, 0); PackageInfo pi = getActivity().getPackageManager().getPackageInfo(mPkgName, 0); loadThemeAudible(themeCtx, RingtoneManager.TYPE_ALARM, pi); loadThemeAudible(themeCtx, RingtoneManager.TYPE_NOTIFICATION, pi); loadThemeAudible(themeCtx, RingtoneManager.TYPE_RINGTONE, pi); } catch (PackageManager.NameNotFoundException e) { return; } } }
From source file:com.example.mapdemo.MyLocationDemoActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { instance = this; super.onCreate(savedInstanceState); setContentView(R.layout.my_location_demo); ButterKnife.bind(this); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(map); mapFragment.getMapAsync(this); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return;//from w w w.j a v a 2 s .c o m } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, new PositionListener()); alarm = RingtoneManager.getRingtone(getApplicationContext(), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)); handler.postDelayed(new Runnable() { @Override public void run() { createDialogForProgrammedStop(); handler.postDelayed(this, Constants.TIME); } }, Constants.TIME); }