且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在接收来电显示通知不显示

更新时间:2022-10-15 15:24:26

这是我的code这是工作

我认为你需要写​​ P>

如果(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))

 公共无效的onReceive(上下文的背景下,意图意图){
       捆绑包= intent.getExtras();
       如果(空==束)
             返回;
       Log.i(IncomingCallReceiver,bundle.toString());
       字符串状态= bundle.getString(TelephonyManager.EXTRA_STATE);
       Log.i(IncomingCallReceiver,状态:+状态);
       如果(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
       {
               字符串PHONENUMBER = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
               Log.i(IncomingCallReceiver,Incomng数量:+ PHONENUMBER);
               字符串信息=检测电话示例应用程序\\ nIncoming号:+ PHONENUMBER;
               Toast.makeText(背景下,信息,Toast.LENGTH_LONG).show();        }
    }

i have added a broadcast receiver that responds to incoming call and the following is the code of the broadcast receiver onreceive method

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();





            }

        }

however when i send a call from the ddms ,the notification does not show.a log message if added does show in the verbose.kindly update why this is happening. thanks tejinder

This is my code which is working

I think that you need to write

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();

        }
    }