- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
到目前为止,我一直在通过为 1 个文件创建 1 个 Activity 来制作具有设置为铃声功能的应用程序。这很糟糕,因为对于具有超过 20 个铃声的应用程序,我将需要 20 个会影响应用程序大小和性能的 Activity 。然后我发现有一种方法可以只用一个 Activity 和布局来做到这一点,通过 Intents 传递数据。现在我很清楚它是如何工作的,除了一件困扰我的事情。这就是我如何定义字符串。我需要 1 个字符串作为名称,1 个字符串作为文件路径
我的代码:
Boolean success = false;
rsound = new File(rpath, "Slow tone.mp3");rpath.mkdirs(); //Copied file name
if (!rsound.exists()) {
try {
InputStream in = getResources().openRawResource(R.raw.s8slowtone); //path for file
FileOutputStream out = new FileOutputStream(rsound.getPath());
byte[] buff = new byte[1024];
int read = 0;
try {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
} finally {
in.close();
out.close();
}
} catch (Exception e) {
success = false;
}
} else {
success = true;
setRingtone();
}
if (!success) {
setRingtone();
}
}
private void setRingtone() {
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, rsound.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "Slow tone"); //Ringtone name
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
values.put(MediaStore.Audio.Media.ARTIST, " ");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, true);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(rsound.getAbsolutePath());
getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + rsound.getAbsolutePath() + "\"",
null);
Uri newUri = getContentResolver().insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(
S15.this, RingtoneManager.TYPE_RINGTONE,
newUri);
Toast.makeText(getApplicationContext(), "Ringtone set successfully",
Toast.LENGTH_SHORT).show();
那么我该怎么做呢?如何为每个文件定义字符串以及如何传递它们?
由于某些成员的问题不清楚,我会使其更简单我不知道应该如何编写字符串,所以当我使用 Intent 启动 RingtoneManager Activity 时,我从字符串传递数据。那么我应该如何编写我的代码来传递这个
文件名“慢音.mp3”
文件路径:R.raw.s8slowtone)
铃声名称“慢调”
最佳答案
要调用您的 Activity ,只需将此函数放在任何地方,然后使用您想要的参数调用它。它将构建一个 Intent 并填写参数:
public static void runRingToneActivity(Context context, String ringToneName, String ringTonePath, String ringToneFilename) {
Intent intent=new Intent(context, RingToneActivity.class);
intent.putExtra("NAME", ringToneName);
intent.putExtra("PATH", ringTonePath);
intent.putExtra("FILE", ringToneFileName);
((Activity)context).startActivity(intent);
}
在您的 RingToneActivity 的
onCreate 中,您只需检索刚刚传递的参数:
@Override
protected void onCreate(Bundle savedInstanceState) {
.
.
Intent intent=this.getIntent();
String ringtoneName=intent.getStringExtra("NAME");
String ringtonePath=intent.getStringExtra("PATH");
String ringtoneFile=intent.getStringExtra("FILE");
// you have them, now use them!
}
注意事项:
关于java - 使用 Intents 传递铃声数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22883315/
我正在使用 NotificationManager 构建器在我的应用程序中显示警报。我知道 notify 方法的第一个参数是一个 id,如果它已经可见,框架将更新通知,但是如果我将警报设置为播放铃声或
我想在我的应用程序中使用 iPhone 的铃声。这可能吗?请帮助我解决这一点, 谢谢 最佳答案 您无法以编程方式使用或更改可用的铃声。很抱歉这么说,但苹果实在太保守了。 关于iphone - 如何在应
我正在尝试禁用 vim 上的错误铃声,包括视觉和音频。但是我不能让他们离开。 我的 vimrc 中有以下内容: " Disable annoying beeping set noerrorbells
我的应用程序播放闹钟。在 Android 声音设置中,此声音由“铃声音量” slider 控制,而不是由“闹钟音量” slider 控制。如何更改由“闹钟音量”控制的声音? public void
我想做的是创建类似应用程序的警报。主要编码完成。目前它播放一首添加到我的 apk(原始文件夹)中的歌曲。 我想添加一个功能,让用户可以选择他/她自己的歌曲作为闹钟声音。它可以是来自 SD 卡、内部的文
我想从我的应用程序中从云端下载 mp3 文件,然后将下载的音频文件设置为铃声。我通过 stackoverflow 尝试了很多解决方案,并花了很多时间在谷歌中搜索,但没有任何好的结果。 更新: 我已经解
我正在尝试添加某种回声命令,使我的菜单在准备好供用户输入时发出蜂鸣声或铃声。如果有任何可能的帮助,我将不胜感激,谢谢! loop=y while [ "$loop" = y ] do clear
我开始使用以下方式播放声音:(工作) RingtoneManager.getRingtone(this, Uri.parse(callerRing)).play(); 并尝试使用以下方式停止播放声音:
我如何在 React Native 中获取系统铃声列表,例如铃声、通知铃声,以便我可以让用户选择将它们设置为通知铃声? 我查看了一些库,如 react-native-ringtone-manager
我的应用程序必须能够在收到推送通知时无论如何播放警报声。 有没有办法配置 Audio Session 来播放声音: 并且不遵守无声开关(可能会遵守路线) 在推送消息到达时(可以是无声的)并且应用程序是
我正在尝试在我的 PhoneGap 应用程序中播放 mp3 音调。在 iOS 上运行良好,但在 Android (4.2.2) 上无法播放铃声。 html js: document.getE
我想将我的资源文件夹中的铃声设置为默认铃声。现在我发现这是不可能的,因为无法从外部访问 Assets 。因此,我必须将文件从我的 Assets 复制到 SD,或者我使用内容提供程序。我认为最后一个是更
我想在我的 Android 应用程序中播放来自(铃声)URI 的声音。但是,我想以任意音量播放此声音,并且系统音量(例如媒体和铃声音量)不会影响播放。 我一直在翻阅 API 文档,但不知所措。这在 A
我是一名优秀的程序员,十分优秀!