RNK
RNK

Reputation: 5792

required android.app.Fragment

I am using android.support.v4.app.Fragment. But, it's asking me to use android.app.Fragment that I can't. How can I resolve below issue:

import android.support.v4.app.Fragment;
public class CameraFragment extends Fragment implements View.OnClickListener, FragmentCompat.OnRequestPermissionsResultCallback {
    private void requestCameraPermission() {
       --> if (FragmentCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
           --> new ConfirmationDialog().show(getChildFragmentManager(), FRAGMENT_DIALOG);
        } else {
            FragmentCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA},
                    REQUEST_CAMERA_PERMISSION);
        }
    }
}

ERROR: Found: com.example.app.CameraFragment, required android.app.Fragment

public static class ConfirmationDialog extends DialogFragment {
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final android.app.Fragment parent = getParentFragment();
        return new AlertDialog.Builder(getActivity())
                .setMessage(R.string.request_permission)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        FragmentCompat.requestPermissions(parent,
                                new String[]{Manifest.permission.CAMERA},
                                REQUEST_CAMERA_PERMISSION);
                    }
                })
                .setNegativeButton(android.R.string.cancel,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Activity activity = parent.getActivity();
                                if (activity != null) {
                                    activity.finish();
                                }
                            }
                        })
                .create();
    }
}

Upvotes: 0

Views: 819

Answers (1)

kris larson
kris larson

Reputation: 30985

If you are using the v4 support lib you shouldn't need FragmentCompat:

    if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {

If that method isn't available, you might need to update your build.gradle to a new version of the v4 support lib.

Upvotes: 1

Related Questions