有没有办法在 React native android 中检测最近的电话通话时长

Posted

技术标签:

【中文标题】有没有办法在 React native android 中检测最近的电话通话时长【英文标题】:Is there any way to detect recent phone call duration in React native android 【发布时间】:2021-03-25 00:47:49 【问题描述】:

我正在使用一个呼叫应用程序,我需要检测我刚刚拨打的最近电话的通话时长。那么是否有任何软件包或任何方法可以做到这一点?

【问题讨论】:

【参考方案1】:

没有提供最近通话时长的特定方式或库,但您可以使用 react-native-call-detection 提供来电监听器,例如

import CallDetectorManager from 'react-native-call-detection'

startListenerTapped() 
    this.callDetector = new CallDetectorManager((event, phoneNumber)=> 
    // For ios event will be either "Connected",
    // "Disconnected","Dialing" and "Incoming"

    // For android event will be either "Offhook",
    // "Disconnected", "Incoming" or "Missed"
    // phoneNumber should store caller/called number


    if (event === 'Disconnected') 
    // Do something call got disconnected
    
    else if (event === 'Connected') 
    // Do something call got connected
    // This clause will only be executed for iOS
    
    else if (event === 'Incoming') 
    // Do something call got incoming
    
    else if (event === 'Dialing') 
    // Do something call got dialing
    // This clause will only be executed for iOS
    
    else if (event === 'Offhook') 
    //Device call state: Off-hook.
    // At least one call exists that is dialing,
    // active, or on hold,
    // and no calls are ringing or waiting.
    // This clause will only be executed for Android
    
    else if (event === 'Missed') 
        // Do something call got missed
        // This clause will only be executed for Android
  
,
false, // if you want to read the phone number of the incoming call [ANDROID], otherwise false
()=>, // callback if your permission got denied [ANDROID] [only if you want to read incoming number] default: console.error

title: 'Phone State Permission',
message: 'This app needs access to your phone state in order to react and/or to adapt to incoming calls.'
 // a custom permission request message to explain to your user, why you need the permission [recommended] - this is the default one
)


stopListenerTapped() 
    this.callDetector && this.callDetector.dispose();

【讨论】:

我已经尝试过了,但这并不能检测是否有人接听了电话。在每种情况下,两种方法 ;'offhook' 和 'disconnected' 按顺序执行,但当有人接电话时没有人执行

以上是关于有没有办法在 React native android 中检测最近的电话通话时长的主要内容,如果未能解决你的问题,请参考以下文章

有没有办法从 Native Android Code 调用 React Native 函数?

有没有办法可以将 Text 组件的全部内容包装在 react-native 中的父视图中?

有没有办法在不弹出的情况下删除 react-native 中的默认权限?

有没有办法在 React Native(适用于 Android)中添加视频元素?

有没有办法在 React Native 中使用字体功能设置

有没有办法在 iOS 中使用 react-native 来制作像 Android StaggeredGridView 这样的布局