List of usage examples for android.media RingtoneManager getRingtone
public static Ringtone getRingtone(final Context context, Uri ringtoneUri)
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;/*ww w. j a va2 s . co 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); }
From source file:com.example.volunteerhandbook.GcmIntentService.java
void makeNoise() { boolean toRing = false; String fileName = MainActivity.getFileHeader() + ProfilePage.getTableName(); SharedPreferences mem = getSharedPreferences(fileName, Context.MODE_PRIVATE); String sRing = mem.getString(ProfileActivity.CURRENT_RINGTON, "--");//, String); if (sRing.charAt(0) == '-') return;/*w w w . j av a 2 s . c o m*/ Uri ringUri = Uri.parse(sRing);//, String); String t0 = mem.getString(ProfileActivity.NO_NOISE_START, "--");//, noNoiseStart); String t1 = mem.getString(ProfileActivity.NO_NOISE_END, "--");//, noNoiseEnd); String[] sT0 = t0.split(":"); int h0 = Integer.parseInt(sT0[0]); int m0 = Integer.parseInt(sT0[1]); sT0 = t1.split(":"); int h1 = Integer.parseInt(sT0[0]); int m1 = Integer.parseInt(sT0[1]); Time tm = new Time(); int iNow = tm.hour * 60 + tm.minute; int iU = h1 * 60 + m1; int iL = h0 * 60 + m0; if (h1 < h0) { toRing = (iNow > iU && iNow < iL); } else toRing = (iNow > iU || iNow < iL); //android.os.Debug.waitForDebugger(); if (toRing) { noise = RingtoneManager.getRingtone(getApplicationContext(), ringUri); noise.play(); } else noise = null; }
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);//from w w w . ja v a 2 s. com 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.google.android.apps.chrometophone.C2DMReceiver.java
private void playNotificationSound(Context context) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (uri != null) { Ringtone rt = RingtoneManager.getRingtone(context, uri); if (rt != null) rt.play();/*www. j ava 2s . c o m*/ } }
From source file:org.proninyaroslav.libretorrent.settings.AppearanceSettingsFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_ALERT_RINGTONE && data != null) { Uri ringtone = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); if (ringtone != null) { SettingsManager pref = new SettingsManager(getActivity().getApplicationContext()); String keyNotifySound = getString(R.string.pref_key_notify_sound); Preference notifySound = findPreference(keyNotifySound); notifySound.setSummary(RingtoneManager.getRingtone(getActivity().getApplicationContext(), ringtone) .getTitle(getActivity().getApplicationContext())); pref.put(keyNotifySound, ringtone.toString()); }//from w w w . j a v a2 s . c o m } else { super.onActivityResult(requestCode, resultCode, data); } }
From source file:com.example.android.pantry.scanner.BarcodeScannerActivity.java
@Override public void handleResult(Result rawResult) { try {//from w w w.j a v a 2 s . c om 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:net.sf.sprockets.app.ui.SprocketsPreferenceFragment.java
/** * Set the preference's value(s) as its summary. *///from w w w.j a v a2 s . c o m protected void setSummary(Preference pref) { SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); if (pref instanceof RingtonePreference) { String val = prefs.getString(pref.getKey(), null); if (!TextUtils.isEmpty(val)) { Ringtone tone = RingtoneManager.getRingtone(a, Uri.parse(val)); if (tone != null) { pref.setSummary(tone.getTitle(a)); } } else { pref.setSummary(R.string.none); } } else if (pref instanceof MultiSelectListPreference) { Set<String> vals = prefs.getStringSet(pref.getKey(), null); if (vals != null) { if (!vals.isEmpty()) { MultiSelectListPreference multi = (MultiSelectListPreference) pref; IntList indexList = new ArrayIntList(vals.size()); for (String val : vals) { // find selected entry indexes int i = multi.findIndexOfValue(val); if (i >= 0) { indexList.add(i); } } int[] indexes = indexList.toArray(); Arrays.sort(indexes); // to display in same order as dialog pref.setSummary(TextUtils.join(getString(R.string.delimiter), Elements.slice(multi.getEntries(), indexes))); } else { pref.setSummary(R.string.none); } } } else if (pref instanceof EditTextPreference) { pref.setSummary(prefs.getString(pref.getKey(), null)); } else if (pref.getClass() == Preference.class) { String val = prefs.getString(pref.getKey(), null); if (!TextUtils.isEmpty(val)) { // don't clear existing summary pref.setSummary(val); } } }
From source file:org.easyaccess.phonedialer.CallStateService.java
/** * Plays the ringtone associated with the number passed as a parameter. * /*from ww w.j a va 2s.co m*/ * @param number * The number associated with the incoming call. */ void playRingtone(String number) { Uri queryUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); String[] columns = new String[] { ContactsContract.Contacts.CUSTOM_RINGTONE }; Cursor contactsCursor = getContentResolver().query(queryUri, columns, null, null, null); if (contactsCursor.moveToFirst()) { if (contactsCursor .getString(contactsCursor.getColumnIndex(ContactsContract.Contacts.CUSTOM_RINGTONE)) == null) { // no custom ringtone has been set Utils.ringtone = RingtoneManager.getRingtone(getBaseContext(), Settings.System.DEFAULT_RINGTONE_URI); Utils.ringtone.play(); } else { Utils.ringtone = RingtoneManager.getRingtone(getBaseContext(), Uri.parse(contactsCursor .getString(contactsCursor.getColumnIndex(ContactsContract.Contacts.CUSTOM_RINGTONE)))); Utils.ringtone.play(); } } }
From source file:com.brq.wallet.lt.activity.LtMainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); _mbwManager = MbwManager.getInstance(this); _ltManager = _mbwManager.getLocalTraderManager(); _viewPager = new ViewPager(this); _viewPager.setId(R.id.pager);// w w w . ja v a 2 s.com setContentView(_viewPager); ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // to provide up navigation from actionbar, in case the modern main // activity is not on the stack actionBar.setDisplayHomeAsUpEnabled(true); TabsAdapter tabsAdapter = new TabsAdapter(this, _viewPager); // Add Buy Bitcoin tab _myBuyBitcoinTab = actionBar.newTab(); _myBuyBitcoinTab.setText(getResources().getString(R.string.lt_buy_bitcoin_tab)); tabsAdapter.addTab(_myBuyBitcoinTab, AdSearchFragment.class, AdSearchFragment.createArgs(true)); // Add Sell Bitcoin tab _mySellBitcoinTab = actionBar.newTab(); _mySellBitcoinTab.setText(getResources().getString(R.string.lt_sell_bitcoin_tab)); tabsAdapter.addTab(_mySellBitcoinTab, AdSearchFragment.class, AdSearchFragment.createArgs(false)); // Add Active Trades tab _myActiveTradesTab = actionBar.newTab(); _myActiveTradesTab.setText(getResources().getString(R.string.lt_active_trades_tab)); tabsAdapter.addTab(_myActiveTradesTab, ActiveTradesFragment.class, null); // Add Historic Trades tab _myTradeHistoryTab = actionBar.newTab(); _myTradeHistoryTab.setText(getResources().getString(R.string.lt_trade_history_tab)); tabsAdapter.addTab(_myTradeHistoryTab, TradeHistoryFragment.class, null); // Add Ads tab _myAdsTab = actionBar.newTab(); _myAdsTab.setText(getResources().getString(R.string.lt_my_ads_tab)); _myAdsTab.setTag(tabsAdapter.getCount()); tabsAdapter.addTab(_myAdsTab, AdsFragment.class, null); // Add Trader Info tab _myTraderInfoTab = actionBar.newTab(); _myTraderInfoTab.setText(getResources().getString(R.string.lt_my_trader_info_tab)); _myTraderInfoTab.setTag(tabsAdapter.getCount()); tabsAdapter.addTab(_myTraderInfoTab, MyInfoFragment.class, null); // Load the tab to select from intent TAB_TYPE tabToSelect = TAB_TYPE.values()[getIntent().getIntExtra(TAB_TO_SELECT, TAB_TYPE.DEFAULT.ordinal())]; actionBar.selectTab(enumToTab(tabToSelect)); _updateSound = RingtoneManager.getRingtone(this, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); // Load saved state if (savedInstanceState != null) { _hasWelcomed = savedInstanceState.getBoolean("hasWelcomed", false); } }
From source file:io.relayr.tellmewhen.gcm.GcmIntentService.java
private void playSound() { if (playingSound) return;/* ww w. j a v a 2s.c o m*/ playingSound = true; Handler mHandler = new Handler(getMainLooper()); mHandler.post(new Runnable() { @Override public void run() { Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); RingtoneManager.getRingtone(getApplicationContext(), sound).play(); playingSound = false; } }); }