Example usage for android.media RingtoneManager getRingtone

List of usage examples for android.media RingtoneManager getRingtone

Introduction

In this page you can find the example usage for android.media RingtoneManager getRingtone.

Prototype

public static Ringtone getRingtone(final Context context, Uri ringtoneUri) 

Source Link

Document

Returns a Ringtone for a given sound URI.

Usage

From source file:com.getkickbak.plugin.NotificationPlugin.java

/**
 * Beep plays the default notification ringtone.
 * /*from  w ww . j a v  a2 s .  co  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.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:es.reprogramador.util.notificationHelper.java

/**
 * Play the default "ding" sound//from  w w w  . java2s  .c o  m
 */
private void playNotificationSound() {
    try {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(_context.getApplicationContext(), notification);
        r.play();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.droidanalyst.app.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_hamburger).setContentTitle("Server Prediction")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
    r.play();/*ww  w.ja v  a  2s  .co  m*/
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.phonegap.Notification.java

/**
 * Beep plays the default notification ringtone.
 * /*from   ww  w. j a 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.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: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  . ja  v  a  2  s .c o  m*/

    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:com.yojiokisoft.yumekanow.activity.MainActivity.java

/**
 * ?? (onCreate?????/*  w w w  .  j av  a 2 s  .  co m*/
 */
@AfterViews
/*package*/void initActivity() {
    // ?????????
    Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());

    SettingDao settingDao = SettingDao.getInstance();

    // px -> dp ?
    if (!settingDao.getConvDpFlag()) {
        convPx2Dp();
        settingDao.setConvDpFlag(true);
    }

    if (MyAlarmManager.getStartTime() == 0 && MyAlarmManager.getWakeUpTime() == 0) {
        MyAlarmManager.setStartTimer(this);
    }

    FragmentManager manager = getSupportFragmentManager();
    mTabHost.setup();
    final MainPagerAdapter adapter = new MainPagerAdapter(manager, this, mTabHost, mPager);

    // tab size from screen size
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int tabWidth = metrics.widthPixels / 3;
    int tabHeight = metrics.widthPixels / 7;

    String tabTitle[] = new String[3];
    tabTitle[0] = getString(R.string.tab_title1);
    tabTitle[1] = getString(R.string.tab_title2);
    tabTitle[2] = getString(R.string.tab_title3);
    for (int i = 0; i < tabTitle.length; i++) {
        TabSpec spec = mTabHost.newTabSpec("tab" + i);
        spec.setIndicator(getTabView(tabWidth, tabHeight, tabTitle[i]));
        adapter.addTab(spec, "tab" + i);
    }

    if ("Timer".equals(mFireEvent)) {
        if (settingDao.getVibrator()) {
            mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
            long[] pattern = { 0, 500, 250, 500, 250, 500 }; // OFF/ON/OFF/ON...
            mVibrator.vibrate(pattern, -1);
        }

        String url = settingDao.getAlarmUrl();
        if (url != null) {
            mRingtone = RingtoneManager.getRingtone(this, Uri.parse(url));
            mRingtone.play();
        }
    }
    mCloseByButtonClicked = false;
}

From source file:com.slodin.transalarm.GeofenceTransitionsIntentService.java

public void setOffAlarm() {
    Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
    // Vibrate for 1000 milliseconds
    v.vibrate(1000);// www. j ava 2 s .c  o  m
    r = RingtoneManager.getRingtone(this, notification);
    r.play();
}

From source file:org.apache.cordova.dialogs.Notification.java

/**
 * Beep plays the default notification ringtone.
 *
 * @param count     Number of times to play notification
 *///from www . ja v a2s.com
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) {
                        }
                    }
                }
            }
        }
    });
}

From source file:org.skt.runtime.original.Notification.java

/**
 * Beep plays the default notification ringtone.
 * /*from w ww  . j ava2s  . 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:org.isoron.uhabits.helpers.ReminderHelper.java

@Nullable
public static String getRingtoneName(Context context) {
    try {// ww w .j  ava2s. c o m
        Uri ringtoneUri = getRingtoneUri(context);
        String ringtoneName = context.getResources().getString(R.string.none);

        if (ringtoneUri != null) {
            Ringtone ringtone = RingtoneManager.getRingtone(context, ringtoneUri);
            if (ringtone != null) {
                ringtoneName = ringtone.getTitle(context);
                ringtone.stop();
            }
        }

        return ringtoneName;
    } catch (RuntimeException e) {
        e.printStackTrace();
        return null;
    }
}