12.10 android双向通话录音,ClipData监听,coding.net pymongo连接使用mongo

通话双向录音代码:

private final class PhoneListener extends PhoneStateListener {
        private String incomeNumber; // 来电号码
        private MediaRecorder mediaRecorder;
        private File file;

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            try {
                System.out.println(">>>>>>CallState>>>>>>>>" + state);
                switch (state) {
                case TelephonyManager.CALL_STATE_RINGING: // 来电
                    System.out.println(">>>>>>来电>>>>>>>>" + state);
                    this.incomeNumber = incomingNumber;
                    break;
                case TelephonyManager.CALL_STATE_OFFHOOK: // 接通电话
                    file = new File(Environment.getExternalStorageDirectory(),
                            this.incomeNumber + System.currentTimeMillis()
                                    + ".3gp");
                    System.out.println(">>>>>>接通>>>>>>>>" + state);
                    mediaRecorder = new MediaRecorder();
                    // mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                    //获得声音数据源(下麦克风)
                    mediaRecorder
                            .setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);//这个设置就是获取双向声音
                    mediaRecorder
                            .setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // 按3gp格式输出
                    mediaRecorder
                            .setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                    mediaRecorder.setOutputFile(file.getAbsolutePath()); // 输出文件
                    mediaRecorder.prepare(); // 准备
                    mediaRecorder.start();
                    break;

                case TelephonyManager.CALL_STATE_IDLE: // 挂掉电话
                    System.out.println(">>>>>>挂电话>>>>>>>>" + state);
                    if (mediaRecorder != null) {

                        System.out.println(">>>>"
                                + Environment.getExternalStorageDirectory());
                        mediaRecorder.stop();
                        mediaRecorder.release();
                        mediaRecorder = null;
                        AppliacationIMmpl.file = file;
                    }

                    break;

                }
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }

http://www.freebuf.com/news/88835.html
假说有一个应用通过某种类型的用户交互在剪切板中创建,增加一个包含了被认为是“公用”组件的Intent对象的ClipData

final ClipboardManager clipboardManager = (ClipboardManager)  
        getSystemService(Context.CLIPBOARD_SERVICE); 

Intent intent = new Intent(getApplicationContext(), 
PublicActivity.class); 
intent.setAction("android.intent.action.VIEW"); 
intent.putExtra("ExtraString", "foobar"); 

ClipData setClipData; 
setClipData = ClipData.newIntent("intent", intent); 
clipboardManager.setPrimaryClip(setClipData);

ClipboardManager.OnPrimaryClipChangedListener
onPrimaryClipChangedListener = new
ClipboardManager.OnPrimaryClipChangedListener() {

@Override
public void onPrimaryClipChanged() {
try {
replaceClipData(clipboardManager);
} catch (URISyntaxException e) {

        e.printStackTrace();                              
    }                                           
}                                               

};

pymongo连接coding的mongo

def getMongoInfo():
    print getMongoInfo
    out = {}
    envs=os.environ
    if envs.has_key('VCAP_SERVICES'):
        decode = json.loads(envs['VCAP_SERVICES'])
        out['host'] = decode['mongodb'][0]['credentials']['host']
        out['port'] = decode['mongodb'][0]['credentials']['port']
        out['username'] = decode['mongodb'][0]['credentials']['username']
        out['password'] = decode['mongodb'][0]['credentials']['password']
        out['uri'] = decode['mongodb'][0]['credentials']['uri']
        out['name'] = decode['mongodb'][0]['credentials']['name']#主要这一行,必须使用这个name的数据库,不然一直提示没有权限~
    if not out.has_key('host'):
        out['host'] = 'localhost'
        out['port'] = 27017
        out['username'] = 'root'
        out['password'] = 'root'
        out['name'] = 'Blog'
    print 'out=%s'%out
    return out

你可能感兴趣的:(android)