在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
第一次编译时,设定android SDK:
F:\RAD Studio XE6\PlatformSDKs\adt-bundle-windows-x86-20131030\sdk
F:\RAD Studio XE6\PlatformSDKs\android-ndk-r9c
C:\Program Files\Java\jdk1.7.0_40
SDK更新代理
XE6 不支持JStringToString、StringTojString、StrToJURI:use Androidapi.Helpers
//Splash Image
Delphi XE5,XE6,XE7编译的程序在Android下启动会有一段时间黑屏,以前需要用Java扩展Activity增加Splash显示,
现在Delphi XE7增加了Splash Image显示功能了。 步骤: 1.鼠标右键点击工程,选择Options, 2.进入Application分页 3.勾选Include Splash Image 4.选择您的Splash Image文件 5.设置Splash Tile mode和Splash Gravity Splash Tile Mode disabled -按图片尺寸大小显示,显示位置有Splash Gravity设置 clamp - 图形边框适应屏幕大小 repeat - 屏幕水平,竖立方向重复填充满Splash Image mirror - 跟repeat差不多,图片是镜像的。 Gravity 设置比屏幕小的图片在屏幕中的位置,只有当Splash Title Mode为Disable时有效, 参数大家一看便知道什么意思了,我就不提了。 带文件发布
菜单 project ->deployment->然后点击增加按钮,选择中sqlite数据 test.s3db, remote path 填写 assets\internal\
应用显示中文名(工程不能为中文否则会编译出错)
菜单 project ->Option->Version Info->label
FMX.Consts汉化(需要更改单元) { Dialog Strings } // SMsgDlgWarning = 'Warning'; // SMsgDlgError = 'Error'; // SMsgDlgInformation = 'Information'; // SMsgDlgConfirm = 'Confirm'; // SMsgDlgYes = 'Yes'; // SMsgDlgNo = 'No'; // SMsgDlgOK = 'OK'; // SMsgDlgCancel = 'Cancel'; // SMsgDlgHelp = 'Help'; // SMsgDlgHelpNone = 'No help available'; // SMsgDlgHelpHelp = 'Help'; // SMsgDlgAbort = 'Abort'; // SMsgDlgRetry = 'Retry'; // SMsgDlgIgnore = 'Ignore'; // SMsgDlgAll = 'All'; // SMsgDlgNoToAll = 'No to All'; // SMsgDlgYesToAll = 'Yes to &All'; // SMsgDlgClose = 'Close'; // // SWindowsVistaRequired = '%s requires Windows Vista or later'; // // SUsername = '&Username'; // SPassword = '&Password'; // SDomain = '&Domain'; // SLogin = 'Login'; SMsgDlgWarning = '警告'; SMsgDlgError = '错误'; SMsgDlgInformation = '信息'; SMsgDlgConfirm = '确认'; SMsgDlgYes = '是的'; SMsgDlgNo = '不是'; SMsgDlgOK = '确定'; SMsgDlgCancel = '取消'; SMsgDlgHelp = '帮助'; SMsgDlgHelpNone = '没有提供帮助'; SMsgDlgHelpHelp = '帮助'; SMsgDlgAbort = '放弃'; SMsgDlgRetry = '重试'; SMsgDlgIgnore = '忽略'; SMsgDlgAll = '全部'; SMsgDlgNoToAll = '全选“不是”'; SMsgDlgYesToAll = '全选“是”'; SMsgDlgClose = '关闭'; SWindowsVistaRequired = '%s 需要 Windows Vista 或以上操作系统'; SUsername = '&用户名'; SPassword = '&密码'; SDomain = '&域名'; SLogin = '登录'; 临时文件路径(支持安卓、IOS) function GeFileName(const AFileName: string): string; begin {$IFDEF ANDROID} Result := TPath.GetTempPath + '/' + AFileName; {$ELSE} {$IFDEF IOS} Result := TPath.GetHomePath + '/Documents/' + AFileName; {$ELSE} Result := AFileName; {$ENDIF} {$ENDIF} end; IOUtils文件说明 路径类 TPath.GetTempPath; {获取临时文件夹路径} TPath.GetTempFileName; {获取一个临时文件名} TPath.GetPathRoot(); {提取盘符, 如: c:\} TPath.GetDirectoryName(); {提取路径} TPath.GetFileName(); {提取文件名} TPath.GetExtension(); {提取扩展名} TPath.GetFileNameWithoutExtension(); {提取无扩展名的文件名} TPath.ChangeExtension(); {更换扩展名} TPath.DriveExists(); {检查路径中的驱动器是否存在} TPath.GetFullPath(); {根据相对路径给出全路径} TPath.HasExtension(); {判断是否有扩展名} TPath.IsPathRooted(); {判断是否是绝对路径} TPath.Combine(); {结合路径} TPath.GetRandomFileName; {产生一个随机文件名} TPath.GetGUIDFileName(); {用于产生一个唯一的文件名, 布尔参数 决定名称中是否包含 -} TPath.IsValidPathChar(); {判断给定的字符是否能用于路径名} TPath.IsValidFileNameChar(); {判断给定的字符是否能用于文件名} TPath.AltDirectorySeparatorChar; {Windows 下是 "\"} TPath.AltDirectorySeparatorChar; {Windows 下是 "/"} TPath.ExtensionSeparatorChar; {Windows 下是 "."} TPath.PathSeparator; {Windows 下是 ";"} TPath.VolumeSeparatorChar; {Windows 下是 ":"} //目录类 TDirectory.CreateDirectory(); {建立新目录} TDirectory.Exists(); {判断文件夹是否存在} TDirectory.IsEmpty(); {判断文件夹是否为空} TDirectory.Copy(); {复制文件夹} TDirectory.Move(); {移动文件夹} TDirectory.Delete(); {删除文件夹, 第二个参数为 True 可删除 非空文件夹} TDirectory.GetDirectoryRoot(); {获取目录的根盘符, 如: C:\} TDirectory.GetCurrentDirectory; {获取当前目录} TDirectory.SetCurrentDirectory(); {设置当前目录} TDirectory.GetLogicalDrives; {获取驱动器列表; 下有举例} TDirectory.GetAttributes(); {获取文件夹属性, 譬如只读、存档等; 下有举例} TDirectory.SetAttributes(); {设置文件夹属性; 下有举例} //文件类 TFile.Exists();//判断指定的文件是否存在 TFile.Copy();//复制文件 TFile.Move();//移动文件 TFile.Delete();//删除文件 TFile.Replace();//替换文件 MotionSensor1: TMotionSensor; 加速传感器 MotionSensor1.Sensor(AngleAccelX、AngleAccelY、AngleAccelZ)加速度 procedure TAccelerometerForm.Timer1Timer(Sender: TObject); var LProp: TCustomMotionSensor.TProperty; begin for LProp in MotionSensor1.Sensor.AvailableProperties do begin { get the data from the sensor } case LProp of TCustomMotionSensor.TProperty.AccelerationX: begin lbAccelerationX.Visible := True; lbAccelerationX.Text := Format('Acceleration X: %6.2f', [MotionSensor1.Sensor.AccelerationX]); end; end; end; OrientationSensor1: TOrientationSensor;方位传感器 OrientationSensor1.Sensor(TiltX,TiltY,TiltZ) procedure TOrientationSensorForm.Timer1Timer(Sender: TObject); begin { get the data from the sensor } lbTiltX.Text := Format('Tilt X: %f', [OrientationSensor1.Sensor.TiltX]); lbTiltY.Text := Format('Tilt Y: %f', [OrientationSensor1.Sensor.TiltY]); lbTiltZ.Text := Format('Tilt Z: %f', [OrientationSensor1.Sensor.TiltZ]); lbHeadingX.Text := Format('Heading X: %f', [OrientationSensor1.Sensor.HeadingX]); lbHeadingY.Text := Format('Heading Y: %f', [OrientationSensor1.Sensor.HeadingY]); lbHeadingZ.Text := Format('Heading Z: %f', [OrientationSensor1.Sensor.HeadingZ]); end; TSensorManager传感器管理器(包含上述两种传感器,Samples\Object Pascal\Mobile Samples\Device Sensors and Services\SensorInfo) TSensorCategory = (Location, Environmental, Motion, Orientation, Mechanical, Electrical, Biometric, Light, Scanner); 位置传感器,环境传感器,运动传感器,方向传感器,机械传感器,电传感器,生物传感器,光繁传感器,扫描仪传感器 TActionList组件可以添加标准事件(New Standard Action) TakePhotoFromCameraAction1: TTakePhotoFromCameraAction; // 通过手机摄像头获取图片 TakePhotoFromLibraryAction1: TTakePhotoFromLibraryAction; //获取手机已存在图片 ShowShareSheetAction1: TShowShareSheetAction;//用其它程序分享图片(Bitmap.Assign();) 获取麦克风设置 FMX.Media FMicrophone: TAudioCaptureDevice; FMicrophone := TCaptureDeviceManager.Current.DefaultAudioCaptureDevice; FMicrophone.FileName 设置路径 FMicrophone.State = TCaptureDeviceState.Capturing 设备状态 FMicrophone.StartCapture; //开始录音 FMicrophone.StopCapture; // 结束录音 MediaPlayer: TMediaPlayer; 媒体播放器 MediaPlayer.FileName 设置路径 MediaPlayer.Play; // 开始播放 MediaPlayer.Stop; // 结束播放 获取手机摄像头 Camera: TCameraComponent; Camera.Active := True; //打开 Camera.Active := False; //停止 Camera.SampleBufferToBitmap(imgCameraView.Bitmap, True); //保存图片 TThread.Synchronize(TThread.CurrentThread, GetImage); //线程保存图片 Camera.Quality 图像质量 Camera.HasFlash 是否有闪光灯 Camera.TorchMode := TTorchMode.ModeOn; //打开闪光灯 Camera.FlashMode := FMX.Media.TFlashMode.fmFlashOff; Camera.TorchMode := TTorchMode.ModeOff;//关闭闪光灯 Camera.FlashMode := FMX.Media.TFlashMode.fmFlashOn; Camera.Kind := FMX.Media.TCameraKind.ckFrontCamera;//前置摄像头 Camera.Kind := FMX.Media.TCameraKind.ckBackCamera;//后置摄像头 获取设备信息 lbDeviceType.Text := Format('Device Type: %s', [JStringToString(TJBuild.JavaClass.MODEL)]); lbOSName.Text := Format('OS Name: %s', [GetCodename(JStringToString(TJBuild_VERSION.JavaClass.RELEASE))]); lbOSVersion.Text := Format('OS Version: %s', [JStringToString(TJBuild_VERSION.JavaClass.RELEASE)]); GestureManager1: TGestureManager; 手势识别组件(igiRotate|旋转、igiZoom|缩放、igiLongTap|长按) 组件关联GestureManager1(Touch.GestureManager,Getures.Standard可以直接添加事件) procedure TPinchZoom.FormGesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean); var LObj: IControl; LImage: TImage; LImageCenter: TPointF; begin if EventInfo.GestureID = igiZoom then begin LObj := Self.ObjectAtPoint(ClientToScreen(EventInfo.Location)); if LObj is TImage then begin if (not(TInteractiveGestureFlag.gfBegin in EventInfo.Flags)) and (not(TInteractiveGestureFlag.gfEnd in EventInfo.Flags)) then begin { zoom the image } LImage := TImage(LObj.GetObject); LImageCenter := LImage.Position.Point + PointF(LImage.Width / 2, LImage.Height / 2); LImage.Width := LImage.Width + (EventInfo.Distance - FLastDistance); LImage.Height := LImage.Height + (EventInfo.Distance - FLastDistance); LImage.Position.X := LImageCenter.X - LImage.Width / 2; LImage.Position.Y := LImageCenter.Y - LImage.Height / 2; end; FLastDistance := EventInfo.Distance; end; end; end; 获取地理信息 LocationSensor1: TLocationSensor;//定位 LocationSensor1.Active := swLocationSensorActive.IsChecked; //开始 NewLocation.Latitude //经度 NewLocation.Longitude //纬度 FGeocoder: TGeocoder;//地理编码 procedure TLocationForm.LocationSensor1LocationChanged(Sender: TObject; const OldLocation, NewLocation: TLocationCoord2D); const LGoogleMapsURL: String = 'https://maps.google.com/maps?q=%s,%s'; var ENUSLat, ENUSLong: String; // holders for URL strings begin ENUSLat := NewLocation.Latitude.ToString(ffGeneral, 5, 2, TFormatSettings.Create('en-US')); ENUSLong := NewLocation.Longitude.ToString(ffGeneral, 5, 2, TFormatSettings.Create('en-US')); { convert the location to latitude and longitude } lbLatitude.Text := 'Latitude: ' + ENUSLat; lbLongitude.Text := 'Longitude: ' + ENUSLong; { and track the location via Google Maps } WebBrowser1.Navigate(Format(LGoogleMapsURL, [ENUSLat, ENUSLong])); // Setup an instance of TGeocoder try if not Assigned(FGeocoder) then begin if Assigned(TGeocoder.Current) then FGeocoder := TGeocoder.Current.Create; if Assigned(FGeocoder) then FGeocoder.OnGeocodeReverse := OnGeocodeReverseEvent; end; except ListBoxGroupHeader1.Text := 'Geocoder service error.'; end; // Translate location to address if Assigned(FGeocoder) and not FGeocoder.Geocoding then FGeocoder.GeocodeReverse(NewLocation); end; //地理信息 procedure TLocationForm.OnGeocodeReverseEvent(const Address: TCivicAddress); begin ListBoxItemAdminArea.ItemData.Detail := Address.AdminArea; //省份 ListBoxItemCountryCode.ItemData.Detail := Address.CountryCode; //国家编码 CN ListBoxItemCountryName.ItemData.Detail := Address.CountryName; //国家 ListBoxItemFeatureName.ItemData.Detail := Address.FeatureName; //镇 ListBoxItemLocality.ItemData.Detail := Address.Locality; //市 ListBoxItemPostalCode.ItemData.Detail := Address.PostalCode; //邮政编码 ListBoxItemSubAdminArea.ItemData.Detail := Address.SubAdminArea;//子级省 ListBoxItemSubLocality.ItemData.Detail := Address.SubLocality;//子级市 ListBoxItemSubThoroughfare.ItemData.Detail := Address.SubThoroughfare;//街道 ListBoxItemThoroughfare.ItemData.Detail := Address.Thoroughfare;//子街道 end; 获取本机信息 FMX.Android.DeviceInfo.GetInformation; Memo1.Lines.Add('ID:'+FMX.Android.DeviceInfo.ID); Memo1.Lines.Add('IMEI:'+FMX.Android.DeviceInfo.IMEI); Memo1.Lines.Add('User:'+FMX.Android.DeviceInfo.User); Memo1.Lines.Add('Host:'+FMX.Android.DeviceInfo.Host); Memo1.Lines.Add('Tags:'+FMX.Android.DeviceInfo.Tags); Memo1.Lines.Add('Time:'+FMX.Android.DeviceInfo.Time); Memo1.Lines.Add('AType:'+FMX.Android.DeviceInfo.AType); Memo1.Lines.Add('Board:'+FMX.Android.DeviceInfo.Board); Memo1.Lines.Add('Radio:'+FMX.Android.DeviceInfo.Radio); Memo1.Lines.Add('Brand:'+FMX.Android.DeviceInfo.Brand); Memo1.Lines.Add('Model:'+FMX.Android.DeviceInfo.Model); Memo1.Lines.Add('Serial:'+FMX.Android.DeviceInfo.Serial); Memo1.Lines.Add('Device:'+FMX.Android.DeviceInfo.Device); Memo1.Lines.Add('CpuABI:'+FMX.Android.DeviceInfo.CpuABI); Memo1.Lines.Add('CpuABI2:'+FMX.Android.DeviceInfo.CpuABI2); Memo1.Lines.Add('Display:'+FMX.Android.DeviceInfo.Display); Memo1.Lines.Add('Product:'+FMX.Android.DeviceInfo.Product); Memo1.Lines.Add('Hardware:'+FMX.Android.DeviceInfo.Hardware); Memo1.Lines.Add('Bootloader:'+FMX.Android.DeviceInfo.Bootloader); Memo1.Lines.Add('FingerPrint:'+FMX.Android.DeviceInfo.FingerPrint); Memo1.Lines.Add('Manufacturer:'+FMX.Android.DeviceInfo.Manufacturer); MapView1: TMapView;//地图足迹 WebBrowser1: TWebBrowser; //浏览器 WebBrowser1.Navigate('www.baidu.com'); //打开网页 WebBrowser1.URL := '';//打开网页 WebBrowser1.GoForward; //前进 WebBrowser1.GoBack;//后退 ShowMessage、MessageDlg、InputQuery //对话框很方便 消息提醒(从手机屏幕顶部向下滑动,出现的提示消息) NotificationC: TNotificationCenter; procedure TNotificationsForm.btnSendNotificationImmediatelyClick( Sender: TObject); var Notification: TNotification; begin { verify if the service is actually supported } if NotificationC.Supported then begin Notification := NotificationC.CreateNotification; try Notification.Name := 'MyNotification'; Notification.AlertBody := 'Delphi for Mobile is here!'; Notification.FireDate := Now; //可修改发送消息时间 { Send notification in Notification Center } NotificationC.ScheduleNotification(Notification); { also this method is equivalent } // NotificationService.PresentNotification(Notification); finally Notification.DisposeOf; end; end end; if NotificationC.Supported then NotificationC.CancelNotification('MyNotification'); //取消消息 NotificationC.CancelAll; //取消所有消息 程序事件服务 var FMXApplicationEventService: IFMXApplicationEventService; begin if TPlatformServices.Current.SupportsPlatformService (IFMXApplicationEventService, IInterface(FMXApplicationEventService)) then FMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent) else flag := false; end; function TForm1.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject) : boolean; begin if flag = false then exit; case AAppEvent of TApplicationEvent.aeEnteredBackground: begin //当程序后台运行了 end; end; Result := true; end; 电话信息(Call拨号) PhoneDialerService: IFMXPhoneDialerService; 获取电话服务信息 procedure TPhoneDialerForm.btnGetCarrierInfoClick(Sender: TObject); var PhoneDialerService: IFMXPhoneDialerService; begin { test whether the PhoneDialer services are supported } if TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService, IInterface(PhoneDialerService)) then begin { if yes, then update the labels with the retrieved information } CarrierNameItem.ItemData.Detail := PhoneDialerService.GetCarrier.GetCarrierName; CountryCodeItem.ItemData.Detail := PhoneDialerService.GetCarrier.GetIsoCountryCode; NetworkCodeItem.ItemData.Detail := PhoneDialerService.GetCarrier.GetMobileCountryCode; MobileNetworkItem.ItemData.Detail := PhoneDialerService.GetCarrier.GetMobileNetwork; end else ShowMessage('PhoneDialer service not supported'); end; 拨号 procedure TPhoneDialerForm.btnMakeCallClick(Sender: TObject); var PhoneDialerService: IFMXPhoneDialerService; begin { test whether the PhoneDialer services are supported } if TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService, IInterface(PhoneDialerService)) then begin { if the Telephone Number is entered in the edit box then make the call, else display an error message } if edtTelephoneNumber.Text <> '' then PhoneDialerService.Call(edtTelephoneNumber.Text) else begin ShowMessage('Please type in a telephone number.'); edtTelephoneNumber.SetFocus; end; end else ShowMessage('PhoneDialer service not supported'); end; Intent :TJIntent uses Androidapi.JNI.GraphicsContentViewText, FMX.Helpers.Android, Androidapi.JNI.Net, Androidapi.Helpers; procedureCall_URI(constAAction : JString;constAURI: string); var uri: Jnet_Uri; Intent: JIntent; begin uri := StrToJURI(AURI); Intent := TJIntent.JavaClass.init(AAction, uri); {Intent.putExtra() //短信 Call_URI(TJIntent.JavaClass.ACTION_SENDTO, 'smsto:137114553XX'); Intent.putExtra(StringToJString('sms_body'), StringToJString('测试短信')); 如果是要发短信等复杂的应用,需要传递各种其他的参数.要用到Intent.putExtra()传递多个参数. 这里只封装最简单的,具体Intent.putExtra()的用法,可以查询Java的资料.大把的 } SharedActivityContext.startActivity(Intent); end; //使用例子: //打电话 Call_URI(TJIntent.JavaClass.ACTION_CALL, 'tel:137114553XX'); //打开地图显示某个坐标点 Call_URI(TJIntent.JavaClass.ACTION_VIEW, 'geo:38.899533,-77.036476'); //打开网页 Call_URI(TJIntent.JavaClass.ACTION_VIEW, 'www.baidu.com'); //发送电子邮件 Call_URI(TJIntent.JavaClass.ACTION_SENDTO, 'mailto:[email protected]'); //播放音乐 Call_URI(TJIntent.JavaClass.ACTION_VIEW, 'file:///sdcard/download/最炫民族风.mp3'); 回到主画面procedure TForm1.Button3Click(Sender: TObject);var Intent: JIntent;begin Intent:= TJIntent.Create; Intent.setAction(TJIntent.JavaClass.ACTION_MAIN); Intent.addCategory(TJIntent.JavaClass.CATEGORY_HOME); Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK); MainActivity.startActivity(Intent);end; 条码扫描(需要安装zxing) procedure TINVMCForm.btnSCANClick(Sender: TObject);var uri: Jnet_Uri; //引用Androidapi.JNI.Net Intent: JIntent; //引用Androidapi.JNI.GraphicsContentViewText jstr:JString;begin inherited; uri := StrToJURI('com.google.zxing.client.android.SCAN'); //引用FMX.Helpers.Android //Intent := TJIntent.JavaClass.init(jstring(('com.google.zxing.client.android.SCAN'); Intent := TJIntent.JavaClass.init(StringToJString('com.google.zxing.client.android.SCAN')); SharedActivityContext.startActivity(Intent);end; function GetZXingIntent: JIntent; const 全部评论
专题导读
热门推荐
热门话题
阅读排行榜
|
请发表评论