- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 android 应用程序有一个小问题。我的应用程序中有一些 mp3 文件,我希望能够将其设置为默认铃声或通知。应用程序设置调用铃声和警报铃声没有问题,但设置短信铃声不起作用来电铃声:
public void onClick(View arg0) {
// TODO Auto-generated method stub
btn3.setBackgroundResource(R.drawable.ok);
File localFile1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/bomb/");
Uri mUri = Uri.parse("android.resource://ir.bazisong/"+R.raw.bababanana);
ContentResolver mCr = bombsound2.this.getContentResolver();
AssetFileDescriptor soundFile;
try {
soundFile= mCr.openAssetFileDescriptor(mUri, "r");
} catch (FileNotFoundException e) {
soundFile=null;
}
try {
byte[] readData = new byte[1024];
FileInputStream fis = soundFile.createInputStream();
FileOutputStream fos = new FileOutputStream(localFile1);
int i = fis.read(readData);
while (i != -1) {
fos.write(readData, 0, i);
i = fis.read(readData);
}
fos.close();
} catch (IOException io) {
}
ContentValues localContentValues = new ContentValues();
localContentValues.put("_data", localFile1.getAbsolutePath());
localContentValues.put("title", "bomb");
localContentValues.put("mime_type", "audio/ogg");
localContentValues.put("artist", "cssounds ");
localContentValues.put("is_ringtone", Boolean.valueOf(true));
localContentValues.put("is_notification", Boolean.valueOf(false));
localContentValues.put("is_alarm", Boolean.valueOf(false));
localContentValues.put("is_music", Boolean.valueOf(false));
Uri localUri1 = MediaStore.Audio.Media.getContentUriForPath(localFile1.getAbsolutePath());
Uri localUri2 = bombsound2.this.getContentResolver().insert(localUri1, localContentValues);
RingtoneManager.setActualDefaultRingtoneUri(bombsound2.this.getApplication(), 1, localUri2);
((Vibrator)bombsound2.this.getSystemService("vibrator")).vibrate(50L);
Toast.makeText(bombsound2.this.getApplicationContext(), "زنگ تماس انتخاب شد", 1).show();
}
});
短信铃声
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
btn4.setBackgroundResource(R.drawable.ok);
File localFile1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/bomb/");
Uri mUri = Uri.parse("android.resource://ir.bazisong/"+R.raw.bababanana);
ContentResolver mCr = bombsound2.this.getContentResolver();
AssetFileDescriptor soundFile;
try {
soundFile= mCr.openAssetFileDescriptor(mUri, "r");
} catch (FileNotFoundException e) {
soundFile=null;
}
try {
byte[] readData = new byte[1024];
FileInputStream fis = soundFile.createInputStream();
FileOutputStream fos = new FileOutputStream(localFile1);
int i = fis.read(readData);
while (i != -1) {
fos.write(readData, 0, i);
i = fis.read(readData);
}
fos.close();
} catch (IOException io) {
}
ContentValues localContentValues = new ContentValues();
localContentValues.put("_data", localFile1.getAbsolutePath());
localContentValues.put("title", "bomb");
localContentValues.put("mime_type", "audio/ogg");
localContentValues.put("artist", "cssounds ");
localContentValues.put("is_ringtone", Boolean.valueOf(false));
localContentValues.put("is_notification", Boolean.valueOf(true));
localContentValues.put("is_alarm", Boolean.valueOf(false));
localContentValues.put("is_music", Boolean.valueOf(false));
Uri localUri1 = MediaStore.Audio.Media.getContentUriForPath(localFile1.getAbsolutePath());
Uri localUri2 = bombsound2.this.getContentResolver().insert(localUri1, localContentValues);
RingtoneManager.setActualDefaultRingtoneUri(bombsound2.this.getApplication(), 1, localUri2);
((Vibrator)bombsound2.this.getSystemService("vibrator")).vibrate(50L);
Toast.makeText(bombsound2.this.getApplicationContext(), "زنگ پیام انتخاب شد", 1).show();
}
});
最佳答案
解决方案是将原始文件夹中的声音复制到 SD 卡中,然后从那里执行以下操作
File k = new File(path, filename);
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "TwiAppclip");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");
values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k
.getAbsolutePath());
//do a delete here before inserting
Uri newUri = getApplicationContext().getContentResolver().insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),
RingtoneManager.TYPE_RINGTONE, newUri);
关于java - 怎么设置短信铃声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24980670/
我正在使用 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
我是一名优秀的程序员,十分优秀!