Android Question Send input menu command

Discussion in 'Android Questions' started by G-ShadoW, Jun 18, 2015.

  1. G-ShadoW

    G-ShadoW Active Member Licensed 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.
     
  2. hogiebaer

    hogiebaer Active Member Licensed User

    "callsubdelayed" could be your friend
     
  3. G-ShadoW

    G-ShadoW Active Member Licensed User

    Hello, are you sure, coz everything goes from service module.
    Activity is closed afther service was started.
     
  4. hogiebaer

    hogiebaer Active Member Licensed User

    what do you mean with
    "activity is closed ?"


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

    in main

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

    in service module
    Code:
    CallSubDelayed(Main,"ComeFromService")
     
    Last edited: Jun 18, 2015
  5. G-ShadoW

    G-ShadoW Active Member Licensed User

    main module

    Code:
    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

    Code:
    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.
     
  6. hogiebaer

    hogiebaer Active Member Licensed 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 ??
     
  7. G-ShadoW

    G-ShadoW Active Member Licensed 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.
     
  8. hogiebaer

    hogiebaer Active Member Licensed 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 ???
     
  9. G-ShadoW

    G-ShadoW Active Member Licensed 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...
     
  10. G-ShadoW

    G-ShadoW Active Member Licensed User

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

    hogiebaer Active Member Licensed User

    i test with services codes for my note2 (*#0011#)
    please be patient :)
     
  12. hogiebaer

    hogiebaer Active Member Licensed 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
     
  13. G-ShadoW

    G-ShadoW Active Member Licensed 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
     
  14. G-ShadoW

    G-ShadoW Active Member Licensed User

    I have rooted phone and tested, working...
    Thank you for your help and sugestion's
    Best Regards
     
  15. G-ShadoW

    G-ShadoW Active Member Licensed User

  16. hogiebaer

    hogiebaer Active Member Licensed User

    very nice :)
    i have tested your code for my note2. only the *#0011# works, the 000011672 doesnt. The 'Q' is upcase ?
     
  17. G-ShadoW

    G-ShadoW Active Member Licensed 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
     
Loading...