显示通知错误

时间:2013-01-31 06:39:40

标签: android android-service android-logcat

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

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

我认为这是通知声音,我评论了它。即使在这样做之后,我也会遇到同样的错误。

Update.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();
                    }

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

1 个答案:

答案 0 :(得分:0)

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

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

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

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