VB开发安卓程序_例程20传感器应用


运行截图

 


布局文件

感谢源码作者晕晕

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

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值