biodunalfet / VoIpUSSD

How use ussd displayed windows on Android

Home Page:https://romellfudi.github.io/VoIpUSSD/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handler USSD API

Platform API License Bintray Android Arsenal Jitpack CircleCi

by Romell Dominguez

Target Development High Quality:

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.

USSD LIBRARY

latestVersion is 1.1.c

Add the following in your app's build.gradle file:

repositories {
    jcenter()
}
dependencies {
    implementation 'com.romellfudi.ussdlibrary:ussd-library:{latestVersion}'
}
  • Writing xml config file from here to res/xml folder (if necessary), this config file allow link between App and SO:
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    .../>

Application

Puts dependencies on manifest, into manifest put CALL_PHONE, READ_PHONE_STATE and SYSTEM_ALERT_WINDOW:

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

Add service:

    <service
        android:name="com.romellfudi.ussdlibrary.USSDService"
        android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>
        <meta-data
            android:name="android.accessibilityservice"
            android:resource="@xml/ussd_service" />
    </service>

How use:

First you need an hashMap from detect witch USSD' response contains the login and error messages

KEY MESSAGE String Messages
KEY_LOGIN "espere","waiting","loading","esperando",...
KEY_ERROR "problema","problem","error","null",...
map = new HashMap<>();
map.put("KEY_LOGIN",..."waiting"...);
map.put("KEY_ERROR",..."problem"...);

Instance an object ussController with activity

ussdController = USSDController.getInstance(activity);
ussdController.callUSSDInvoke(phoneNumber, map, new USSDController.CallbackInvoke() {
    @Override
    public void responseInvoke(String message) {
        // message has the response string data
        dataToSend // send "data" into USSD's input text
        ussdController.send(dataToSend,new USSDController.CallbackMessage(){
            @Override
            public void responseMessage(String message) {
                // message has the response string data from USSD
            }
        });
    }

    @Override
    public void over(String message) {
        // message has the response string data from USSD
        // response no have input text, NOT SEND ANY DATA
    }
});

if you need work with your custom messages, use this structure:

ussdController.callUSSDInvoke(phoneNumber, map, new USSDController.CallbackInvoke() {
    @Override
    public void responseInvoke(String message) {
        // first option list - select option 1
        ussdController.send("1",new USSDController.CallbackMessage(){
            @Override
            public void responseMessage(String message) {
                // second option list - select option 1
                ussdController.send("1",new USSDController.CallbackMessage(){
                    @Override
                    public void responseMessage(String message) {
                        ...
                    }
                });
            }
        });
    }

    @Override
    public void over(String message) {
        // message has the response string data from USSD
        // response no have input text, NOT SEND ANY DATA
    }
    ...
});

OverlayShowingService Widget (not required)

A problem huge working with ussd is you cant invisible, disenable, resize or put on back in progressDialog But now on Android O, Google allow build a nw kind permission from overlay widget, my solution was a widget call OverlayShowingService: For use need add permissions at AndroidManifest:

<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />

Add Broadcast Service:

<service android:name="com.romellfudi.ussdlibrary.OverlayShowingService"
         android:exported="false" />

Invoke like a normal services, need a tittle set extra vallue EXTRA:

Intent svc = new Intent(activity, OverlayShowingService.class);
svc.putExtra(OverlayShowingService.EXTRA,"PROCESANDO");
getActivity().startService(svc);
// stop
getActivity().stopService(svc);

EXTRA: Use Voip line

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

image

License

Copyright 2018 Romell D.Z.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
<style> img[src*='#center'] { width:390px; display: block; margin: auto; } img[src*='#gif'] { width:200px; display: block; margin: auto; } </style>

About

How use ussd displayed windows on Android

https://romellfudi.github.io/VoIpUSSD/

License:Apache License 2.0


Languages

Language:Java 96.1%Language:HTML 3.9%