私はandroid.iは初めてですが、エミュレーターでアプリケーションを実行しますが、常にエラー.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"/>