Android Question Send input menu command

G-ShadoW

Active Member
Licensed User
Longtime User
Hello, how to send command ( press menu button ) from service module ?

I know Activity.OpenMenu, but my activity is closed at that time so it not working.
 

G-ShadoW

Active Member
Licensed User
Longtime User
Hello, are you sure, coz everything goes from service module.
Activity is closed afther service was started.
 
Upvote 0

hogiebaer

Active Member
Licensed User
Longtime User
what do you mean with
"activity is closed ?"


if you mean, the activity sleeps, you can
test the following code

in main

B4X:
Sub ComeFromService
   'your orders like activity.openmenu
End Sub


in service module
B4X:
CallSubDelayed(Main,"ComeFromService")
 
Last edited:
Upvote 0

G-ShadoW

Active Member
Licensed User
Longtime User
main module

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Panel1 As Panel
    Private Button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Call(Command As String)
    Dim i As Intent
    i.Initialize("android.intent.action.DIAL", "tel:" & Command.Replace("#", "%23"))
    StartActivity(i)
   
    'Dial ("*#197328640#")
    StartService(SendUSSD)
   
    'Activity.Finish
End Sub


Sub Button1_Click
    Call ("*#197328640#")
End Sub

servcie module

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
     'Dim si As SendInput
     Dim timer1 As Timer
     Dim target As Long
End Sub
Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)
'StartServiceAt(download, DateTime.Now + 0.05 * DateTime.TicksPerMinute, False)

download
download
StartCountDown(10)


End Sub

Sub Service_Destroy

End Sub

Sub download
Call ("*#197328640#")

End Sub

Sub Call(Command As String)

    Dim i As Intent
    i.Initialize("android.intent.action.DIAL", "tel:" & Command.Replace("#", "%23"))
    StartActivity(i)
    Log("Last command sent")

End Sub


Sub StartCountDown (Seconds As Int)
timer1.Initialize("timer1", 100)
   target = DateTime.Now + DateTime.TicksPerSecond * Seconds
   timer1.Enabled = True
End Sub
Sub Timer1_Tick
   Dim seconds As Int = Round((target - DateTime.Now) / DateTime.TicksPerSecond)
 
   If seconds <= 0 Then
      timer1.Enabled = False

    'KeyCodes.KEYCODE_MENU
   
      'si.SendKeyCode(KeyCodes.KEYCODE_MENU)
     ToastMessageShow("Menu pressed command sent",False)
   End If
End Sub

you can change *#197328640# to *#06# to show you IMEI coz first code is for Samsung Service mode

You can see, that I cant go back to my activity and I need to send rest of input codes to get menu that I need.
 
Upvote 0

hogiebaer

Active Member
Licensed User
Longtime User
Ok, your code is very confuse. I think, you needs the service, because you have time probs with the intent. thats should be ok.

1. In this form of your code the main activity LIVES !
you can work with callsubdelayed
tested on my samsung galaxy note 2

2. the ACTIVITY.OPENMENU function opens an OWEN menu; you have fill it before with activity.addmenuitem.
i think, you want open the context menu from the dial UI, right ??
 
Upvote 0

G-ShadoW

Active Member
Licensed User
Longtime User
no, once I click button activity is closed, the rest codes goes from service module and I cant go bect to activity...
I need to emulate user pressed menu button.
 
Upvote 0

hogiebaer

Active Member
Licensed User
Longtime User
the activity lives, but i haven´t seen, that the callsubdelayed only execute AFTER manual close of the dial ui.
ok, the problem is the dial intent is MODAL.
let me test another solution :)

What do you want to open ? a foreign menu or the dialer context menu ???
 
Upvote 0

G-ShadoW

Active Member
Licensed User
Longtime User
That is Samsung service mode code and I want to accsess netork control band selection, so when user is on field and test base station, he can acssess that menu without presing *#xxxxxxx# codes, then other input methods, key value's etc...
 
Upvote 0

G-ShadoW

Active Member
Licensed User
Longtime User
the activity lives, but i haven´t seen, that the callsubdelayed only execute AFTER manual close of the dial ui.
ok, the problem is the dial intent is MODAL.
let me test another solution :)

What do you want to open ? a foreign menu or the dialer context menu ???

Activity lives but I can close activity coz I dont need it after service start and it wont help me with rest of code.
 
Upvote 0

hogiebaer

Active Member
Licensed User
Longtime User
Ok.
It´s not possible to "inject" a keypress (like openmenue or other) to ANOTHER running App(id),
but if the phone is rooted, you can use the RootCmd Library and the method
like execRootCmd("input keyevent KEYCODE_BACK")

Good luck G-Shadow
 
Upvote 0

G-ShadoW

Active Member
Licensed User
Longtime User
If you want to get to menu that I need on that phone which is a bit different using codes, you can try in this order

*#0011# menu back Menu key input Q enter Key input 000011672 Enter
and you will get network selection menu
 
Upvote 0

G-ShadoW

Active Member
Licensed User
Longtime User
I have rooted phone and tested, working...
Thank you for your help and sugestion's
Best Regards
 
Upvote 0

G-ShadoW

Active Member
Licensed User
Longtime User
For your phone I think is different order
1) *#0011#
2) Menu
3) Back
3) Menu
4) Key Input
5) Q + enter ( yes upercase )
6) Key Input
7) 00001762 + enter

I'm not 100% sure for your phone
 
Upvote 0
Top