Android手机窃听器的实现
来源:互联网 发布:贪吃蛇编程代码 编辑:程序博客网 时间:2024/06/06 05:24
设置一个按钮布局点击可以开启服务。
public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void click(View v){ Intent intent=new Intent(this,PhoneService.class); startService(intent); }}服务类
public class PhoneService extends Service {private MediaRecorder recorder;@Overridepublic IBinder onBind(Intent arg0) {// TODO Auto-generated method stubreturn null;}@Overridepublic void onCreate() {TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);tm.listen(new MyPhoneStateListener(),PhoneStateListener.LISTEN_CALL_STATE);super.onCreate();}private class MyPhoneStateListener extends PhoneStateListener{@Overridepublic void onCallStateChanged(int state, String incomingNumber) {switch(state){case TelephonyManager.CALL_STATE_IDLE:if(recorder!=null){ recorder.stop(); recorder.reset(); // You can reuse the object by going back to setAudioSource() step recorder.release(); // Now the object cannot be reused}break;case TelephonyManager.CALL_STATE_OFFHOOK:System.out.println("开始录"); recorder.start(); // Recording is now startedbreak;case TelephonyManager.CALL_STATE_RINGING:System.out.println("准备一个录音机");//1创建一个实例recorder = new MediaRecorder();//2设置音频的来源 recorder.setAudioSource(MediaRecorder.AudioSource.MIC); //3设置输出的格式 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); //4设置编码方式 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); //5设置有效的路径 recorder.setOutputFile("/mnt/sdcard/luyinn.3gp"); //6准备录 try {recorder.prepare();} catch (IllegalStateException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} break;}super.onCallStateChanged(state, incomingNumber);}}}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.recorder.MainActivity" > <Button android:id="@+id/button1" android:onClick="click" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="48dp" android:layout_marginTop="90dp" android:text="Button" /></RelativeLayout>
加上权限
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />注册服务
<service android:name="com.example.recorder.PhoneService" > </service>
0 0
- Android手机窃听器的实现
- Android电话窃听器的实现
- Android BroadcastReceiver广播接收者实现短信窃听器
- 简单实现android中的电话窃听器
- Android:Service:采用Service实现电话窃听器
- 让手机变成窃听器
- 警惕:冒充Google+ 让手机变成窃听器的恶意软件
- android广播实现短信窃听器和开机自动启动activity
- Android入门:利用MediaRecorder和TelephonyManager实现电话窃听器
- Android开发入门之采用广播接收者实现短信窃听器
- Android开发入门之采用Service实现电话窃听器
- Android入门:利用MediaRecorder和TelephonyManager实现电话窃听器
- Android:BroadcastReceiver:采用广播接收者实现短信窃听器
- Android 电话窃听器
- android电话窃听器
- Android之短信窃听器
- android 电话窃听器
- Android 短信窃听器
- ReactNative Could not install the app on the device
- CCF 201604-3 路径解析 java实现w
- 蓝桥杯_C语言_本科B——啤酒和饮料
- Gson 解析遇到的奇怪问题
- CentOS 7 安装Docker服务
- Android手机窃听器的实现
- Android support library
- Vue2+VueRouter2+webpack 构建项目实战(二)目录以及文件结构
- java cos和native cos的区别
- PowerDesigner连接mysql逆向生成pdm
- centos7下安装ab测试
- mysql获取一个表中的下一个自增(id)值的方法
- Markdown的基础设置
- eclipse中文注释显示为unicode