登录

  • 登录
  • 忘记密码?点击找回

注册

  • 获取手机验证码 60
  • 注册

找回密码

  • 获取手机验证码60
  • 找回
毕业论文网 > 外文翻译 > 计算机类 > 软件工程 > 正文

基于 Android 平台的 移动位置服务的开发与实现外文翻译资料

 2022-11-27 02:11  

Development and Implementation of Mobile

Location Service Based on Android Platform

1 background

The Android platform is a smartphone platform launched by Google in November 2007, a fully integrated mobile 'software stack' that consists of operating systems, middleware, user-friendly interfaces, and application software. Since its introduction, Android has received widespread attention from the industry. At present the Google Android platform SD K has launched a 2. 2 version, we can use SD K provided in the tool for the Android platform for mobile phone application development. Mobile Internet era is characterized by the location of the mobile terminal can be perceived by the server, this is a huge leap. People are always concerned with the information generated around their own, through the mobile terminal equipment to obtain more and more useful information, such as query the weather, access to news, online stocks, etc., this information also contains an important information - location information The This article will examine how to get accurate information about yourself and others on the Android platform and display the information on the map.

2 Android platform application architecture analysis

Android applications are made up of the following four parts: activities, intentions, services, and content providers.

2. 1 Activity (Activity)

An activity is a users screen interface. An application can define one or more activities to handle tasks in different stages of the program. As part of the application lifecycle, each activity holds its own state so that it can be restored later. The status of the activity includes start, start, continue, pause, stop, restart and destroy, and the developer can not control which state the program is in, which is managed by the system; however, when the state is changed by the onXX () method call, personnel.

2. Intent

Intent is a mechanism for describing specific actions, such as 'taking pictures', 'calling home' or 'opening the player'. In Android, almost everything has to go through this stage of intent, so there are many opportunities to replace or reuse many components.

2. Service (Service)

The service is a task that runs in the background, without the need for the user to interact directly with it, which is similar to the Unix daemon. For example, suppose there is a location service locator. Can be targeted through an activity, but we hope that even when the user uses other programs, can still monitor the location information changes. Therefore, the implementation of location information to monitor the code should be in a service. After that, another activity may be bound to the service, telling the service to continue or tentative location monitoring. Android has built a number of services to 2. 4 Content Provider (Content Provider) content provider is packaged in a custom API in a set of data, you can read the data and write data to the API. This is the best way to share global data between applications. For example, Google provides a content provider for the contact program. Any application that needs to use contact information can share all of the information, including name, address, phone number, and so on.

3 based on the Android platform mobile location service implementation

3. 1 Develop permission settings

The basic interface component of the map application is 'MapView'. Before using MapView, well need to go to the Google Maps site to sign the Google Maps services 'Development Key' (API Key) by signing up for 'certificates'.

With the 'development of the key after', you need to register in AndroidManifest. Xml need to use the activities and permissions.

3. 2 self-positioning function to achieve

3. 2. 1 interface function code

Add mylocation. Xml layout file, the entire layout mode using the framework layout, in the framework of the layout, add a map view, a horizontal layout and a vertical layout. A TextView is nested in a horizontal layout to display the text information for the location. Two buttons are nested in the vertical layout, used to implement the map view mode switching function. The map view is first embedded in the frame layout, and the layout_width and layout_height property values ​​are 'fill_parent', indicating that the map view is full of the entire frame layout. Horizontal layout and vertical layout of the background are set to penetrate

So that text messages and buttons are floating on top of the map.

3. 2. 2 activity code

The reference code is as follows:

privatevoid phoneShowOverlay(String name ,GeoPoint gp)

{

GeoPoint TextOverlay mLocationOverlay01 = new

GeoPoint TextOverlay

(gp , name “的位置”, getResources ( ) . getColor

(R. color. blue) ,

getResources() . getColor(R. color. white) ) ;

List lt; Overlay gt; overlays = mMapView01. ge2

tOverlays() ;

overlays. clear () ;

overlays. add(mLocationOverlay01) ;

}

3. 3 mobile positioning function to achieve

3. 3. 1 interface function code

Add a dialogphonelocation. Xml layout file that displays the users phone number that entered the location to be queried. There is only one Text2View and a Edit Text in the layout, which are used to display the prompt and enter the phone number.

3. 3. 2 Activity code

The reference code is as follows:

privateboolean isPhoneNumberValid (String phoneNumber)

{

boolean isValid = false ;

String expression =“^[1 ]{1}[3 ,5 ]{1}[0 - 9 ]{9}|[1 ]{1}[8 ]{1}[6 - 9 ]{1}[0 - 9 ]{8} $”;

CharSequence inputStr = phoneNumber ;

Pattern pattern = Pattern. compile (expression) ;

Matcher matcher = pattern. matcher(inputStr) ;

if (matcher. matches() )

isValid = true ;

return isValid ;

}

3. 3. 3 function button encoding

SFFManager smsManager = SmsManager.

剩余内容已隐藏,支付完成后下载完整资料


基于 Android 平台的 移动位置服务的开发与实现

1 背景

Android 平台是 Google 于 2007 年 11 月推出的一种智能手机平台 ,它是一个由操作系统、中间件、用户友好界面和应用软件组成的 ,全面整合的移动“软件栈”。自推出以来 ,Android 受到了业界的广泛关注。目前 Google Android平台的 SD K已经推出了 2. 2 版本 ,我们可以利用 SD K中所提供的工具 ,为 Android 平台手机进行应用开发。移动互联网时代的特点是移动终端的位置可以被服务器感知 ,这是一个巨大的飞跃。人们总是关注与发生在自己周围的信息 ,通过移动终端设备获得越来越多有用的信息 ,如查询天气、查阅新闻、网上炒股等 ,这些信息中还包含着一个重要的信息 ——位置信息。本文将研究如何在 Android 平台上获得自己和别人的准确的位置信息 ,并将信息在地图上显示出来。

2 Android 平台应用程序架构分析

Android 应用程序主要由以下四个部分组成 :活动、意图、服务和和内容提供者。

2. 1 活动( Activity)

一个活动就是一个用户屏幕界面。应用程序可定义一个或多个活动 ,以处理程序不同阶段中的任务。作为应用程序生命周期的一部分 ,每个活动都要保存自己的状态 ,以便日后还原这些状态。活动的状态包括启动、开始、继续、暂停、停止、重启和销毁 ,开发人员不能控制程序处于哪个状态 ,这是由系统管理的 ;但是 ,通过 onXX() 方法调用改变状态时 ,系统会通知开发人员。

2. 2 意图( Intent)

意图是一种描述具体动作的机制 ,例如“拍照”、“往家里打电话”或“打开播放器”。在 Android 中 ,几乎所有事情都要经历意图这个阶段 ,所以有很多机会可替换或重用很多组件。

2. 3 服务( Service)

服务是在后台运行的任务 ,无需用户直接与其交互 ,它与 Unix 的守护进程类似。例如 ,假设有一个位置服务定位器。可以通通过某个活动来进行定位 ,但是我们希望即使当用户使用其他程序时 ,仍能监测位置信息变化。所以 ,执行位置信息监测的代码应该在某个服务中。之后 ,另一活动可能会绑定到该服务上 ,告诉该服务继续或暂定位置信息监测。Android 内置了许多服务 ,以2. 4 内容提供者( Content Provider)内容提供者是封装在自定义 API 中的一组数据 ,可以读取该数据和向 API 中写入数据。这是在应用程序之间共享全局数据的最佳方式。例如 ,谷歌为联系人程序提供了一个内容提供者。任何需要使用联系人信息的应用程序都可共享其中的所有信息 ,包括姓名、地址、电话号码等。

3 基于 Android 平台移动位置服务的实现

3. 1 开发权限设置

地图应用程序的基本界面组件为“MapView”。在使用“MapView”前 ,我们必须前往 Google 地图网站 ,通过注册“证书”(certificates) ,取得 Google 地图服务的“开发密钥”(API Key) 。

有了“开发密钥之后”,需要在 AndroidManifest. xml 注册需要用到的活动以及权限。

3. 2 自我定位功能实现

3. 2. 1 界面功能编码

添加 mylocation. xml 布局文件 ,整个布局模式采用框架布局 ,在框架布局中 ,添加地图视图、一个水平方向布局和一个垂直方向布局。一个 TextView 嵌套在水平布局中 ,用于显示所在位置的文字信息。两个 Button 嵌套在垂直方向布局中 ,用于实现地图视图模式的切换功能。地图视图最先嵌入到框架布局中 ,并且 layout_width 和layout_height 属性值均为“fill_parent”,表示地图视图充满整个框架布局。水平布局和垂直布局的背景均设置成透

明 ,使得文字信息和按钮均浮在地图的上方。

3. 2. 2 活动编码

参考代码如下 :

privatevoid phoneShowOverlay(String name ,GeoPoint gp)

{

GeoPoint TextOverlay mLocationOverlay01 = new

GeoPoint TextOverlay

(gp , name “的位置”, getResources ( ) . getColor

(R. color. blue) ,

getResources() . getColor(R. color. white) ) ;

List lt; Overlay gt; overlays = mMapView01. ge2

tOverlays() ;

overlays. clear () ;

overlays. add(mLocationOverlay01) ;

}

3. 3 移动定位功能的实现

3. 3. 1 界面功能编码

添加 dialogphonelocation. xml 布局文件 ,用于显示输入所要查询位置的用户电话号码。该布局中只有一个 Text2View 和一个 Edit Text ,分别用于显示提示信息和输入电话号码。

3. 3. 2 活动编码

参考代码如下 :

privateboolean isPhoneNumberValid (String phoneNumber)

{

boolean isValid = false ;

String expression =“^[1 ]{1}[3 ,5 ]{1}[0 - 9 ]{9}|[1 ]{1}[8 ]{1}[6 - 9 ]{1}[0 - 9 ]{8} $”;

CharSequence inputStr = phoneNumber ;

Pattern pattern = Pattern. compile (expression) ;

Matcher matcher = pattern. matcher(inputStr) ;

if (matcher. matches() )

isValid = true ;

return isValid ;

}

3. 3. 3 功能按钮编码

发送请求按钮点击后需要发送短信息 ,故在发送信息按钮的点击事件中 ,首先通过下面的语句 :SmsManager smsManager = SmsManager. getDefault() ;获得对发送短信息的控制对象 smsManager ,然后判断输入在 Edit Text 中的电话号码格式是否正确 ,如果正确 ,通过下面两条语句实现短信息的发送 :

PendingIntent mPI = PendingIntent. getBroadcast

( PhoneLocation. this , 0 , new Intent () , 0) ;

smsManager. sendTextMessage (strDestAddress ,

null , strMessage , mPI , null) ;

3. 3. 4 BroadcastReceiver 服务编码

本程序通过编写继承自 BroadcastReceiver 类的 SMS_Receiver 类来实现对短信息的监听。在 onReceive 函数中 ,首先判断监听到的 Intent 是不是 android. provider. Teleph2ony. SMS_RECEIVED ,如果是 ,将 Intent 封装成 Bundle ,创建 SMSMessage 对象数组 ,通过 createFromPdu () 函数获取跟短信相关的信息 ,再分别通过 getDisplayOriginationAd2dress() 函数和 getdisplayMessageBody() 函数获取信息的来源号码和信息的内容。如果信息的内容中包含“LOCA2TION_SMS”内容 ,则通过下面的两条语句启动位置服务 :

LocationManager mLocationManager = ( Location2Manager)

context. getSystemService ( Context. LOCA TION _SERVICE) ;

Location mLocation = getLocationProvider (mLocation2Manager) ;

然后将所在位置的经纬度信息以短信的形式回复给源手机用户 ;如果信息内容包含“LOCAL”内容 ,将其中的经纬度信息取出来 ,调用 refreshMapView () 函数在地图中标注出来。

4 结语

通过对 Android 地图服务的研究 ,实现了 Android 平台上的自我定位以及通过短信获取对方手机的位置信息在地图上显示出来的功能。该方法也对从事移动定位开发的人员具有一定的参考价值 ,而通过桌面平台显示所有监控对象的位置信息是我的继续研究的方向。

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[26023],资料为PDF文档或Word文档,PDF文档可免费转换为Word

您需要先支付 30元 才能查看全部内容!立即支付

企业微信

Copyright © 2010-2022 毕业论文网 站点地图