Search code examples
androidiosiphonemobilecallkit

How to Get info about phone calls


I have to develop a mobile application that monitors some info about calls, to limit users of a company to spend too much time with the phone near their ears. After x minutes, it should suggest to use earphones.

1st question: is it possible to monitor data like this? Phonecall time duration, start and end, if it's using earphones, internal or external speaker.. I mean, without using jailbreak or other hackings.

2nd question: is it possible doing this for IOS and Android?

3rt question: Do you know if Ionic has the capability to that?

Thank you.


Solution

  • For Android:

    • You can easily get the call history or incoming and outgoing call time. So it is possible in android.

    For iOS:

    According to your question you want to limit the current calling time of phone near their ears.

    So you also do it in iOS by some smartness.

    • In iOS 10 a new framework introduces for calling i.e. CallKit.
    • First, you have to get all contact in your application.
    • So user should call from your app.
    • For dialing also add the custom phone dialer.

    By Some method of callKit you can do:

    1. Add a call observer

      @property ( nonatomic ) CXCallObserver *callObserver;

    2. Initialize the call observer:

      • (instancetype)init { self = [super init]; if (self) {

            //Initialize the call observer
            _callObserver = [CXCallObserver new];
            [_callObserver setDelegate:self queue:dispatch_get_main_queue()];
        }
        return self;
        

        }

    Add the delegate of call kit

    #pragma mark - CXCallObserverDelegate
    - (void)callObserver:(CXCallObserver *)callObserver callChanged:(CXCall *)call{
        [self callStateValue:call];
    }
    
    #pragma mark - Callkit State
    - (void)callStateValue:(CXCall *)call {
    
        NSLog(@"Call UIID: %@", call.UUID);
        NSLog(@"hasEnded     %@", call.hasEnded? @"YES":@"NO");
        NSLog(@"isOutgoing   %@", call.isOutgoing? @"YES":@"NO");
        NSLog(@"isOnHold     %@", call.isOnHold? @"YES":@"NO");
        NSLog(@"hasConnected %@", call.hasConnected? @"YES":@"NO");
    
        if (call == nil || call.hasEnded == YES) {
            NSLog(@"CXCallState : Disconnected");
            [timer1 invalidate];
            NSLog(@"%ld",(long)self.duration);
            if(self.duration>1)
            self.duration=1;
        }
    
        if (call.isOutgoing == YES && call.hasConnected == NO) {
        }
    
        if (call.isOutgoing == NO  && call.hasConnected == NO && call.hasEnded == NO && call != nil) {
            self.duration = 0;
            NSLog(@"CXCallState : Incoming");
            NSLog(@"Call Details: %@",call);
        }
    
        if (call.hasConnected == YES && call.hasEnded == NO) {
            NSLog(@"CXCallState : Connected");
        timer1 = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
            self.duration++;
            NSLog(@"%ld",(long)self.duration);
        }];
    
        }
    }
    

    You can get the time duration and also add the condition After x minutes, it should suggest to use earphones.