在广播接收器中显示通知

问题描述

| 嗨, 我处于通话到达时需要显示通知的情况。为此,我正在使用广播接收器。代码如下
public class MyPhoneStateListener extends PhoneStateListener {
    public Context context;
    @Override
    public void onCallStateChanged(int state,String incomingNumber) {
        // TODO Auto-generated method stub
        super.onCallStateChanged(state,incomingNumber);
        switch(state){
        case TelephonyManager.CALL_STATE_IDLE:
            NotificationManager notifier = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

            //Get the icon for the notification
            int icon = R.drawable.icon;
            Notification notification = new Notification(icon,\"Simple Notification\",System.currentTimeMillis());

            //Setup the Intent to open this Activity when clicked
            Intent toLaunch = new Intent(context,main.class);
            PendingIntent contentIntent = PendingIntent.getActivity(context,toLaunch,0);

            //Set the Notification Info
            notification.setLatestEventInfo(context,\"Hi!!\",\"This is a simple notification\",contentIntent);

            //Setting Notification Flags
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notification.defaults |= Notification.DEFAULT_SOUND;
            notification.flags |= Notification.FLAG_INSISTENT;
          //  notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI,\"6\");
            //Send the notification
            notifier.notify(0x007,notification);
            Log.d(\"CALL\",\"IDLE\");
        break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
          Log.d(\"DEBUG\",\"OFFHOOK\");
        break;
        case TelephonyManager.CALL_STATE_RINGING:

          Log.d(\"DEBUG\",\"RINGING\");
        break;
        }
    }

}
现在的问题是通知的声音没有播放,但是通知显示正确。任何人都可以点亮它,为什么不播放通知声音?     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)