Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/223.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 通知声音有问题_Android_Android Emulator - Fatal编程技术网

Android 通知声音有问题

Android 通知声音有问题,android,android-emulator,Android,Android Emulator,我正在尝试测试通知。我已经创建了一个启用音频播放的模拟器。我可以得到通知,但我听不到声音。有什么问题吗?是否有我缺少的设置 NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); int icon = R.drawable.icon; CharSequence tickerText = "Hello"; CharSe

我正在尝试测试通知。我已经创建了一个启用音频播放的模拟器。我可以得到通知,但我听不到声音。有什么问题吗?是否有我缺少的设置

NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
        int icon = R.drawable.icon;
        CharSequence tickerText = "Hello";
        CharSequence contentTitle = "My notification";  // expanded message title
        CharSequence contentText = "Hello";      // expanded message text

        Intent notificationIntent = new Intent("ABC");
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        long when = System.currentTimeMillis();

        Notification notification = new Notification(icon, tickerText, when);

        notification.defaults |= Notification.DEFAULT_SOUND;

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);


        mNotificationManager.notify(HELLO_ID, notification);
当我看到logcat时,我有以下堆栈跟踪

09-20 15:44:47.297: DEBUG/MediaPlayer(62): Couldn't open file on client side, trying server side
09-20 15:44:47.347: ERROR/MediaPlayerService(34): Couldn't open fd for content://settings/system/notification_sound
09-20 15:44:47.347: ERROR/MediaPlayer(62): Unable to to create media player
09-20 15:44:47.415: WARN/NotificationService(62): error loading sound for content://settings/system/notification_sound
09-20 15:44:47.415: WARN/NotificationService(62): java.io.IOException: setDataSource failed.: status=0x80000000
09-20 15:44:47.415: WARN/NotificationService(62):     at android.media.MediaPlayer.setDataSource(Native Method)
09-20 15:44:47.415: WARN/NotificationService(62):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:714)
09-20 15:44:47.415: WARN/NotificationService(62):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:669)
09-20 15:44:47.415: WARN/NotificationService(62):     at com.android.server.NotificationPlayer$CreationAndCompletionThread.run(NotificationPlayer.java:88)

我能够通过在SD卡上给它一个不同的文件来获得通知声音播放。我在播放默认声音时遇到问题。我不确定默认的声音是什么。当我进入设置,看到默认的声音-它只有一个选项,即沉默。我也无法改变它。
所以可能没有默认通知的声音,因此我得到了那个错误,尽管我们假设,会有一个合理的默认。

thisisanath的想法是正确的。阅读之后,我添加了指定的目录结构,并将声音文件推送到DDMS中的
/mnt/sdcard/media/audio/notifications
目录。(我认为
C:\ProgramFiles(x86)\Android\Android sdk\platforms\Android-14\data\res\raw\fallbackring.ogg
发出了很好的通知声音。)在模拟器中,我卸载了SD卡,然后重新安装了SD卡。通知铃声设置除“静音”外还有“钴”,选择该选项后,我的通知声音工作正常