在接收来电显示通知不显示 [英] Notification shown on receiving call not showing

查看:151
本文介绍了在接收来电显示通知不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经添加,响应来电广播接收器和以下是广播接收器的onReceive方法的code

 捆绑额外= intent.getExtras();
        如果(临时演员!= NULL)
        {
            字符串状态= extras.getString(TelephonyManager.EXTRA_STATE);
            的System.out.println(州);
            如果(state.equals(TelephonyManager.CALL_STATE_RINGING))
            {
                字符串PHONENO = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
                Toast.makeText(背景下,适当,Toast.LENGTH_SHORT).show();
                的System.out.println(不为+ PHONENO);                NotificationManager纳米=(NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
                通知新台币=新的通知(R.drawable.ic_launcher,你有叫,System.currentTimeMillis的()+ 2000);
                字符串title =你有叫
                字符串文本=你接到电话来自+ PHONENO;
                意图II =新意图();
                //ii.setData(Uri.parse(\"http://www.google.com));
                的PendingIntent圆周率= PendingIntent.getActivity(上下文,1,二,0);
                nt.setLatestEventInfo(背景,标题,文字,PI);
                nm.notify(5,NT);
                Toast.makeText(背景下,适当,Toast.LENGTH_SHORT).show();            }        }

然而,当我从DDMS发送呼叫,通知不加,如果在不显示verbose.kindly更新为什么发生这种情况没有show.a日志信息。
谢谢
tejinder


解决方案

这是我的code这是工作

我认为你需要写

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

        }
    }

这篇关于在接收来电显示通知不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆