2011-10-11 94 views
1

我正在尝试记录调用。但是启动服务意图存在一个大问题。无法启动服务意图{flg = 0x10000000 cmp = com.company.callrecorder/.CallStateListener}:找不到

WARN/ActivityManager(61):无法启动服务意图{FLG = 0x10000000的> CMP = com.company.callrecorder/.CallStateListener}:找不到

这是我的广播接收器的代码:

 public class StartServicesAtStartUp extends BroadcastReceiver 

{ public static Intent phoneStateListener; public void onReceive(Context context,Intent intent) Log.d(“DEBUG”,“com.its.CallRecorder Initiated ...”); Toast.makeText(context,“Call Recording Initiated ..”,Toast.LENGTH_SHORT).show(); Start_CallRec(context); }

public static void Start_CallRec(Context context) 
    { 
     if(!SharedData._Started) 
     { 
      if(SharedData._AutoStart) 
      { 
       Toast.makeText(context," Call Recording Auto-Start.. ", Toast.LENGTH_SHORT).show(); 
       phoneStateListener = new Intent(context, CallStateListener.class); 
       phoneStateListener.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       context.startService(phoneStateListener); 
       Log.d("DEBUG", "com.its.CallRecorder Call Recorder Started ..."); 
       TelephonyManager tManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
       CallStateListener callStateListener = new CallStateListener(); 
       tManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE); 
       SharedData._Started = true; 
       Toast.makeText(context," Call Recording Started ... ", Toast.LENGTH_SHORT).show(); 
      } 
     } 
     else 
     { 
      Toast.makeText(context," Call Recording Already Active.. ", Toast.LENGTH_SHORT).show(); 
     } 
    } 

    public static void Stop_CallRec(Context context) 
    { 
     if(SharedData._Started) 
     { 
      context.stopService(phoneStateListener); 
      Toast.makeText(context," Call Recording Stopped ... ", Toast.LENGTH_SHORT).show(); 
      SharedData._Started = false;     
     } 
     else 
     { 
      Toast.makeText(context," Call Recording Already Stopped ... ", Toast.LENGTH_SHORT).show(); 
     } 
    } 

}

而且CallStateListener.java代码:

public class CallStateListener extends PhoneStateListener { 
public void onCallStateChanged(int state, String incomingNumber) 
{ 
    super.onCallStateChanged(state, incomingNumber); 
    switch(state) 
    { 
    case TelephonyManager.CALL_STATE_IDLE: 
     if(SharedData._Recording) 
      { Recorders_Stop(); } 
     break; 
    case TelephonyManager.CALL_STATE_RINGING: 
     break; 
    case TelephonyManager.CALL_STATE_OFFHOOK: 
     String CallDate = SanityDate(); 
     String CallNum = SanityNum(incomingNumber); 
     String RootDir = SharedData._Path ; 
     String CallDir = SharedData._Path + CallNum + "/" ; 
     String CallFile = SharedData._Path + CallNum + "/" + CallNum + "-" + CallDate ; 
     if(!SharedData._Recording) 
     { 
      SharedData._Recording = true; 
      String med_state = android.os.Environment.getExternalStorageState(); 
      if(!med_state.equals(android.os.Environment.MEDIA_MOUNTED)) 
       { break; } 

      File directory = null; 
      directory = new File(RootDir + "text.txt").getParentFile(); 
      if (!directory.exists() && !directory.mkdirs()) 
       { break; } 

      directory = new File(CallDir + "text.txt").getParentFile(); 
      if (!directory.exists() && !directory.mkdirs()) 
       { break; } 

      Recoders_Init(CallFile); 
      Recorder_Prepare(); 
     } 

     break; 
    } 
} 

回答

0

我想通话录音。

这是不可能的,除非在免提模式下。

但是启动服务意图存在一个大问题。

那是因为你没有一个Service做。你有一个BroadcastReceiver。 A BroadcastReceiver不是Service。您无法拨打startService()Intent会识别BroadcastReceiver

+0

感谢您的回答CommonsWare。我成功地使用此代码录制电话,而无需使用免提电话。这个问题是基于不同类型的录音,例如:.3gp,.mp4和.amr。当我解决重新启动mediarecorder的问题时,问题就会自发解决。 – parloid