1

我正在尝试在获取更新后获取通知。我在一个单独的模块中尝试过它并且它有效。但是当我试图将它包含在一个包中时,它会显示错误。

01-18 09:54:27.020: E/MediaPlayerService(33): Couldn't open fd for content://settings/system/notification_sound
01-18 09:54:27.121: E/MediaPlayer(1460): Unable to to create media player
01-18 09:54:27.260: E/RingtoneManager(1460): Failed to open ringtone content://settings/system/notification_sound

我认为它与通知声音有关,我对此发表了评论。即使这样做了,我也遇到了同样的错误。

更新.java

    Intent intent = new Intent(UpdateService.this,NewsActivity.class);
                            PendingIntent pIntent = PendingIntent.getActivity(UpdateService.this, 0, intent, 0);
                            Notification n = new Notification(R.drawable.ic_launcher, "new update arrived", System.currentTimeMillis());
                            n.setLatestEventInfo(getApplicationContext(), "Update", "new update arrived", pIntent);
                            n.flags = Notification.FLAG_AUTO_CANCEL;
                            NM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                            NM.notify(id,n);
//                          try{
//                              Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
//                              Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
//                              r.play();
//                          }catch(Exception e){
//                              e.printStackTrace();
//                          }    
                            Log.d("Change","the old value changed");
                        }else{
                                    Thread.sleep(DELAY);
                        }                       
                    } catch (InterruptedException e) {
                        isRunning = false;
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

我是一个崭露头角的安卓开发者。请帮我。

4

1 回答 1

0

您不应该自己播放声音 - Android 会为您处理。

使用 RingtoneManager 删除 try/catch 块,你应该没问题。

如果您没有收到通知声音或想要更改它,请参阅Notification.sound字段。

我建议你使用notification.defaults = Notification.DEFAULT_ALL.

于 2013-02-15T20:28:03.490 回答