To comunicate with ussd display, It is necessary to have present that the interface depends on the SO and on the manufacturer of Android device.
latestVersion
is 1.0.b
Add the following in your app's build.gradle
file:
repositories {
jcenter()
}
dependencies {
compile 'com.romellfudi.ussdlibrary:ussd-library:{latestVersion}'
}
Build a accessibility service class:
Capture information from USSD displaying windows, excist two ways:
- Writting code:
- Writting xml, this link manifest to SO:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes
="typeWindowStateChanged"
android:packageNames="com.android.phone"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagDefault"
android:canRetrieveWindowContent="true"
android:description="@string/accessibility_service_description"
android:notificationTimeout="0"/>
Configure build.gradle file, add exteension for run aar libraries(witch we build and export)
allprojects { repositories { ...
flatDir { dirs 'libs' } } }
Configure ussd library dependencies on app module {debugCompile: attach library module, releaseCompile: import *.aar library}
dependencies {
...
//debugCompile project(':ussdlibrary')
//releaseCompile(name: 'ussdlibrary-{latestVersion}', ext: 'aar')
implementation 'com.romellfudi.ussdlibrary:ussd-library:{latestVersion}'
}
Puts dependencies on manifest, into manifest put CALL_PHONE, READ_PHONE_STATE and SYSTEM_ALERT_WINDOW:
In this secction leave the lines to call to Telcom (ussd hadh number) for connected it:
ussdPhoneNumber = ussdPhoneNumber.replace("#", uri);
Uri uriPhone = Uri.parse("tel:" + ussdPhoneNumber);
context.startActivity(new Intent(Intent.ACTION_CALL, uriPhone));
Once initialized the call will begin to receive and send the famous USSD windows
<style> img[src*='#center'] { width:400px; display: block; margin: auto; } img[src*='#gif'] { width:200px; display: block; margin: auto; } </style>