我正在啓動相機意圖以使用相機應用程序拍攝照片。它在我的默認版本的應用程序中按預期工作。Android for Work中的相機意圖
我已經爲我的應用程序的"Android for Work"
版本實施了相同的代碼,最終出現了一個奇怪的行爲。通常,根據"Android for Work"
視頻,如果Intent位於其他配置文件中,則無法處理該Intent。例如,如果我的工作資料中沒有安裝相機應用程序,Camera Intent在解析後應該爲空,這是預期的。
但在我的情況下,Camera Intent是由安裝在我的默認用戶配置文件中的Camera Application處理的(Work Profile
沒有Camera應用程序)。拍攝照片後,它會返回onActivityResult
,並帶有resultCode
Activity.RESULT_CANCELED
。
所以,我的問題是,我如何區分用戶的Real Cancel Event
和這種情況?他們都有相同的結果,Activity.RESULT_CANCELED
下面的代碼顯示了我如何觸發相機意圖。
/* Create Camera Intent */
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
/* Check if the Camera Intent is Available */
if (cameraIntent.resolveActivity(getActivity().getPackageManager()) == null) {
/* Notify User in Error Case */
UIUtils.notifyUser(getActivity(), getString(R.string.error), getString(R.string.no_camera_application_found));
} else {
/* Create a new File with Random Photo Name */
takenPhoto = new File(FileUtils.getExternalPhotoCacheDirectory(), generatePhotoName());
takenPhoto.createNewFile();
/* Create Uri to send to within the Intent */
Uri outputFileUri = Uri.fromFile(takenPhoto);
/* Set Photo destination File Uri */
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
/* Start Activity for Result */
startActivityForResult(cameraIntent, ACTION_TAKE_PHOTO);
}
您可以處理如有應用程序可以處理這個意圖,子彈 –
@sadeghsaati這就是我在第一機械手做'resolveActiivty'在if語句前。但它不會返回null,意外。 – osayilgan