Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package permissions.dispatcher.ktx.sample;
import android.Manifest;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import permissions.dispatcher.PermissionRequest;
import permissions.dispatcher.ktx.FragmentExtensionsKt;
import permissions.dispatcher.ktx.PermissionsRequester;
class MainFragment extends Fragment {
@NonNull
private PermissionsRequester permissionsRequester;
@Override
public void onAttach(Context context) {
super.onAttach(context);
permissionsRequester = FragmentExtensionsKt.constructPermissionsRequest(this,
new String[]{Manifest.permission.CAMERA},
new Function1<PermissionRequest, Unit>() {
@Override
public Unit invoke(PermissionRequest permissionRequest) {
return null;
}
},
new Function0<Unit>() {
@Override
public Unit invoke() {
return null;
}
},
new Function0<Unit>() {
@Override
public Unit invoke() {
return null;
}
},
new Function0<Unit>() {
@Override
public Unit invoke() {
return null;
}
});
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
permissionsRequester.launch();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment