I created a voice call with flutter and agora.
In voice call, the user touches something, while the phone is on his ear, something opens, because the screen is on, the battery is drained quickly. What solution should I apply for this? For ios and android ?
How can I lock the screen like voice call in whatsapp?
The answer may not be relevant in flutter, I want to learn what is its mentality in android and ios.
_streamSubscriptionProximity =
ProximitySensor.events.listen((int event) async {
if (event > 0) {
await ScreenBrightness().setScreenBrightness(0.0);
} else {
await ScreenBrightness().system;
}
});
I did something like this but it's not enough I have to lock everything during the conversation
Related
When a phone is ringing ( by an incoming call) If the phone number is a specific number I want to show my custom UI. If It is not, I want to pass it to the (built-in) system call app(Or any other call app is okay).
I should use 'InCallService' and the device set my app as 'a default call app' so that even when the phone screen is locked my custom-UI-activity be shown. The following kotlin source code is my goal.
override fun onCallAdded(call: Call) {
//app should receive a new incoming call via 'onCallAdded'
super.onCallAdded(call)
val phoneNumber = getPhoneNumber(call)
if (isMyTargetNumber(phoneNumber)) {
//show my custom UI
} else {
//run a built-in call app
}
}
The problem that I want to solve is how to run a built-in call app appropriately. I mean I want to complete to wirte the blank of 'else'
else {
//run a built-in call app
}
Apps on the android market like 'truecaller' or 'whosecall' works well the way I want to acheive. I want to make my app such apps. Please help me and advise something to me.
I am trying to show a large list in react native - Expo. When I lock the screen while data loading via API. App State changed from "Active" to "Inactive".
When I return to an active state, no data has been loaded. The App processes are stopped. ListEmptyComponent renders the ActivityIndicator. It is loading indefinitely. It occurs only in android build.
I tried to recall the API by AppState.
const handleAppStateChange = nextAppState => {
console.log(nextAppState);
if (nextAppState === 'active') {
console.log(JSON.stringify(Store.apiCall));
// "Store.apiCall" has data about last API Call and its status.
if (Store.apiCall.status === codes.PENDING || Store.apiCall.status === codes.ERROR) {
api(Store.apiCall.payload);
}
}
setAppState(nextAppState);
};
Still it doesn't works..
This happening because of the battery optimization features of newer Android versions. The only fix would be to ask the user to disable the battery optimization for your app by redirecting them to your app settings or you can use a node package like this one:
https://www.npmjs.com/package/react-native-disable-battery-optimizations
Also, if you dont want your device to sleep if its in active state you can use something like this:
https://www.npmjs.com/package/react-native-keep-awake
Hope this helps :)
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.
Answering your questions:
Question1: Yes it's possible on Android. It's not possible on iOS. In Android, you can get call information if the user permits. You don't need to do jailbreaking or something. Whereas in iOS no way you can access call info.
Question2: Hope my first answer itself answers this. i.,e Android-Possible, iOS- not Possible
Question 3: AFAIK ionic framework is providing only basic details of Phone call time duration and contacts framework. You should explore more on Android to find out. Even if you use ionic framework you can't access this info at all on iPhone as native ios only not providing these details, we can't expect this from ionic framework.
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:
Add a call observer
#property ( nonatomic ) CXCallObserver *callObserver;
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.
I am developing an application for my friend who is in sales, this application will make phone calls one after another, as soon as one phone call gets disconnected, it will automatically make call to another number from the list. This list can be read from and xml data source or json or mongodb or even from excel sheet.
This could be an ios app that reads data from an end point and stores them and can initiate the call at any point and it wont stop until all the calls are made.
Next call will be made only after the first call has been finished.
I am thinking about using node based web app using google voice to trigger the chain.
I've no experience with ios / android apis but Im willing to work on that if it's a viable thing on that platform.
Note: what we're trying to avoid is whole process of
looking up the phone number.
touch hangup and then click for another phone number.
It should self trigger the next call as soon as current call gets disconnected.
Also we're trying to avoid any paid services like twillo.
Thanks in advance :)
for IOS, you could use CTCallCenter
self.callCenter = [[CTCallCenter alloc] init];
self.callCenter.callEventHandler = ^(CTCall *call){
if ([call.callState isEqualToString: CTCallStateConnected])
{
//NSLog(#"call stopped");
}
else if ([call.callState isEqualToString: CTCallStateDialing])
{
}
else if ([call.callState isEqualToString: CTCallStateDisconnected])
{
//NSLog(#"call played");
}
else if ([call.callState isEqualToString: CTCallStateIncoming])
{
}
};
Download phone list, loop inside phone list, make a call, listening for CTCallCenter and appdelegate's Event, detect user have finish last call, our app active again, then make the next call.
Or you can try in Demo here !
My app allows the user to access their corporate voice mail. Normally, durring a phone call when the user holds the device up to their ear, the screen shuts off so they wont accidentally push buttons with their face. I would like to make my app do the same thing when the user is listening to their voice mail.
anyone know how to do this?
If you are allowed to look at open source code without causing yourself problems, check the source of the Android Phone Application. Specifically src/com/android/phone/PhoneApp.java and src/com/android/phone/InCallScreen.java.
From src/com/android/phone/PhoneApp.java:
//Around line 519
// Wake lock used to control proximity sensor behavior.
if ((pm.getSupportedWakeLockFlags()
& PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) != 0x0) {
mProximityWakeLock = pm.newWakeLock(
PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
LOG_TAG);
}
....
// Around line 1334
if (((state == Phone.State.OFFHOOK) || mBeginningCall)&& !screenOnImmediately) {
// Phone is in use! Arrange for the screen to turn off
// automatically when the sensor detects a close object.
if (!mProximityWakeLock.isHeld()) {
if (DBG) Log.d(LOG_TAG, "updateProximitySensorMode: acquiring...");
mProximityWakeLock.acquire();
} else {
if (VDBG) Log.d(LOG_TAG, "updateProximitySensorMode: lock already held.");
}
} else {
// Phone is either idle, or ringing. We don't want any
// special proximity sensor behavior in either case.
if (mProximityWakeLock.isHeld()) {
if (DBG) Log.d(LOG_TAG, "updateProximitySensorMode: releasing...");
// Wait until user has moved the phone away from his head if we are
// releasing due to the phone call ending.
// Qtherwise, turn screen on immediately
int flags =
(screenOnImmediately ? 0 : PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE);
mProximityWakeLock.release(flags);
}
}
Additionally, if you look at the code for the PowerManager class, PROXIMITY_SCREEN_OFF_WAKE_LOCK is documented (but hidden) and should do what you want ( I am not sure which API level this works for, however ) -- but not in the table for some reason.
/**
* Wake lock that turns the screen off when the proximity sensor activates.
* Since not all devices have proximity sensors, use
* {#link #getSupportedWakeLockFlags() getSupportedWakeLockFlags()} to determine if
* this wake lock mode is supported.
*
* {#hide}
*/
public static final int PROXIMITY_SCREEN_OFF_WAKE_LOCK = WAKE_BIT_PROXIMITY_SCREEN_OFF;
If you aren't afraid of using a potential undocumented feature, it should do exactly what you need.
as of API level 21 (Lollipop) you can get proximity wake lock this just like that:
if(powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG);
wakeLock.setReferenceCounted(false);
return wakeLock;
} else {
return null;
}
}
then it is up to you to acquire and release the lock.
PS: PowerManager#getSupportedWakeLockFlags was hidden, but now exists nomore. They have invented isWakeLockLevelSupported instead.
Probably you don't need it anymore but for the ones that are interested in code you could have a look at my SpeakerProximity project at http://code.google.com/p/speakerproximity/
What you are seeing is the use of a proximity sensor. For devices that have one, you access it through SensorManager.