1

我在我的應用程序中使用地理圍欄。如果用戶在第一次設備運行後首先切換位置,他會要求同意Google的位置。但如果用戶不同意,geofences初始化會返回錯誤代碼1000.Android使用Google的位置服務對話框

有什麼方法可以再次詢問是否從我的應用程序使用Google位置?

我知道this questin,但這個對話框只在第一次啓動位置設置時啓動。如果用戶禁止,恕我直言,沒有辦法顯示對話框。或者有什麼辦法?

感謝您anwser

+0

不清楚你在問什麼。什麼會阻止你能夠再次提示用戶? –

回答

-1

正如你的問題被評論,我不知道你問什麼,但你可以測試用戶是否原本不同意位置許可使用shouldShowRequestPermissionRationale

下面是一些基於我使用的Requestion Permissions文檔的擴展代碼,可能會對您有所幫助。

if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED 
      && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { 

     Log.d(TAG, "checkMyPermissions (" + permissionRequestCode + ") : Permissions FAILED"); 
     // Should we show an explanation? 

     if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { 
      // Show an explanation to the user *asynchronously* -- don't block 
      // this thread waiting for the user's response! After the user 
      // sees the explanation, try again to request the permission. 
      new AlertDialog.Builder(this) 
        .setMessage("In order to show data this app requires location permissions") 
        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          ActivityCompat.requestPermissions(MainActivity.this, 
            new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 
            permissionRequestCode); 
         } 
        }) 
        .setNegativeButton(android.R.string.cancel, null) 
        .show(); 

     } else { 
      ActivityCompat.requestPermissions(this, 
        new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 
        permissionRequestCode); 
     } 
     return false; 
    } else { 
     Log.d(TAG, "checkMyPermissions (" + permissionRequestCode + ") : Permissions Passed"); 
     return true; 
    } 
+0

他詢問Google的位置服務對話框(https://i.stack.imgur.com/ccg4k.png),而不是關於自定義權限請求。 – algarrobo

+0

這個問題對我來說似乎很清楚。 – algarrobo