Telefonowanie z aplikacji

jak wykonać telefon z aplikacji AI2


Use the MakePhoneCallDirect block from the PhoneCall component.

Directly initiates a phone call using the number in the PhoneNumber property, bypassing user interaction to start the call.

Używam PhoneCallDirect, czy można z poziomu aplikacji w AI2 przerwać połczenie z wybranym użytkownikiem w sytuacji gdy nie obiera połaczenia. Próbowałem użyć clock, TimerEnabled i zdarzenia WhenPhoneCall.PhoneCallStarted ale nie działa. Aplikacja dla niepelnosprawnych.

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

Uploading: blocks (64).png…




Uploading: blocks (61).png…

What exactly is not working?
The phone call itself?
It looks like you forgot to ask for permission and to set the phone number

http://ai2.appinventor.mit.edu/reference/components/social.html#PhoneCall

MakePhoneCallDirect()
Directly initiates a phone call using the number in the PhoneNumber property, bypassing user interaction to start the call. Most apps should use MakePhoneCall instead, which requires no permissions.

Taifun

How do you test?
Using the companion app or the apk file?
Try the apk file

EDIT: or try the companion app version downloadable from the App Inventor page

Taifun

Telefonowanie działa. Chciałbym aby po połączeniu z wybranym numerem ( to działa prawidłowo), była możliwość przerwania połączenia w przypadku kiedy osoba do której się dzwoni - nie odbiera telefonu. Wtedy chciałbym ustawić czas zwłoki np na 20 sekund (clock2) i po tym czasie przerwać połączenie. Nie działa blok
when Clock2.Timer

Not possible
After starting the phone call, the phone app is active and your own app is in the background
You can't stop another app from the background

Taifun

Bardzo dziękuję.

This is what Gemini is telling us
Taifun


Programmatically ending a phone call in Android has become increasingly restricted with newer Android versions due to security and privacy concerns. What was once possible with direct access to internal APIs is now either deprecated, requires a system app, or uses different approaches for specific use cases.
Here's a breakdown of the common approaches and a Java example for the more modern (and restricted) method, along with important considerations:

Key Considerations:

  • Android Version: The method to end a call varies significantly by Android API level.

    • Android 9 (Pie) and above (API 28+): The TelecomManager.endCall() method is the official (but still privileged) way.
    • Older Android Versions (below API 28): Relying on reflection to access hidden ITelephony interfaces was a common workaround. This approach is highly discouraged as it's undocumented, unstable, and can break with any Android update. Most devices running newer Android versions actively block this.
  • Permissions: Ending a call requires sensitive permissions.

    • android.permission.ANSWER_PHONE_CALLS (for Android 9+)
    • android.permission.MODIFY_PHONE_STATE (for older versions, and often requires your app to be a system app or device owner)
  • App Type:

    • Normal Apps: For regular user-installed apps, directly ending an ongoing call (especially if it's not initiated by your app) is generally not allowed without special device owner or system app privileges.
    • Call Screening Apps: If your app is designed for call screening (e.g., blocking spam calls), Android provides the CallScreeningService API, which allows you to reject incoming calls. This is the recommended and official way for such functionality.
    • System Apps/Device Owners: Apps with elevated privileges (like those pre-installed by device manufacturers or deployed as device owner apps in enterprise settings) have more control.

In summary, if you are developing a standard user application, directly ending an ongoing call is almost certainly not possible due to Android's strict security model. If your app has a specific use case like call screening, you should explore the CallScreeningService API.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.