<! -? xml version = "1.0" encoding = "utf-8"? ->
<linearlayout xmlns: android = "schemas.android.com/apk/res/android"
android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent" >
<autocompletetextview
android: layout_width = "fill_parent"
android: text = ""
android: layout_height = "wrap_content"
android: inputtype = "phone | textUri"
android: id = "@ + id / Text1" >
<requestfocus > </ requestfocus >
</ autocompletetextview >
<textview
android: layout_width = "fill_parent"
android: id = "@ + id / Text2"
android: layout_height = "wrap_content" >
</ textview >
<button
android: text = "@ string / send"
android: id = "@ + id / button1"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content" >
</ button >
</ linearlayout >
// I do not write all the imports, I will only write what do not forget to connect the USSD class
import com.example.android.UssdMessage.USSD ;
public class UssdmessageActivity extends Activity implements OnClickListener {
/ ** Called when the activity is first created. * /
private TextView view ;
private AutoCompleteTextView number ;
Override
public void onCreate ( Bundle savedInstanceState ) {
super . onCreate ( savedInstanceState ) ;
setContentView ( R. layout . main ) ;
Button button = ( Button ) findViewById ( R. id . Button1 ) ;
button. setOnClickListener ( this ) ;
this . view = ( TextView ) findViewById ( R. id . Text2 ) ;
this . number = ( AutoCompleteTextView ) findViewById ( R. id . Text1 ) ;
}
Override
public void onClick ( View arg0 ) {
String encodedHash = Uri. encode ( "#" ) ;
call ( " * " + number. getText ( ) + encodedHash ) ;
this . view . setText ( "" ) ;
}
protected void call ( String phoneNumber ) {
try {
startActivityForResult (
new Intent ( "android. intent . action . CALL ", Uri. parse ( "tel : "
+ phoneNumber ) ) , 1 ) ;
} catch ( Exception eExcept ) {
this . view . append ( "nn" + "n" + eExcept. toString ( ) ) ;
}
}
Override
protected void onActivityResult ( int requestCode, int resultCode, Intent data ) {
USSD ussd = new USSD ( 4000 , 4000 ) ; // two parameters are transmitted, delay before and after (ms) of message creation
if ( ussd. IsFound ( ) )
this . view . append ( "n" + ussd. getMsg ( ) ) ;
else
this . view . append ( "" + R. string . error_ussd_msg ) ;
}
}
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> <uses-permission android:name="android.permission.CALL_PRIVILEGED"></uses-permission> <uses-permission android:name="android.permission.READ_LOGS"></uses-permission>
Source: https://habr.com/ru/post/130717/
All Articles