的Andr​​oid的LocationManager不能调用方法 [英] Android locationmanager not calling methods

查看:179
本文介绍了的Andr​​oid的LocationManager不能调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与在Android中的LocationManager麻烦。我有以下类:

 包com.flyer;进口android.app.Activity;
进口android.content.Context;
进口android.content.Intent;
进口android.location.Location;
进口android.location.LocationListener;
进口android.location.LocationManager;
进口android.os.Bundle;
进口android.widget.Toast;
进口org.apache.http.HttpEntity;
进口org.apache.http.Htt presponse;
进口org.apache.http.NameValuePair;
进口org.apache.http.client.HttpClient;
进口org.apache.http.client.entity.UrlEn codedFormEntity;
进口org.apache.http.client.methods.HttpPost;
进口org.apache.http.impl.client.DefaultHttpClient;
进口org.apache.http.message.BasicNameValuePair;
进口org.apache.http.util.EntityUtils;
进口org.json.JSONArray;
进口org.json.JSONObject;进口java.io.IOException异常;
进口的java.util.ArrayList;
进口的java.util.List;公共类的ContentProvider实现LocationListener的{
    私人活动connectedActivity;    公众的ContentProvider(活动connectedActivity){
        this.connectedActivity = connectedActivity;
        的LocationManager的LocationManager =(的LocationManager)connectedActivity.getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,100,0,这一点);
    }    公共无效onLocationChanged(位置LOC)
    {
        MyActivity.rowsData.add(新RowData(0,测试,瓦尔:+的Math.random(),0));
    }    公共无效onProviderDisabled(字符串提供商)
    {
        在意向=新意图(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        connectedActivity.startActivity(在);
    }    公共无效onProviderEnabled(字符串提供商)
    {
        Toast.makeText(connectedActivity.getApplicationContext(),
                GPS功能
                Toast.LENGTH_SHORT).show();    }    公共无效onStatusChanged(字符串提供商,INT地位,捆绑演员)
    {
        MyActivity.rowsData.add(新RowData(0,测试,瓦尔:+的Math.random(),0));
    }
}

我把我的mainactivity构造的ContentProvider(本)。然而,当我telnet到我的模拟器,做一个地理修复,什么都不会发生。

我试着用断点设置内容,也不会达到。

此外,我正在开发的Andr​​oid 2.1系统。

任何帮助将是AP preciated。

得到一个警告:

  10-30 21:10:3​​8.787:WARN / GpsLocationProvider(52):无法打开GPS配置文件/etc/gps.conf


解决方案

你可以发布您的清单XML?你有没有添加的必要权限?

 <机器人:名字=android.permission.ACCESS_COARSE_LOCATION/>
<机器人:名字=android.permission.ACCESS_FINE_LOCATION/>

是你,让你的一丝logcat中的任何异常?我建议在真实设备上尝试这种排除配置的问题与你的模拟器。

仅供参考,这里是我如何使用打开调试跟踪我的应用程序亚行logcat

 亚行外壳停止
亚行外壳setprop log.tag.MYTAG DEBUG
亚行shell启动
亚行logcat MyTag的:D *:W> C:\\ TEMP \\ trace.txt

要避免与DEBUG级别的跟踪不必浪费时间,我建议你坚持在Log.INFO级记录。在这种情况下,你只需要一个命令。

I'm having trouble with the locationmanager in Android. I have the following class:

package com.flyer;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ContentProvider implements LocationListener {
    private Activity connectedActivity;

    public ContentProvider(Activity connectedActivity) {
        this.connectedActivity = connectedActivity;
        LocationManager locationManager = (LocationManager)connectedActivity.getSystemService(Context.LOCATION_SERVICE);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 0, this);
    }

    public void onLocationChanged(Location loc)
    {
        MyActivity.rowsData.add(new RowData(0, "Test", "Val: " + Math.random(), 0));
    }

    public void onProviderDisabled(String provider)
    {
        Intent in = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        connectedActivity.startActivity(in);
    }

    public void onProviderEnabled(String provider)
    {
        Toast.makeText(connectedActivity.getApplicationContext(),
                "Gps Enabled",
                Toast.LENGTH_SHORT).show();

    }

    public void onStatusChanged(String provider, int status, Bundle extras)
    {
        MyActivity.rowsData.add(new RowData(0, "Test", "Val: "+Math.random(), 0));
    }


}

I call the constructor ContentProvider(this) in my mainactivity. However when I telnet to my emulator and do a geo fix, nothing happens.

I tried setting the content with a breakpoint, it won't reach.

Also I'm developing for Android 2.1.

Any help would be appreciated.

Getting a warning:

10-30 21:10:38.787: WARN/GpsLocationProvider(52): Could not open GPS configuration file /etc/gps.conf

解决方案

Can you publish your manifest XML? Have you added the permissions necessary?

<android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<android:name="android.permission.ACCESS_FINE_LOCATION" />

Were you getting any exceptions in your logcat trace? I recommend trying this on a real device to rule out config issues with your emulator.

FYI, here's how I turn on debug trace for my app using adb logcat:

adb shell stop
adb shell setprop log.tag.MYTAG DEBUG
adb shell start
adb logcat MYTAG:D *:W > c:\temp\trace.txt

To avoid having to mess around with DEBUG level trace, I suggest you stick with logging at Log.INFO level. In that case you only need the last command.

这篇关于的Andr​​oid的LocationManager不能调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆