当前位置:操作系统 > 安卓/Android >>

Android日志创建应用与添加位置服务

1、申明头文件

import android.util.Log;

import android.location.Location;
import android.location.LocationManager;  

2、创建变量及其应用

 public static final String DEBUG_TAG = "MySecondAppLogging";

    public void getLocation()
    {
    try
    {
    LocationManager locMgr=(LocationManager)getSystemService(LOCATION_SERVICE);
    Location recentLoc=locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    Log.i(DEBUG_TAG, "loc:" + recentLoc.toString());
   
    }
    catch(Exception e)
    {
    Log.e(DEBUG_TAG, "Location failed", e);
    }
    }


补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,