コード例 #1
0
ファイル: GPS_receiver.java プロジェクト: starboxs/Locate
 public void run() {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
     if (context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
             != PackageManager.PERMISSION_GRANTED
         && context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
             != PackageManager.PERMISSION_GRANTED) {
       // TODO: Consider calling
       //    public void requestPermissions(@NonNull String[] permissions, int requestCode)
       // 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 Activity#requestPermissions for more details.
       return;
     }
   }
   if (lms != null) {
     lms.requestLocationUpdates(bestProvider, 0, 0, GPS_Receiver.this);
   }
   // 服務提供者、更新頻率60000毫秒=1分鐘、最短距離、地點改變時呼叫物件
 }
コード例 #2
0
  @SuppressLint("NewApi")
  public static boolean hasPermission(Context context, String permission) {

    if (!sIsAtLeastM) return true;
    return context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
  }