运行截图
布局文件
感谢源码作者晕晕
Main窗体代码如下
#Region Project Attributes
#ApplicationLabel: 传感器
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: True
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Phone(32) As PhoneSensors
Dim KaiGuan As Boolean
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Label1 As Label,Label2 As Label
Dim Butt As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim Width As Long ,Height As Long
Width=Activity.Width
Height=Activity.Height/6
'使用可视化界面设计工具设计了界面后,请不要忘记用下面的方法加载你设计的界面(参数是界面文件的名字) o70078汉化 QQ172259743:
Activity.LoadLayout("Form")
Label1.Top=Height*4:Label1.Left=0
Label1.Width=Width:Label1.Height=Height
Label2.Top=0:Label2.Left=0
Label2.Width=Width:Label2.Height=Height
Butt.Top=Height*5:Butt.Left=0
Butt.Width=Width:Butt.Height=Height
Phone(0).Initialize(Phone(0).TYPE_PROXIMITY)'距离传感器
Phone(1).Initialize2(Phone(1).TYPE_ORIENTATION,0)'方向传感器
Label2.Text="欢迎使用传感器!"
SensorTrue
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Butt_Click'开关
If KaiGuan Then
SensorFalse
Else
SensorTrue
End If
End Sub
Sub SensorTrue()'传感器全开
Phone(0).StartListening("Phone0")
Phone(1).StartListening("Phone1")
KaiGuan=True
End Sub
Sub SensorFalse()'传感器全关
Phone(0).StopListening()
Phone(1).StopListening()
KaiGuan=False
End Sub
Sub Phone0_SensorChanged(Values() As Float)
If Values(0)=0.0 Then
Label1.Text ="距离传感器:你接近了手机听筒"
Else
Label1.Text ="距离传感器:你远离了手机听筒"
End If
End Sub
Sub Phone1_SensorChanged(Values() As Float)
Label2.Text=Values(0)
End Sub