Search in sources :

Example 1 with MobicomkitUriListener

use of com.applozic.mobicomkit.uiwidgets.uilistener.MobicomkitUriListener in project Applozic-Android-SDK by AppLozic.

the class PictureUploadPopUpFragment method imageCapture.

public void imageCapture() {
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (!(getActivity() instanceof MobicomkitUriListener)) {
        Utils.printLog(getContext(), TAG, "Activity must implement MobicomkitUriListener to get image file uri");
        return;
    }
    if (cameraIntent.resolveActivity(getContext().getPackageManager()) != null) {
        Uri capturedImageUri = ((MobicomkitUriListener) getActivity()).getCurrentImageUri();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            ClipData clip = ClipData.newUri(getActivity().getContentResolver(), "a Photo", capturedImageUri);
            cameraIntent.setClipData(clip);
            cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            List<ResolveInfo> resInfoList = getActivity().getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                getActivity().grantUriPermission(packageName, capturedImageUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                getActivity().grantUriPermission(packageName, capturedImageUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }
        }
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
        getActivity().startActivityForResult(cameraIntent, ProfileFragment.REQUEST_CODE_TAKE_PHOTO);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) MobicomkitUriListener(com.applozic.mobicomkit.uiwidgets.uilistener.MobicomkitUriListener) Intent(android.content.Intent) List(java.util.List) Uri(android.net.Uri) ClipData(android.content.ClipData)

Aggregations

ClipData (android.content.ClipData)1 Intent (android.content.Intent)1 ResolveInfo (android.content.pm.ResolveInfo)1 Uri (android.net.Uri)1 MobicomkitUriListener (com.applozic.mobicomkit.uiwidgets.uilistener.MobicomkitUriListener)1 List (java.util.List)1