2017-04-03 89 views
-2

的Android片段,而在5.1 version.in工作的其他移動臺但在Micromax的Q424使用Micromax的Q424被重新加載的片段獲得從選擇相機或畫廊onActivityResult結果之後重新加載之後重新加載。獲得結果後如何避免。片段是得到一個結果從照相機onActivityResult

回答

0

您好,您是否授予使用相機所需的權限,運行時權限還需要與清單權限一起使用。

public boolean CheckPermissionForWriteStorage() { 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && 
       checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { 

      requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 
        PERMISSIONS_REQUEST_CODE_WRITE_EXTERNAL_STORAGE); 

      return false; 
     } 

     return true; 
    } 

使用上面的代碼用於獲取許可 和下面的代碼在onACtivityResult

final boolean isCamera; 
       if (data == null) { 
        isCamera = true; 
       } else { 
        final String action = data.getAction(); 
        if (action == null) { 
         isCamera = false; 
        } else { 
         if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { 
          isCamera = true; 
         } else { 
          isCamera = action.equalsIgnoreCase(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
         } 
        } 
       } 

       if (isCamera) { 
        String selectedImagePath = getImagePath(); 

        aQuery.id(imgFarmerPhoto).image(selectedImagePath); 
       } else { 
        String selectedImagePath = getAbsolutePath(data.getData()); 
        selectedImagePath = getRightAngleImage(selectedImagePath); 
        aQuery.id(imgFarmerPhoto).image(selectedImagePath); 
       } 
相關問題