我添加了一个响应来电的广播接收器,以下是广播接收器 onreceive 方法的代码
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 发送呼叫时,通知不会显示。如果添加了日志消息,则会在详细信息中显示。请更新为什么会发生这种情况。谢谢特金德