无法启动服务 Intent { flg=0x10000000 cmp=com.company.callrecorder/.CallStateListener }:未找到

发布于 2024-12-09 00:09:23 字数 3753 浏览 0 评论 0原文

我正在尝试录音。但启动服务意图有一个很大的问题。

WARN/ActivityManager(61): 无法启动服务 Intent { flg=0x10000000 >cmp=com.company.callrecorder/.CallStateListener }: 未找到

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

        public class StartServicesAtStartUp extends BroadcastReceiver

{ 公共静态意图phoneStateListener; 公共无效onReceive(上下文上下文,意图意图) { Log.d("DEBUG", "com.its.CallRecorder 启动..."); Toast.makeText(context,"通话录音已启动..",Toast.LENGTH_SHORT).show(); Start_CallRec(上下文); CallStateListener.java

    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();
        }
    }

代码

是:

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;
    }
}

I'm trying to record calls. But there is a big issue in starting service intent.

WARN/ActivityManager(61): Unable to start service Intent { flg=0x10000000 >cmp=com.company.callrecorder/.CallStateListener }: not found

This is my Broadcastreceiver code:

        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();
        }
    }

}

And CallStateListener.java code is:

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;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扎心 2024-12-16 00:09:23

我正在尝试录音。

这是不可能的,除非处于免提模式。

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

那是因为您没有服务。您有一个BroadcastReceiverBroadcastReceiver 不是 Service。您不能使用标识 BroadcastReceiverIntent 来调用 startService()

I'm trying to record calls.

This is not possible, except perhaps when in speakerphone mode.

But there is a big issue in starting service intent.

That is because you do not have a Service. You have a BroadcastReceiver. A BroadcastReceiver is not a Service. You cannot call startService() with an Intent identifying a BroadcastReceiver.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文