天天看点

android监控电话录音,Android应用开发:电话监听和录音代码示例

package com.cons.dcg.collect;

import java.io.file;

import java.text.simpledateformat;

import java.util.*;

import android.app.*;

import android.content.intent;

import android.database.cursor;

import android.net.uri;

import android.os.asynctask;

import android.os.bundle;

import android.os.environment;

import android.provider.mediastore;

import android.view.*;

import android.widget.*;

public class recordactivity extends activity implements onclicklistener {

private static final int result_capture_image = 1;// 照相的requestcode

private static final int request_code_take_video = 2;// 摄像的照相的requestcode

private static final int result_capture_recorder_sound = 3;// 录音的requestcode

private string strimgpath = "";// 照片文件绝对路径

private string strvideopath = "";// 视频文件的绝对路径

private string strrecorderpath = "";// 录音文件的绝对路径

@override

protected void oncreate(bundle savedinstancestate) {

super.oncreate(savedinstancestate);

this.setcontentview(r.layout.problem_report);

}

@override

protected void onactivityresult(int requestcode, int resultcode, intent data) {

super.onactivityresult(requestcode, resultcode, data);

switch (requestcode) {

case result_capture_image://拍照

if (resultcode == result_ok) {

toast.maketext(this, strimgpath, toast.length_short).show();

}

break;

case request_code_take_video://拍摄视频

if (resultcode == result_ok) {

uri urivideo = data.getdata();

cursor cursor=this.getcontentresolver().query(urivideo, null, null, null, null);

if (cursor.movetonext()) {

strvideopath = cursor.getstring(cursor.getcolumnindex("_data"));

toast.maketext(this, strvideopath, toast.length_short).show();

}

}

break;

case result_capture_recorder_sound://录音

if (resultcode == result_ok) {

uri urirecorder = data.getdata();

cursor cursor=this.getcontentresolver().query(urirecorder, null, null, null, null);

if (cursor.movetonext()) {

strrecorderpath = cursor.getstring(cursor.getcolumnindex("_data"));

toast.maketext(this, strrecorderpath, toast.length_short).show();

}

}

break;

}

}

private void cameramethod() {

intent imagecaptureintent = new intent(mediastore.action_image_capture);

strimgpath = environment.getexternalstoragedirectory().tostring() + "/consdcgmpic/";//存放照片的文件夹

string filename = new simpledateformat("yyyymmddhhmmss").format(new date()) + ".jpg";//照片命名

file out = new file(strimgpath);

if (!out.exists()) {

out.mkdirs();

}

out = new file(strimgpath, filename);

strimgpath = strimgpath + filename;//该照片的绝对路径

uri uri = uri.fromfile(out);

imagecaptureintent.putextra(mediastore.extra_output, uri);

imagecaptureintent.putextra(mediastore.extra_video_quality, 1);

startactivityforresult(imagecaptureintent, result_capture_image);

}

private void videomethod() {

intent intent = new intent(mediastore.action_video_capture);

intent.putextra(mediastore.extra_video_quality, 0);

startactivityforresult(intent, request_code_take_video);

}

private void soundrecordermethod() {

intent intent = new intent(intent.action_get_content);

intent.settype("audio/amr");

startactivityforresult(intent, result_capture_recorder_sound);

}

private void showtoast(string text, int duration) {

toast.maketext(problemreport.this, text, duration).show();

}

}