Ich habe diese Klasse, die ich erstellt habe, wo muss ich meinen letzten Standort?GPS-Standort nach Genehmigung funktioniert nicht (SDK 23) android studio
public class DescriptionActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks {
TextView t;
Button up;
GoogleApiClient mGoogleApiClient;
LocationManager locationManager;
LocationListener locationListener;
LocationServices mLastLocation;
private static final int PERMS_REQUEST_CODE=123;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hr__description);
Toolbar toolbar = (Toolbar) findViewById(R.id.hr_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
t = (TextView) findViewById(R.id.test_boaz);
up=(Button)findViewById(R.id.upload);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener((GoogleApiClient.OnConnectionFailedListener) this)
.build();
if(hasPermission())
{
getGPS();
}
else {
requestPerms();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case PERMS_REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// All good!
} else {
Log.d("bobbbbbbbbbbbbbbbbbb","boazboabzobaob");
}
break;
}
}
private void getGPS() {
up.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
private boolean hasPermission(){
int res=0;
String[] permissions=new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION};
for(String params:permissions)
{
res=checkCallingOrSelfPermission(params);
if(!(res==PackageManager.PERMISSION_GRANTED)) {
return false;
}
}
return true;
}
private void requestPerms(){
String[] permissions=new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION};
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
requestPermissions(permissions,PERMS_REQUEST_CODE);
ActivityCompat.requestPermissions(this, permissions, PERMS_REQUEST_CODE);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onConnected(@Nullable Bundle bundle) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mLastLocation != null) {
}
}
@Override
public void onConnectionSuspended(int i) {
}
}
Ich habe versucht, GPS zu aktivieren und sie wollen, dass ich immer Berechtigungen überprüfen wie man es beheben? sahen viele Beispiele im Internet und ich habe erfolgreich Dialog zu erhalten GPS-Gerät zu aktivieren, aber wenn ich versuche Lage i Problem
Können Sie Fehlerdialog posten? – NilayDani
Ich habe keinen Fehler, nur er bittet mich, Berechtigungen hinzuzufügen –
Welche Erlaubnis? – NilayDani