Skip to content

Commit

Permalink
New message structure, use calllback to catch each message,
Browse files Browse the repository at this point in the history
README files update, change snapshot to code lines
  • Loading branch information
romellfudi committed Sep 27, 2018
1 parent 11da1c1 commit 2a745a1
Show file tree
Hide file tree
Showing 19 changed files with 457 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .project
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>VoIpUSSDSample</name>
<name>VoIpUSSD</name>
<comment>Project BIOX_USSD created by Buildship.</comment>
<projects>
</projects>
Expand Down
128 changes: 95 additions & 33 deletions README.es.md
Expand Up @@ -18,7 +18,7 @@ Para manejar la comunicaci贸n ussd, hay que tener presente que la interfaz depen

## USSD LIBRARY

`latestVersion` is 1.0.b
`latestVersion` is 1.1.b

Agregar en tu archivo `build.gradle` del proyecto Android:

Expand All @@ -31,60 +31,122 @@ dependencies {
}
```

Construir una clase que extienda de los servicios de accesibilidad:
* Escribir el archivo xml [ac谩](https://github.com/romellfudi/VoIpUSSD/blob/master/ussd-library/src/main/res/xml/ussd_service.xml) to res/xml folder (if necessary), this config file allow link between App and SO:

![image](snapshot/G.png#center)
```xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
.../>
```

En ella capturara la informaci贸n de la pantalla USSD con el SO la visualice, para ello existen 2 maneras:
### Application

* via c贸digo:
Agregar las dependencias: CALL_PHONE, READ_PHONE_STATE and SYSTEM_ALERT_WINDOW:

![image](snapshot/H.png#center)
```xml
<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" />
```

* via xml, el cual deberas vincular en el manifest de tu aplicaci贸n:
Agregar el servicio:

```xml
<?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"/>
<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>
```

# Uso del API:

### Aplicaci贸n
Instancia un objeto ussController con su activity

Configuramos en el archivo build.gradle, la extensi贸n para leer librerias *.aar (la cu谩l crearemos y exportaremos)
```java
ussdController = USSDController.getInstance(activity);
ussdController.callUSSDInvoke(phoneNumber, new USSDController.CallbackInvoke() {
@Override
public void responseInvoke(String message) {
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
}
});
```gradle
allprojects { repositories { ...
flatDir { dirs 'libs' } } }
```
Configuramos la dependencia de la libraria ussdlibrary mediante los prefijs {debugCompile: llamar a m贸dulo de la libreria, releaseCompile: llamar al empaquetado *.aar}
Si requiere un flujo de trabajo, tienes que usar la siguiente estructura:
```gradle
dependencies {
```java
ussdController.callUSSDInvoke(phoneNumber, 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
}
...
//debugCompile project(':ussdlibrary')
//releaseCompile(name: 'ussdlibrary-{latestVersion}', ext: 'aar')
implementation 'com.romellfudi.ussdlibrary:ussd-library:{latestVersion}'
}
});
```
## OverlayShowingService Widget (no indispensable)
Un severo problema al manejar este tipo de widget, este no puede ocultarse, redimencionarse, no puede ser puesto en el fondo con un rogressDialog
Pero recientemente a partir del Android O, Google permite la construcci贸n build a nw kind permission dde widget sobrepuestos, mi soluci贸n implementada fue este widget llamdo `OverlayShowingService`:
For use need add permissions at AndroidManifest:
```xml
<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />
```
Agregar Broadcast Service:
Teniendo importada las dependencias, en el manifest de la aplicaci贸n se debe escribir el servicio con los permisos necesarios
```xml
<service android:name="com.romellfudi.ussdlibrary.OverlayShowingService"
android:exported="false" />
```
![image](snapshot/J.png#center)
Invocar como cualquier servicio, necesita un titulo para ser mostrado mientras se ejecuta la llama `callUSSDInvoke` mediante una variable extra `EXTRA`:
![image](snapshot/F.png#center)
```java
Intent svc = new Intent(activity, OverlayShowingService.class);
svc.putExtra(OverlayShowingService.EXTRA,"PROCESANDO");
getActivity().startService(svc);
```
### Uso de la l铆nea voip
### EXTRA: Uso de la l铆nea voip
En esta secci贸n dejo las l铆neas claves para realizar la conexi贸n VOIP-USSD
Expand Down
131 changes: 97 additions & 34 deletions README.md
Expand Up @@ -18,7 +18,7 @@ To comunicate with ussd display, It is necessary to have present that the interf

## USSD LIBRARY

`latestVersion` is 1.0.b
`latestVersion` is 1.1.b

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

Expand All @@ -27,63 +27,126 @@ repositories {
jcenter()
}
dependencies {
compile 'com.romellfudi.ussdlibrary:ussd-library:{latestVersion}'
implementation 'com.romellfudi.ussdlibrary:ussd-library:{latestVersion}'
}
```

Build a accessibility service class:
* Writing xml config file from [here](https://github.com/romellfudi/VoIpUSSD/blob/master/ussd-library/src/main/res/xml/ussd_service.xml) to res/xml folder (if necessary), this config file allow link between App and SO:

![image](snapshot/G.png#center)
```xml
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
.../>
```

Capture information from USSD displaying windows, excist two ways:
### Application

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

![image](snapshot/H.png#center)
```xml
<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" />
```

* Writting xml, this link manifest to SO:
Add service:

```xml
<?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"/>
<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:

### Application
Instance an object ussController with activity

Configure build.gradle file, add exteension for run aar libraries(witch we build and export)
```java
ussdController = USSDController.getInstance(activity);
ussdController.callUSSDInvoke(phoneNumber, new USSDController.CallbackInvoke() {
@Override
public void responseInvoke(String message) {
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
}
});
```gradle
allprojects { repositories { ...
flatDir { dirs 'libs' } } }
```
Configure ussd library dependencies on app module {debugCompile: attach library module, releaseCompile: import *.aar library}
if you need work with your custom messages, use this structure:
```gradle
dependencies {
```java
ussdController.callUSSDInvoke(phoneNumber, 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
}
...
//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:
## 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:
```xml
<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />
```
Add Broadcast Service:
![image](snapshot/J.png#center)
```xml
<service android:name="com.romellfudi.ussdlibrary.OverlayShowingService"
android:exported="false" />
```
![image](snapshot/F.png#center)
Invoke like a normal services, need a tittle set extra vallue `EXTRA`:
```java
Intent svc = new Intent(activity, OverlayShowingService.class);
svc.putExtra(OverlayShowingService.EXTRA,"PROCESANDO");
getActivity().startService(svc);
```
### Use Voip line
### EXTRA: Use Voip line
In this secction leave the lines to call to Telcom (ussd hadh number) for connected it:
Expand Down
18 changes: 7 additions & 11 deletions app/build.gradle
Expand Up @@ -12,11 +12,11 @@ android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "fudi.freddy.biox_ussd"
applicationId "com.romellfudi.ussd_sample"
minSdkVersion 17
targetSdkVersion 26
versionCode 1
versionName "1.0"
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -28,15 +28,11 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'

// compile(name: 'fudipermission-1.0.a', ext: 'aar')

// debugCompile project(':ussd-library')
// releaseCompile(name: 'ussdlibrary-1.0.b', ext: 'aar')

implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.romellfudi.permission:fudi-permission:1.0.a'
implementation 'com.romellfudi.ussdlibrary:ussd-library:1.0.b'

implementation project(':ussd-library')
// implementation 'com.romellfudi.ussdlibrary:ussd-library:1.1.b'

}
Binary file removed app/libs/fudipermission-1.0.a.aar
Binary file not shown.
Binary file removed app/libs/ussdlibrary-1.0.b.aar
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="fudi.freddy.biox_ussd">
package="com.romellfudi.ussd_sample">
<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" />
Expand Down

0 comments on commit 2a745a1

Please sign in to comment.