こんにちは皆Android Studioを使用してナビゲーションアプリケーションを作成していて、このエラーが発生しています。 マイコードはif(ActivityCompat.checkSelfPermission)
セグメントで停止します。ここで私はトーストステートメントを持っています。 AndroidManifestファイルのCOARSE_LOCATION
、FINE_LOCATION
、INTERNET
のアクセス権を既に提供しています。 次のコードがあります。If(ActivityCompat.checkSelfPermission)セグメントからコードが返される
public class Second extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
//Declaring Class Objects
Location location;
LocationManager lm;
GoogleApiClient googleApiClient;
//Data type for storing value of Longitude and Latitude
private double fromLongitude;
private double fromLatitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
googleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
getLocation();
}
private void getLocation() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
Toast.makeText(this,"Issue with permission",Toast.LENGTH_LONG).show();
return;
}
Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);
fromLatitude = location.getLatitude();
fromLongitude = location.getLongitude();
Toast.makeText(this,String.valueOf(fromLatitude)+" "+String.valueOf(fromLongitude),Toast.LENGTH_LONG).show();
}
//Starting Google API Client
@Override
protected void onStart() {
googleApiClient.connect();
super.onStart();
}
//Stopping Google API Client
@Override
protected void onStop() {
googleApiClient.disconnect();
super.onStop();
}
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
これは私は、IFセグメントにトーストを持っていることを、"Issue with Permission"
を印刷します。
に理解するために、ここで参照してください。 http://developer.android.com/training/permissions/requesting.html –
兄弟に感謝しました。 –