Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在blackberry中录制通话?_Blackberry_Call - Fatal编程技术网

如何在blackberry中录制通话?

如何在blackberry中录制通话?,blackberry,call,Blackberry,Call,我想在blackberry中创建一个通话记录应用程序。在这个论坛搜索时,我得到了这个链接。下面链接中给出的代码是可以理解的 对于你们这些专家来说,这可能是一个愚蠢的问题,但我的问题是如何使用这段代码。我的意思是MyScreen对象将在UIApplication上工作。但是,如何在启动设备时启动模块,并在后台运行,等待电话侦听器调用呢 我使用了下面的代码,它记录了通话,但仅当通话处于扬声器模式时。现在,我如何在不使用扬声器模式的情况下进行同样的操作 import java.io.ByteArra

我想在blackberry中创建一个通话记录应用程序。在这个论坛搜索时,我得到了这个链接。下面链接中给出的代码是可以理解的

对于你们这些专家来说,这可能是一个愚蠢的问题,但我的问题是如何使用这段代码。我的意思是MyScreen对象将在UIApplication上工作。但是,如何在启动设备时启动模块,并在后台运行,等待电话侦听器调用呢


我使用了下面的代码,它记录了通话,但仅当通话处于扬声器模式时。现在,我如何在不使用扬声器模式的情况下进行同样的操作

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.RecordControl;

import net.rim.blackberry.api.phone.Phone;
import net.rim.blackberry.api.phone.PhoneCall;
import net.rim.blackberry.api.phone.PhoneListener;
import net.rim.device.api.system.Application;
import net.rim.device.api.ui.component.Dialog;

public class CatchCall extends Application implements PhoneListener {

    Player player;
    RecordControl recorder;
    private ByteArrayOutputStream output;
    byte[] data;
    boolean yes = false;
    int st;

    public CatchCall() {
        Phone.addPhoneListener(this);
    }

    public static void main(String[] args) {
        new CatchCall().enterEventDispatcher();
    }

    public void callAdded(int callId) {
    }

    public void callAnswered(int callId) {
    }

    public void callConferenceCallEstablished(int callId) {
    }

    public void callConnected(int callId) {

        // TODO Auto-generated method s
        PhoneCall phoneCall = Phone.getCall(callId);
        if (phoneCall != null) {
            if (yes)
                initPlay();
        }
    }

    public void callDirectConnectConnected(int callId) {
    }

    public void callDirectConnectDisconnected(int callId) {
    }

    public void callDisconnected(int callId) {
        // TODO Auto-generated method stub
        if (yes) {
            try {
                recorder.commit();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            player.close();
            data = output.toByteArray();
            saveRecordedFile(data);
        }
    }

    public void callEndedByUser(int callId) {
    }

    public void callFailed(int callId, int reason) {
    }

    public void callHeld(int callId) {
    }

    public void callIncoming(int callId) {
        Dialog.ask(Dialog.D_YES_NO, "Are u sure to record this call");
    }

    public void callInitiated(int callid) {

        PhoneCall phoneCall = Phone.getCall(callid);
        if (phoneCall != null) {
            st = Dialog.ask(Dialog.D_YES_NO, "Are u sure to record this call");
            if (st == Dialog.YES)
                yes = true;
            else
                yes = false;
        }

    }

    public void callRemoved(int callId) {
    }

    public void callResumed(int callId) {
    }

    public void callWaiting(int callid) {
    }

    public void conferenceCallDisconnected(int callId) {
    }

    private void initPlay() {
        try {
            player = Manager.createPlayer("capture://audio");
            player.realize();
            recorder = (RecordControl) player.getControl("RecordControl");
            output = new ByteArrayOutputStream();
            recorder.setRecordStream(output);
            recorder.startRecord();
            player.start();
        } catch (Exception e) {
            Dialog.alert(e + "");
        }

    }

    public static boolean saveRecordedFile(byte[] data) {
        try {
            String filePath1 = System.getProperty("fileconn.dir.music");
            String fileName = "Call Recorder(";
            boolean existed = true;
            for (int i = 0; i < Integer.MAX_VALUE; i++) {
                try {
                    FileConnection fc = (FileConnection) Connector.open(filePath1 + fileName + i + ").amr");
                    if (!fc.exists()) {
                        existed = false;
                    }
                    fc.close();
                } catch (IOException e) {
                    Dialog.alert("unable to save");
                    return existed;
                }
                if (!existed) {
                    fileName += i + ").amr";
                    filePath1 += fileName;
                    break;
                }
            }
            System.out.println(filePath1);
            System.out.println("");
            FileConnection fconn = (FileConnection) javax.microedition.io.Connector .open(filePath1, javax.microedition.io.Connector.READ_WRITE);
            if (fconn.exists())
                fconn.delete();
            fconn.create();

            OutputStream outputStream = fconn.openOutputStream();
            outputStream.write(data);
            outputStream.close();
            fconn.close();
            return true;
        } catch (Exception e) {
        }
        return false;
    }
}
import java.io.ByteArrayOutputStream;
导入java.io.IOException;
导入java.io.OutputStream;
导入javax.microedition.io.Connector;
导入javax.microedition.io.file.FileConnection;
导入javax.microedition.media.Manager;
导入javax.microedition.media.Player;
导入javax.microedition.media.control.RecordControl;
导入net.rim.blackberry.api.phone.phone;
导入net.rim.blackberry.api.phone.PhoneCall;
导入net.rim.blackberry.api.phone.PhoneListener;
导入net.rim.device.api.system.Application;
导入net.rim.device.api.ui.component.Dialog;
公共类CatchCall扩展应用程序实现PhoneListener{
玩家;
记录控制记录器;
私有ByteArrayOutputStream输出;
字节[]数据;
布尔值yes=false;
int st;
公众电话{
addPhoneListener(this);
}
公共静态void main(字符串[]args){
新建CatchCall().enterEventDispatcher();
}
已添加公共无效调用(int callId){
}
公共无效呼叫已应答(int CALID){
}
公共无效callConferenceCallEstablished(int callId){
}
公共无效调用连接(int callId){
//TODO自动生成的方法s
PhoneCall=Phone.getCall(callId);
if(phoneCall!=null){
如果(是)
initPlay();
}
}
public void callDirectConnectConnected(int callId){
}
public void callDirectConnectDisconnected(int callId){
}
公共无效调用已断开连接(int callId){
//TODO自动生成的方法存根
如果(是){
试一试{
recorder.commit();
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
player.close();
data=output.toByteArray();
保存的记录文件(数据);
}
}
被调用的公共无效数据(int callId){
}
public void callFailed(int callId,int reason){
}
公共无效呼叫保持(内部呼叫){
}
公共无效调用(内部调用){
询问(Dialog.D_YES_NO,“您确定要录制此通话吗”);
}
公共无效callInitiated(内部callid){
PhoneCall=Phone.getCall(callid);
if(phoneCall!=null){
st=Dialog.ask(Dialog.D_YES_NO,“您确定要录制此通话吗”);
如果(st==Dialog.YES)
是=正确;
其他的
是=假;
}
}
已删除公共无效调用(int callId){
}
公共无效调用恢复(int callId){
}
公共无效呼叫等待(int callid){
}
公共无效会议CallDisconnected(int callId){
}
私人游戏{
试一试{
player=Manager.createPlayer(“capture://audio");
player.realize();
recorder=(RecordControl)player.getControl(“RecordControl”);
输出=新的ByteArrayOutputStream();
setRecordStream(输出);
录音机;
player.start();
}捕获(例外e){
对话框。警报(e+“”);
}
}
公共静态布尔saveRecordedFile(字节[]数据){
试一试{
字符串filePath1=System.getProperty(“fileconn.dir.music”);
String fileName=“呼叫记录器(”;
布尔值=真;
对于(int i=0;i
黑莓手机不可能实现直接通话录音。我知道当你用免提电话打电话时,上面的代码是通话录音。这意味着,如果手机有扩音器,那么就给扩音器打个电话并录制那个声音。看看这个讨论,

不可能像您试图做的那样录制电话音频(除了用扩音器)。这是故意的。要做到这一点,您需要另一种脱离设备的方法。不过,我可以回答你的其他问题:

要使应用程序自动启动,可以执行以下步骤:

此外,由于上面的应用程序不是从UiApplication扩展而来,您应该选中“作为系统模块运行”框