当前位置: 首页>>代码示例>>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;未经允许,请勿转载。