接听电话中显示的通知未显示

时间:2013-06-30 13:21:53

标签: android

我添加了一个响应来电的广播接收器,以下是广播接收器接收方法的代码

Bundle extras=intent.getExtras();
        if(extras!=null)
        {
            String state=extras.getString(TelephonyManager.EXTRA_STATE);
            System.out.println(state);
            if(state.equals(TelephonyManager.CALL_STATE_RINGING))
            {
                String phoneno=extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
                Toast.makeText(context, "proper", Toast.LENGTH_SHORT).show();
                System.out.println("no is "+phoneno);

                NotificationManager nm=(NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
                Notification nt=new Notification(R.drawable.ic_launcher, "You got call", System.currentTimeMillis()+2000);
                String title="You got call";
                String text="The call you got was from "+phoneno;
                Intent ii=new Intent("");
                //ii.setData(Uri.parse("http://www.google.com"));
                PendingIntent pi=PendingIntent.getActivity(context, 1, ii, 0);
                nt.setLatestEventInfo(context, title, text, pi);
                nm.notify(5, nt);
                Toast.makeText(context, "proper", Toast.LENGTH_SHORT).show();





            }

        }

然而,当我从ddms发送呼叫时,通知不会显示。如果添加的日志消息确实显示在verbose.kindly更新中,为什么会发生这种情况。 谢谢 tejinder

1 个答案:

答案 0 :(得分:0)

这是我正在运作的代码

我认为你需要写

if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))

public void onReceive(Context context, Intent intent) {
       Bundle bundle = intent.getExtras();                
       if(null == bundle)
             return;                
       Log.i("IncomingCallReceiver",bundle.toString());                
       String state = bundle.getString(TelephonyManager.EXTRA_STATE);                                
       Log.i("IncomingCallReceiver","State: "+ state);                
       if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
       {
               String phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);                             
               Log.i("IncomingCallReceiver","Incomng Number: " + phonenumber);                        
               String info = "Detect Calls sample application\nIncoming number: " + phonenumber;                        
               Toast.makeText(context, info, Toast.LENGTH_LONG).show();

        }
    }