Kill Process not working from service

sangee

Member
Licensed User
Longtime User
Hi,

I am trying to make a service app which runs to manage start and stop of a designated application. The code reads the SMS inbox, checks if it is from a designated number "+91999999003", checks if the body is having "Appstop", then tries to kill the app. Can any one please guide me why the code does not work? both the method of shell and OS.killprocess does not work.The toastmessage indicating the "killing" of the process shows up indicating me that till there its good. Dont know where i am going wrong...

Final goal of this code would be to act as a remote control controlling the app start and stop using SMS sent from a designated phone. This is for a college project.

Can anyone help me please..

Thanks,
Sangee


B4X:
Sub Service_Start(startingIntent As Intent)
Dim SmsMessages1 As SmsMessages
Dim Matcher1 As Matcher
List1 = SmsMessages1.GetAllSince(DateTime.Add(DateTime.Now , 0, 0,-1))
For i = 0 To List1.Size - 1
Dim Sms As Sms
Sms = List1.Get(i)
   If Sms.Address = "+9199999003" Then
      If Sms.Body = "Appstop" Then
         ToastMessageShow(Sms.Address,False)
          Dim OS As OperatingSystem
          OS.Initialize("OS")
          Dim lstname,lstpid, lstnamepid, lstret As List
          lstname.Initialize
          lstpid.Initialize
          lstnamepid.Initialize
          lstret=OS.RunningAppProcessInfo(lstname,lstpid,lstnamepid)
          Dim i  As Int
          For i = 0 To lstname.Size - 1
            Matcher1 = Regex.Matcher("camera", lstname.Get(i))
            If Matcher1.Find Then
               ToastMessageShow ("Trying to kill : " & lstname.Get(i) ,True)
                  'OS.killProcess(lstpid.Get(i))
               Phone.Shell("kill","anywheresoftware.b4a.samples.camera", Null, Null)
            End If
              'If lstname.Get(i) = "anywheresoftware.b4u.samples.camera" Then
            '   ToastMessageShow (lstname.Get(i),True)
              '    OS.killProcess(lstpid.Get(i))
              'End If
          Next      
      End If
   End If
Next 

StartServiceAt("", DateTime.Now + 1 * DateTime.TicksPerMinute,True) 'schedule the next task to run in 3 mins.

End Sub
 

sangee

Member
Licensed User
Longtime User
Thanks Erel. Worked. Now I understand the right way to control the processes.

Thanks,
Sangee
 
Upvote 0
Top