2016-04-10 24 views
1

Uygulamamda bir harita etkinliğim var. Üzerinde yer izinleri talep etmeye çalışıyorum, ancak istek izinleri görünmüyor. Ben Bu benim tam kod neden ...Uygulama istekleri gösterilmiyor

hiçbir fikrim yok: Sonunda

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { 
private static final String FIREBASE_URL="https://****.firebaseio.com/"; 
private Firebase firebaseRef; 
private LocationManager locationManager; 
private GoogleMap mMap; 
SupportMapFragment mapFrag; 
boolean bPermissionGranted; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_maps2); 
    Firebase.setAndroidContext(this); 
    firebaseRef = new Firebase(FIREBASE_URL); 

    // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 




    setUpMapIfNeeded(); 

    } 

private void setUpMapIfNeeded() { 
    if (mMap == null) { 
     // Try to obtain the map from the SupportMapFragment. 
     mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
       .getMap(); 

     if (mMap != null) { 


      CameraUpdate center = CameraUpdateFactory.newLatLng(new LatLng(32.065483, 34.824550)); 
      CameraUpdate zoom = CameraUpdateFactory.zoomTo(10); 
      mMap.moveCamera(center); 
      mMap.animateCamera(zoom); 

     } 
    } 
} 

public static final int MY_PERMISSIONS_REQUEST_LOCATION = 99; 
public void checkLocationPermission() { 
    if (ContextCompat.checkSelfPermission(this, 
      Manifest.permission.ACCESS_FINE_LOCATION) 
      != PackageManager.PERMISSION_GRANTED) { 

     // Should we show an explanation? 
     if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 
      if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) { 
       showMessageOKCancel("You need to accept location permissions for using these services!, 
         new DialogInterface.OnClickListener() { 
          @Override 
          public void onClick(DialogInterface dialog, int which) { 
           if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 
           { 
            Toast.makeText(MapsActivity.this, "came here 1", Toast.LENGTH_SHORT).show(); 
            requestPermissions(new String[]{Manifest.permission.WRITE_CONTACTS}, 
              MY_PERMISSIONS_REQUEST_LOCATION); 
          } 
          } 
         }); 
       return; 
      } 

      requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 
        MY_PERMISSIONS_REQUEST_LOCATION); 
      Toast.makeText(MapsActivity.this, "came here 2", Toast.LENGTH_SHORT).show(); 
      return; 

     } 
     else 
     { 
      mMap.setMyLocationEnabled(true); 
      Toast.makeText(MapsActivity.this, "came here 3", Toast.LENGTH_SHORT).show(); 
     } 
    } 



} 

private void showMessageOKCancel(String message, DialogInterface.OnClickListener okListener) { 
    new AlertDialog.Builder(MapsActivity.this) 
      .setMessage(message) 
      .setPositiveButton("OK", okListener) 
      .setNegativeButton("Cancel", null) 
      .create() 
      .show(); 
} 

@Override 
public void onRequestPermissionsResult(int requestCode, 
             String permissions[], int[] grantResults) { 
    switch (requestCode) { 
     case MY_PERMISSIONS_REQUEST_LOCATION: { 
      // If request is cancelled, the result arrays are empty. 
      if (grantResults.length > 0 
        && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 

       // permission was granted, yay! 
       if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && 
         ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { 
        mMap.setMyLocationEnabled(true); 
       } 
      } else { 
       // permission denied, boo! Disable the 
       // functionality that depends on this permission. 
       Toast.makeText(this, "Permission Denied", Toast.LENGTH_LONG).show(); 
      } 
      return; 
     } 

    } 
} 


@Override 
public void onMapReady(final GoogleMap googleMap) { 

    mMap=googleMap; 

    mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 

    checkLocationPermission(); 


} 

, tost "gösterilmesini burada 2 geldi". Sanırım isteklerin ortaya çıkmamasıdır. Ben

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

Belki bu izinleri kullanmak için bir şeyler yazmak gerekiyor ?: Bu çizginin dışında Manifest'inizde şeyler yazmak gerekiyor mu?

LogCat tekrar baktıktan sonra bu ne anlama gelir bu I/Choreographer: Skipped 46 frames! The application may be doing too much work on its main thread.

log buldum?

+0

Manifest 'android.permission.INTERNET' – Naz141

+0

@ Naz141 içeriyor mu? Bu satırı benim Manifest – olash12345

+0

içinde buldum Bu satırı logcat'te buldum, belki sorun nedir? 'I/Koreograf: 46 kare atladım! Uygulama ana iş parçacığı üzerinde çok fazla iş yapıyor olabilir. ' – olash12345

cevap

4

Bu sorunla ilgili günleri harcadıktan sonra, istek izinlerinin gösterilmemesinin nedeninin TabHost nedeniyle olduğunu öğrendim.

Bir MainActivity içinde bir TabHost parçası olan bir Harita Etkinliğinden izin isteğinde bulundum. Şimdi, TabHost'taki bir etkinlikten izin almanın imkansız olduğunu anladım.

İstek izinleri kodunu MapActivity'den MainActivity'ye taşıdıktan sonra çalıştı.