我创建了一个通知
mBuilder = new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.drawable.notification_icon);
mBuilder.setContentTitle("My notification!");
mBuilder.setContentText("Hello world!!!");
Uri notifiSound;
notifiSound = Uri.parse("file://"+Environment.getExternalStorageDirectory().getPath()+"/музыка/Hi-Fi - мы любили.mp3");
mBuilder.setSound(notifiSound);
Intent resIntent = new Intent(this, MainActivity.class);
PendingIntent pendIntent = PendingIntent.getActivity(this, 0, resIntent, 0);
mBuilder.setContentIntent(pendIntent);
NotificationManager mNotifyMng = (NotificationManager) getSystemService(Activity.NOTIFICATION_SERVICE);
mNotifyMng.notify(0, mBuilder.build());
记录猫
03-07 17:08:26.146: E/UsbDebuggingManager(949): Communication error:
03-07 17:08:26.146: E/UsbDebuggingManager(949): java.io.IOException: Connection refused
03-07 17:08:26.146: E/UsbDebuggingManager(949): at android.net.LocalSocketImpl.connectLocal(Native Method)
03-07 17:08:26.146: E/UsbDebuggingManager(949): at android.net.LocalSocketImpl.connect(LocalSocketImpl.java:290)
03-07 17:08:26.146: E/UsbDebuggingManager(949): at android.net.LocalSocket.connect(LocalSocket.java:130)
03-07 17:08:26.146: E/UsbDebuggingManager(949): at com.android.server.usb.UsbDebuggingManager.listenToSocket(UsbDebuggingManager.java:75)
03-07 17:08:26.146: E/UsbDebuggingManager(949): at com.android.server.usb.UsbDebuggingManager.run(UsbDebuggingManager.java:111)
03-07 17:08:26.146: E/UsbDebuggingManager(949): at java.lang.Thread.run(Thread.java:841)
我从SD卡添加声音但没有。 如何从SD卡添加Android声音和声音? 请帮忙
答案 0 :(得分:0)
你很难实现这个目标
1。)
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.yoursoundfilename);
mBuilder.setSound(sound);
我详细解释了你
将你的mp3文件放到res-> raw文件夹中。例如FILENAME.MP3
Uri sound = Uri.parse("android.resource://com.yourpackagename/" + R.raw.filename);
mBuilder.setSound(sound);
OR
Uri sound = Uri.parse("android.resource://com.yourpackagename/raw/filename");
mBuilder.setSound(sound);
执行正常的通知程序
您可以在通知中使用默认声音:
notification.defaults |= Notification.DEFAULT_SOUND;
如果您想通过通知播放SD卡中的自定义声音:
notification.sound = Uri.parse("file:///sdcard/path/filename.mp3");