2011-08-24 621 views
0

我想在黑莓中创建一个通话记录器应用程序。虽然在这个论坛搜索我有call-recorder-in-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; 
    } 
} 

回答

1

其实黑莓直接通话录音是不可能的。在拨打免提电话时,发布代码的AFAIK是通话录音。这意味着如果移动电话有扬声器,请给扬声器打电话并录下该声音。并且看看这个讨论,Call recorder in Blackberry.

+0

我很欣赏。您对此的评论,但我的问题与您给出的答案有点不同。 –

1

当您正在尝试执行的操作时,不能记录电话的音频(除了扬声器外)。这是故意的。您需要使用另一种方法来完成此操作。不过,我可以回答你的其他问题:

为了使应用程序自动启动,可以按照下列步骤操作:http://supportforums.blackberry.com/t5/Java-Development/Configure-an-application-to-start-automatically-when-the/ta-p/444748

而且,这上面的应用程序不会从UIApplication的扩展,您应检查“为运行一个系统模块“盒子,当你按照上面的指示。这样它就不会出现在功能区或应用程序列表中的图标上。

+0

什么是你另一种方法关闭设备,这将帮助我? –