Giter VIP home page Giter VIP logo

simple-phone's Introduction

Simple Phone

This project shows the absolute minimum an Android Phone app needs to implement to replace the native phone app and provide the UI when making calls. It was created to address the lack of good documentation, evidenced by multiple questions on stackoverflow (1), (2).

This app uses minSdkVersion 23, because that's when the APIs supporting this were added.

There are two steps an app has to make to show its own UI during an ongoing call. One is to implement an InCallService that Android will use to notify you about events related to the calls. But before the system will let you know about any call, the user must first choose your app as the default Phone app, and you need to make it available to him as such.

Becoming a default Phone app

To have your app listed as a Phone app, you must have an activity with at least those intent filters (to handle both cases mentioned in documentation of ACTION_DIAL, also mentioned in DefaultDialerManager hidden class):

<intent-filter>
    <action android:name="android.intent.action.DIAL" />
    <data android:scheme="tel" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.DIAL" />
</intent-filter>

And to be honest, that's a bit counterintuitive, because setting the default Phone app is separate from setting a default Dialer โ€“ the former controls only the ongoing call UI, while the latter controls only the dialing UI.

Filters in the AndroidManifest improve a bit over that minimum, to allow setting the app as the default Dialer, and launching dialer from web browser. The Dialer app in AOSP has even more filters declared.

Anyway, this will make your app available in the Settings -> Apps & notifications -> Advanced -> Default apps -> Phone app:

settings

You can make it easier for the user to set your app as the default Phone app with the help from TelecomManager:

if (getSystemService(TelecomManager::class.java).defaultDialerPackage != packageName) {
    Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER)
            .putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName)
            .let(::startActivity)
}

This will show a dialog similar to this:

change default dialer dialog

Handling calls

You need to define an InCallService implementation the system will bind to and notify you about the call:

<service
    android:name=".CallService"
    android:permission="android.permission.BIND_INCALL_SERVICE">
    <meta-data
        android:name="android.telecom.IN_CALL_SERVICE_UI"
        android:value="true" />
    <intent-filter>
        <action android:name="android.telecom.InCallService" />
    </intent-filter>
</service>

There you should handle at least onCallAdded (set up listeners on Call, start your UI - activity - for the call) and onCallRemoved (remove listeners), like CallService does in a simplified way.

If the user wants to answer the call, you need to invoke the method Call#answer(int) (with VideoProfile.STATE_AUDIO_ONLY for example). In this example CallActivity reacts to user input by calling those methods on Call object shared through the OngoingCall singleton.

Check out Call.Callback for events that can happen with a single call. This sample uses just the onStateChanged callback, to update the UI and finish the activity when the remote party hangs up.

call

simple-phone's People

Contributors

arekolek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

simple-phone's Issues

Ongoing.call is sometimes null in when answer/hangup

Hello,

Thanks for this little app, it is really amazing!
However, recently I receive kotlin.KotlinNullPointerException in OngoingCall.answer with stack trace:

com.github.arekolek.phone.OngoingCall.answer OngoingCall.kt:29
com.github.arekolek.phone.CallActivity$onStart$7.invoke CallActivity.kt:85
com.github.arekolek.phone.CallActivity$onStart$7.invoke CallActivity.kt:27
com.github.arekolek.phone.CallActivity$subscribeWithDelay$2.accept CallActivity.kt:128
io.reactivex.internal.observers.LambdaObserver.onNext LambdaObserver.java:63
io.reactivex.observers.SerializedObserver.onNext SerializedObserver.java:111
io.reactivex.internal.operators.observable.ObservableDelay$DelayObserver$OnNext.run ObservableDelay.java:114
io.reactivex.internal.schedulers.ScheduledRunnable.run ScheduledRunnable.java:66
io.reactivex.internal.schedulers.ScheduledRunnable.call ScheduledRunnable.java:57
java.util.concurrent.FutureTask.run FutureTask.java:266

The stack trace is not showing CallActivity$onStart$.onClick because here I pickup phone automatically with delay in CallActivity

        // Autopickup with delay
        OngoingCall.state
                .filter{ it == Call.STATE_RINGING && isAutopickup() }
                .subscribeWithDelay(
                        Random.nextLong(pickupDelayFrom, pickupDelayTo),
                        "$autopickupNumber will be picked after {delay} sec"
                ) { OngoingCall.answer()
                    muteMic() }
                .addTo(disposables)

I was looking through the code and I really can't see a situation when OngoingCall.call will be null at this step...

Maybe you have any ideas on why this could happen? So I can try to build a workaround...

Kind regards!
Max

Can I create the same app in flutter?

Hi. I am developing an app in flutter. I want to create an app like this. I don't know java or kotlin. How can I implement this in flutter. Kindly help me. Thanks in advance.

Stop default ringtone when get call

Hi, I have a query. I am new to kotlin and android. I don't know how to stop the default ringtone when I get called. How to implement this? Kindly help me to implement this. Thanks in advance.

Question: Any idea how to clone the Phone app of Android

This repository is nice, but the full implementation of all things in a during call UI is probably much larger.

Do you know perhaps how to clone correctly the official Phone app, or at least just the part of during the call?

I've tried here:
https://android.googlesource.com/platform/packages/apps/Dialer

But it is so messy and I don't get what to do with the folders. The IDE failed to just import it all.

However, I've found 2 repositories that have it working, though in a bit old version (Android N) of the Phone app:

How did they do it? Can you please show, step by step, how to import it all into a working project ?

The screen doesn't turn off during call

Hello, I have noticed that during a call the screen doesn't turn off with the proximity sensor, I tried several codes but it was in vain. Any help would be greatly appreciated.

Suggestion dialog with deafult dialer icon instead custom dialer icon

Steps:
0. reset apps settings(if installed previously)

  1. click by phone number click (in browser)
  2. select in suggestion dialog "CustomPhoneDialer"
  3. launch
  4. confirm "set as default"
  5. enter/edit number + click done
  6. appeared dialog with default dialer icon and skype (for example) -> by click on the default dialer icon opening CustomPhoneDialer.

Huawei P10Lite, android 8; Samsung S8+;
Why is show icon from default? How to change such behaviour?

Code for java

Hello, I really appreciate the work you have done in Kotlin. But, while integrating it to an existing Java project. Handling observers are quite confusing and leading to nullpointer or no UI update. Can you help me a little bit?

CallService not invoking in xiaomi devices.

Describe the bug

I wanted to call from the app and when I clicked the number I want to call, I got redirected to my phone default caller.

To Reproduce

  1. Open the app
  2. Pick any number and dial.
  3. Note the issue

I debug the app and notice that CallService not invoking.

Device Details

  • SDK:23,
  • Brand:Xiaomi,
  • Model:Redmi 3S

Does not work when screen is off

I managed to write a code to replace default phone app as explained in this repository. It is working only when screen is turned on. If screen is turned off, I can only hear ring tone, screen does not turn on. If I turn on screen manually, I can't see any call interface (not mine or not system default phone app. So I can't handle answer that call). How can I turn on screen when phone rings? I've tried several solutions about how to turn on screen, but no one is working in this case.

Any suggestions?

Question: is it possible to show the built in during-call-UI, from this one?

There are tons of functions that are available for when you have the control here, of the during-call-UI.

Is it possible, since a developer might not implement&use all of them, to revert back to the built-in-UI ?

For example, suppose I create an app based on this sample, that only offers to answer and reject calls.

This means I didn't handle conference calls, video calls, etc...

Is there an API of some sort, that allows me to put a button on the UI, to go back to the built-in-UI ? One that has everything else covered?

Or once I replace the UI, I have to implement it all? Meaning all or nothing?

doesn't build with android studio 2023.2.1

i try to build it and i get the error:
Unable to find method ''org.gradle.api.file.DirectoryProperty org.gradle.api.file.ProjectLayout.directoryProperty(org.gradle.api.provider.Provider)''
'org.gradle.api.file.DirectoryProperty org.gradle.api.file.ProjectLayout.directoryProperty(org.gradle.api.provider.Provider)'

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

Question: how to handle immersive mode apps?

In the built in dialer, in case you are in an immersive app (playing a game or watching a video), and someone calls you, you get a notification instead of a full screen Activity asking you what to do.

Is it possible to handle it too, using the new API ?
Maybe even give the user a choice, of whether to show it as notification or a full screen Activity ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.