llb988

android监控来电显示

当电话来电的时候,我们要监控着电话号码的来电,哪我们是通过代码控制,下面我们看看利用吐丝显示来电显示

view source print ?
代码
package com.smart;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.Toast;
public class Main extends Activity {
public class MyPhoneCallListener extends PhoneStateListener{
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_OFFHOOK:
Toast.makeText(Main.this, "正在通话中....", Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText(Main.this, incomingNumber, Toast.LENGTH_SHORT).show();
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
MyPhoneCallListener myPhoneCallListener=new MyPhoneCallListener();
tm.listen(myPhoneCallListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/phonestate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

更多相关文章

  1. Android(安卓)Studio 新建编辑条 点击按钮显示控件中的内容
  2. android 关于listview scrollview 底部 控件无法显示的两个解决
  3. 关于用Android的API重写drawRegion方法的代码
  4. Android:adb shell am命令行发送Activity/Service/Broadcast
  5. Android(安卓)studio使用SVN
  6. list多选 android,Android(安卓)ExpandableListView单选以及多选
  7. Android————一个简单记账本(Bookkeeping)
  8. android之ContentResolver与ContentProvider
  9. Android(安卓)内核源代码交叉编译(创建自己的模拟器内核,哈哈终于

随机推荐

  1. seaborn常用的10种数据分析图表
  2. 基于geopandas的空间数据分析-深入浅出分
  3. 火爆全网的动态曲线图是怎么做的?
  4. 使用pyecharts绘制词云图-淘宝商品评论展
  5. 使用sklearn轻松实现数据缩放
  6. Numpy进阶之排序小技巧
  7. 8个超好用的Python内置函数,提升效率必备!
  8. 全平台都能用的pandas运算加速神器
  9. 现代浏览器探秘(part4):事件处理 [每日前
  10. 一步步教你用实现HTML5 SVG动画效果 [每