0

我是android的新手。我通过模拟器运行应用程序。但总是错误.logcat显示:无法打开堆栈跟踪文件'/data/anr/traces.txt':权限被拒绝

WhereAmIActivity.Java

package com.paad.whereami;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class WhereAmIActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    LocationManager locationManager;
    String context = Context.LOCATION_SERVICE;
    locationManager = (LocationManager)getSystemService(context);//bulid locationmanager

    String provider = LocationManager.KEY_LOCATION_CHANGED;
    Location location = locationManager.getLastKnownLocation(provider);//get lastlocation

    updateWithNewLocation(location);//pass to updatewithnewlocation
}

private void updateWithNewLocation(Location location){//show Location in TextView
    String latLongString;
    TextView myLocationText;
    myLocationText = (TextView)findViewById(R.id.myLocationText);//
    if(location!=null){//
        double lat = location.getLatitude();
        double lng = location.getLongitude();
        latLongString = "Lat:"+lat+"\nLong:"+lng;
    }else{//
        latLongString = "No location found";
    }
    myLocationText.setText("Your Current POsition is:\n"+latLongString);//
}

}

使用许可

<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
4

2 回答 2

0

这不是您获取当前位置的方式。它只是最后一个已知的位置。为了获得当前位置,您需要请求操作系统告诉您何时获得新位置(因为它需要未知时间,基于很多事情)并且您可能在,然后使用它。

于 2012-06-19T13:21:24.380 回答
0

无法打开堆栈跟踪文件“/data/anr/traces.txt”:权限被拒绝

我不知道您要在哪里访问 traces.txt 文件。但是如果它显示权限错误,以便解决它,请给予它完全访问权限:)

在终端中执行以下命令

$adb shell
#cd \data
#chmod 777 anr

请记住,如果您在实际设备上尝试,上述命令可能不起作用。您需要 root。

于 2012-06-19T12:52:53.410 回答