Hi All
I need to access the android.media.AudioManager from a module, not an activity. I get the following error when compiling:
B4A version: 6.80
Parsing code. (0.09s)
Compiling code. (0.32s)
Compiling layouts code. (0.04s)
Organizing libraries. (0.00s)
Generating R file. (0.07s)
Compiling generated Java code. Error
B4A line: 74
End Sub
javac 1.8.0_40-ea
src\com\islesystems\pushtotalk\mod_audio_manager.java:164: error: cannot find symbol
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
^
symbol: variable AUDIO_SERVICE
location: class mod_audio_manager
All Help apperciated.
Regards
John.
I need to access the android.media.AudioManager from a module, not an activity. I get the following error when compiling:
B4A version: 6.80
Parsing code. (0.09s)
Compiling code. (0.32s)
Compiling layouts code. (0.04s)
Organizing libraries. (0.00s)
Generating R file. (0.07s)
Compiling generated Java code. Error
B4A line: 74
End Sub
javac 1.8.0_40-ea
src\com\islesystems\pushtotalk\mod_audio_manager.java:164: error: cannot find symbol
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
^
symbol: variable AUDIO_SERVICE
location: class mod_audio_manager
B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private nativeMe As JavaObject
End Sub
Public Sub Init
'lower cased module name
nativeMe.InitializeStatic(Application.PackageName & ".mod_audio_manager")
End Sub
Sub setSpeakerPhone(state As Boolean)
Dim rr As Reflector
rr.Target = rr.GetContext
rr.Target = rr.RunMethod2("getSystemService", "audio", "java.lang.String")
rr.RunMethod2("setSpeakerphoneOn", state, "java.lang.boolean")
End Sub
Sub set_audio_mode(pMode As Int)
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
r.RunMethod2("setMode", pMode, "java.lang.int")
End Sub
Sub get_audio_mode() As Int
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
Return r.RunMethod("getMode")
End Sub
Sub turnSpeakerOn(pState As Boolean)
Dim p As Phone
'Dim java As JavaObject
'java.InitializeContext
If p.SdkVersion < 21 Then
If pState Then
nativeMe.RunMethod("setSpeakerOn_20",Null)
Else
nativeMe.RunMethod("setSpeakerOff_20",Null)
End If
Else
If pState Then
nativeMe.RunMethod("setSpeakerOn_21",Null)
Else
nativeMe.RunMethod("setSpeakerOff_21",Null)
End If
'nativeMe.RunMethod("setSpeakerOn_21",Array(pState))
End If
End Sub
Sub setMicrophoneMute(pState As Boolean)
Dim p As Phone
If p.SdkVersion < 21 Then
If pState Then
nativeMe.RunMethod("setMicroPhoneMuteOn_20",Null)
Else
nativeMe.RunMethod("setMicroPhoneMuteOff_20",null)
End If
Else
nativeMe.RunMethod("setMicroPhoneMute_21",Array(pState))
End If
' // hack to set voice call volume to zero
If pState Then
Main.APPSET.currentChannel.voice_call_vol = p.GetVolume(p.VOLUME_VOICE_CALL)
p.SetVolume(p.VOLUME_VOICE_CALL,0,False)
Else
p.SetVolume(p.VOLUME_VOICE_CALL,Main.APPSET.currentChannel.voice_call_vol,False)
End If
' // http://www.programcreek.com/java-api-examples/index.php?class=android.media.AudioManager&method=setMicrophoneMute
Dim Sleep As Lock
Sleep.Initialize(True)
Sleep.WaitFor(200)
Sleep.Unlock
End Sub
#If JAVA
import android.media.AudioManager;
public void setSpeakerOn_20() {
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setSpeakerphoneOn(true);
}
#End if
#If JAVA
import android.media.AudioManager;
public void setSpeakerOff_20() {
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setSpeakerphoneOn(false);
}
#End if
#If JAVA
import android.media.AudioManager;
public void setSpeakerOn_21() {
AudioManager audioManager= (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(true);
}
#End if
#If JAVA
import android.media.AudioManager;
public void setSpeakerOff_21() {
AudioManager audioManager= (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(false);
}
#End if
#If JAVA
import android.media.AudioManager;
public void setMicroPhoneMute_21(boolean Value) {
AudioManager audioManager= (AudioManager) getSystemService(AUDIO_SERVICE);
if (Value)
{
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setMicrophoneMute(Value);
}
else
{
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setMicrophoneMute(Value);
}
}
#End if
#If JAVA
import android.media.AudioManager;
public void setMicroPhoneMuteOn_20() {
AudioManager audioManager= (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setMicrophoneMute(true);
}
#End if
#If JAVA
import android.media.AudioManager;
public void setMicroPhoneMuteOff_20() {
AudioManager audioManager= (AudioManager) getSystemService(AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setMicrophoneMute(false);
}
#End if
#End Region
All Help apperciated.
Regards
John.