Android Question Stop audio record when whatsapp call

Devv

Active Member
Licensed User
Longtime User
As you know, only one app can use the mic to record.
when i do a recording using b4a and then another app asks to record. the other app will not be able to record because i was already using the mic (like having a whatsapp/viber call in the middle of a recording).
is their is s way to detect if another app is requesting the mic so i could release it ?
 

Devv

Active Member
Licensed User
Longtime User
MY project is something like cortana or siri , it keep listening to the audio through the mic all the time.
the problem is that if my app is using the mic all the time through service.
other apps like (whatsapp, viber ) will not be able to use the mic.
so in m project their is only a service the activity will only start the service and the app must still run when the service is paused
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is indeed problematic.

You can use this code to find the current running app:
B4X:
Sub CurrentRunningActivity As String
   Try
     Dim jo As JavaObject
     jo.InitializeContext
     jo = jo.RunMethod("getSystemService", Array("activity"))
     Return jo.RunMethodJO("getRunningTasks", Array(1)).RunMethodJO("get", Array(0)).GetFieldJO("topActivity") _
       .RunMethod("getPackageName", Null)
   Catch
     Log(LastException)
     Return ""
   End Try
End Sub

AddPermission(android.permission.GET_TASKS)

It is based on this code: http://stackoverflow.com/questions/3278895/how-to-check-current-running-applications-in-android

However it doesn't return the correct values on Android 5+.
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
This is indeed problematic.

You can use this code to find the current running app:
B4X:
Sub CurrentRunningActivity As String
   Try
     Dim jo As JavaObject
     jo.InitializeContext
     jo = jo.RunMethod("getSystemService", Array("activity"))
     Return jo.RunMethodJO("getRunningTasks", Array(1)).RunMethodJO("get", Array(0)).GetFieldJO("topActivity") _
       .RunMethod("getPackageName", Null)
   Catch
     Log(LastException)
     Return ""
   End Try
End Sub

AddPermission(android.permission.GET_TASKS)

It is based on this code: http://stackoverflow.com/questions/3278895/how-to-check-current-running-applications-in-android

However it doesn't return the correct values on Android 5+.


The problem i don't know the mic apps that the user could use.
Is their is a way to make b4a take the lowest priority for the mic ? so if any other app request the mic b4a will let it go..
 
Upvote 0
Top