當前位置: 首頁>>代碼示例>>Java>>正文


Java Ringtone類代碼示例

本文整理匯總了Java中android.media.Ringtone的典型用法代碼示例。如果您正苦於以下問題:Java Ringtone類的具體用法?Java Ringtone怎麽用?Java Ringtone使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Ringtone類屬於android.media包,在下文中一共展示了Ringtone類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setPowerNotificationRingtone

import android.media.Ringtone; //導入依賴的package包/類
private void setPowerNotificationRingtone(Intent intent) {
    final Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

    final String toneName;
    final String toneUriPath;

    if ( uri != null ) {
        final Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), uri);
        toneName = ringtone.getTitle(getActivity());
        toneUriPath = uri.toString();
    } else {
        // silent
        toneName = getString(R.string.power_notifications_ringtone_silent);
        toneUriPath = POWER_NOTIFICATIONS_SILENT_URI;
    }

    mPowerSoundsRingtone.setSummary(toneName);
    CMSettings.Global.putString(getContentResolver(),
            CMSettings.Global.POWER_NOTIFICATIONS_RINGTONE, toneUriPath);
}
 
開發者ID:ric96,項目名稱:lineagex86,代碼行數:21,代碼來源:OtherSoundSettings.java

示例2: handleDataReceived

import android.media.Ringtone; //導入依賴的package包/類
/**
 * Handles incoming data events from the mesh - toasts the contents of the data.
 *
 * @param e event object from mesh
 */
private void handleDataReceived(MeshManager.RightMeshEvent e) {
    final MeshManager.DataReceivedEvent event = (MeshManager.DataReceivedEvent) e;

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // Toast data contents.
            String message = new String(event.data);
            Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();

            // Play a notification.
            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(MainActivity.this, notification);
            r.play();
        }
    });
}
 
開發者ID:RightMesh,項目名稱:HelloMesh,代碼行數:23,代碼來源:MainActivity.java

示例3: beep

import android.media.Ringtone; //導入依賴的package包/類
/**
 * Beep plays the default notification ringtone.
 *
 * @param count     Number of times to play notification
 */
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) {
                            Thread.currentThread().interrupt();
                        }
                    }
                }
            }
        }
    });
}
 
開發者ID:Andy-Ta,項目名稱:COB,代碼行數:30,代碼來源:Notification.java

示例4: getRingtoneName

import android.media.Ringtone; //導入依賴的package包/類
@NonNull public static String getRingtoneName(@NonNull Context context, @Nullable Uri uri) {
    String title = context.getString(R.string.sound_chooser_summary);
    if (uri != null) {
        Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
        if (ringtone != null) {
            return ringtone.getTitle(context);
        } else {
            try (Cursor cur = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                    new String[]{MediaStore.Audio.Media.TITLE}, MediaStore.Audio.Media._ID + " =?",
                    new String[]{uri.getLastPathSegment()}, null)) {
                if (cur != null) {
                    title = cur.getString(1);
                    if (InputHelper.isEmpty(title)) {
                        title = cur.getString(cur.getColumnIndex(MediaStore.Audio.Media.TITLE));
                    }
                }
            } catch (Exception ignored) {}
        }
    }
    return title;
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:22,代碼來源:FileHelper.java

示例5: getRingtoneTitle

import android.media.Ringtone; //導入依賴的package包/類
private String getRingtoneTitle() {
    DebugLog.logMethod();
    String ringtoneUri = getPreferenceManager().getSharedPreferences().getString(
            KEY_NOTIFICATION_RINGTONE,
            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString()
    );
    Ringtone ringtone = RingtoneManager.getRingtone(getActivity(), Uri.parse(ringtoneUri));
    String ringtoneTitle = ringtone.getTitle(getActivity());
    // Prevent memory leaks
    ringtone.stop();

    return ringtoneTitle;
}
 
開發者ID:darsh2,項目名稱:CouponsTracker,代碼行數:14,代碼來源:SettingsFragment.java

示例6: handleChangePolicies

import android.media.Ringtone; //導入依賴的package包/類
private void handleChangePolicies(Application application) {
    SharedPreferences sharedPref = application.getSharedPreferences(
            application.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    Uri sound = getTone(sharedPref);
    if (notificationNeeded(application, sharedPref)) {
        Log.i("TTM", "Changes found. Would fire!");
        switch (sharedPref.getString("onChangeForm", "Banner")) {
            case "None":
                if (sound != null) {
                    Ringtone r = RingtoneManager.getRingtone(application.getApplicationContext(), sound);
                    r.play();
                }
                break;
            case "Banner":
                fireBanner(sound);
                break;
        }

    } else {
        Log.i("TTM", "Change check negative -> Won't fire any notification for change.");
    }
}
 
開發者ID:dhbw-timetable,項目名稱:dhbw-timetable-android,代碼行數:23,代碼來源:TimetableManager.java

示例7: maybePlaySound

import android.media.Ringtone; //導入依賴的package包/類
private void maybePlaySound() {
    if (mSoundEnabled &&
            (!mPowerManager.isInteractive() || !mSoundWhenScreenOffOnly)) {
        try {
            final Ringtone sfx = RingtoneManager.getRingtone(mContext,
                    Uri.parse(mSoundUri));
            if (sfx != null) {
                AudioAttributes attrs = new AudioAttributes.Builder()
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                        .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                        .build();
                sfx.setAudioAttributes(attrs);
                sfx.play();
            }
        } catch (Throwable t) {
            XposedBridge.log(t);
        }
    }
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:20,代碼來源:ProgressBarController.java

示例8: getRingtoneName

import android.media.Ringtone; //導入依賴的package包/類
/**
 * Get the title of the ringtone from the uri of ringtone.
 *
 * @param context instance of the caller
 * @param uri     uri of the tone to search
 * @return title of the tone or return null if no tone found.
 */
@Nullable
public static String getRingtoneName(@NonNull Context context,
                                     @NonNull Uri uri) {
    Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
    if (ringtone != null) {
        return ringtone.getTitle(context);
    } else {
        Cursor cur = context
                .getContentResolver()
                .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                        new String[]{MediaStore.Audio.Media.TITLE},
                        MediaStore.Audio.Media._ID + " =?",
                        new String[]{uri.getLastPathSegment()},
                        null);

        String title = null;
        if (cur != null) {
            title = cur.getString(cur.getColumnIndex(MediaStore.Audio.Media.TITLE));
            cur.close();
        }
        return title;
    }
}
 
開發者ID:kevalpatel2106,項目名稱:android-ringtone-picker,代碼行數:31,代碼來源:RingtoneUtils.java

示例9: initializeRingtonePreference

import android.media.Ringtone; //導入依賴的package包/類
private void initializeRingtonePreference() {
    Preference.OnPreferenceChangeListener ringtoneChangedListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            if ("".equals(value)) {
                preference.setSummary(R.string.silent);
            } else {
                Ringtone ringtone = RingtoneManager.getRingtone(ReminderPreferences.this, value == null
                        ? RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION)
                        : Uri.parse((String) value));
                preference.setSummary(ringtone == null ? "" : ringtone.getTitle(ReminderPreferences.this));
            }
            return true;
        }
    };

    String ringtoneKey = getString(R.string.p_rmd_ringtone);
    Preference ringtonePreference = findPreference(ringtoneKey);
    ringtonePreference.setOnPreferenceChangeListener(ringtoneChangedListener);
    ringtoneChangedListener.onPreferenceChange(ringtonePreference, PreferenceManager.getDefaultSharedPreferences(this)
            .getString(ringtoneKey, null));
}
 
開發者ID:andyCano,項目名稱:TaskApp,代碼行數:23,代碼來源:ReminderPreferences.java

示例10: onPreferenceChange

import android.media.Ringtone; //導入依賴的package包/類
@Override
public boolean onPreferenceChange(Preference preference, Object value) {
    String stringValue = value.toString();
    if (isListPreference(preference)) {
        ListPreference listPreference = (ListPreference) preference;
        int index = listPreference.findIndexOfValue(stringValue);
        preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null);

    } else if (isRingtonePreference(preference)) {
        if (TextUtils.isEmpty(stringValue)) {
            preference.setSummary(R.string.pref_ringtone_silent);
        } else {
            Ringtone ringtone = getRingtone(preference, stringValue);
            if (ringtone == null) {
                preference.setSummary(null);
            } else {
                preference.setSummary(getRingtoneTitle(preference, ringtone));
            }
        }

    } else {
        preference.setSummary(stringValue);
    }
    return true;
}
 
開發者ID:open-eid,項目名稱:MOPP-Android,代碼行數:26,代碼來源:ApplicationPreferenceChangeListener.java

示例11: shortPath

import android.media.Ringtone; //導入依賴的package包/類
public String shortPath(String path) {
    if(isPathRingtone(mContext, path)) {
        Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path));
        // Just verified that the ringtone exists... not checking for null
        return ringtone.getTitle(mContext);
    }
    if(path == null) {
        return "";
    }
    if(path.length() == 0) {
        return "xDrip Default";
    }
    String[] segments = path.split("/");
    if (segments.length > 1) {
        return segments[segments.length - 1];
    }
    return path;
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:19,代碼來源:EditAlertActivity.java

示例12: shortPath

import android.media.Ringtone; //導入依賴的package包/類
private String shortPath(String path) {
    try {
        if (path != null) {
            if (path.length() == 0) {
                return "xDrip Default";
            }
            Ringtone ringtone = RingtoneManager.getRingtone(mContext, Uri.parse(path));
            if (ringtone != null) {
                return ringtone.getTitle(mContext);
            } else {
                String[] segments = path.split("/");
                if (segments.length > 1) {
                    return segments[segments.length - 1];
                }
            }
        }
        return "";
    } catch (SecurityException e) {
        // need external storage permission?
        checkStoragePermissions("Need permission to access audio files");
        return "";
    }
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:24,代碼來源:AlertList.java

示例13: beep

import android.media.Ringtone; //導入依賴的package包/類
/**
 * Beep plays the default notification ringtone.
 *
 * @param count     Number of times to play notification
 */
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) {
                        }
                    }
                }
            }
        }
    });
}
 
開發者ID:GeoThings,項目名稱:Clickers,代碼行數:29,代碼來源:Notification.java

示例14: initSeekBar

import android.media.Ringtone; //導入依賴的package包/類
private void initSeekBar(int stream_type, Ringtone tone, int iconRes, boolean enabled) {
	if (enabled) {
		View v = getLayoutInflater().inflate(R.layout.volume_sider_item, volume_sliders_container, false);
		((ImageView) v.findViewById(R.id.vs_icon)).setImageResource(iconRes);

		final SeekBar seek = (SeekBar) v.findViewById(R.id.vs_seek);
		seek.setTag(stream_type);
		seek.setMax(am.getStreamMaxVolume(stream_type));
		seek.setProgress(am.getStreamVolume(stream_type));
		seek.setOnSeekBarChangeListener(this);

		ringtoneMap.put(stream_type, tone);
		volume_sliders_container.addView(v);

		if (mLastControlledSeekbar == null) {
			mLastControlledSeekbar = seek;
		}
	}
}
 
開發者ID:sunnygoyal,項目名稱:PowerToggles,代碼行數:20,代碼來源:VolumeSlider.java

示例15: onStopTrackingTouch

import android.media.Ringtone; //導入依賴的package包/類
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
	final int stream = (Integer) seekBar.getTag();
	am.setStreamVolume(stream, seekBar.getProgress(), 0);

	if (stream == AudioManager.STREAM_RING) {
		volume_modes.check(seekBar.getProgress() > 0 ?
				(VolumeTracker.isVibrateOn(this, am) ? R.id.rd_vol_4 : R.id.rd_vol_3) :
					R.id.rd_vol_1);
	}

	Ringtone tone = ringtoneMap.get(stream);
	if (tone!=null && playMusic) {
		tone.setStreamType(stream);
		tone.play();
	}
	mLastControlledSeekbar = seekBar;
}
 
開發者ID:sunnygoyal,項目名稱:PowerToggles,代碼行數:19,代碼來源:VolumeSlider.java


注:本文中的android.media.Ringtone類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。