Q:

Request phone call permissions from ViewHolder

My app has a RecyclerView with a list a restaurants, in which every restaurant has a button to make a phone call. 
The phone call works with all APIs except the 23 one.  The problem is the app must request permissions to make the phone calls, but it can't do this from a non-activity class. 
I tried passing the context, but it didn't work for me. 
Here is the method that binds the restaurant to the CardView. 
public void bind(final Restaurant restaurant) {
    name.setText(restaurant.getName());
    address.setText(restaurant.getAddress());
    city.setText(String.format("%05d %s (%s)", restaurant.getZip(), restaurant.getCity(), restaurant.getRegion()));
    switch (restaurant.getCountry()) {
        case "France":
            country.setText(R.string.france);
            break;
        case "Spain":
            country.setText(R.string.spain);
            break;
        case "Poland":
            country.setText(R.string.poland);
            break;
        case "Portugal":
            country.setText(R.string.portugal);
    }
    latitude = restaurant.getLatitude();
    longitude = restaurant.getLongitude();

    phoneCall.setOnClickListener(new View. OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent. ACTION_CALL, Uri.parse("tel:"+restaurant.getPhone()));
           //                
           // Here I should request the permissions
           // 
           v.getContext().startActivity(intent);
        }
    });

    navigation.setOnClickListener(new View. OnClickListener() {
        @Override
        public void onClick(View v) {
            Uri gmmIntentUri = Uri.parse("google.navigation:q=" + latitude + "," + longitude);
            Intent mapIntent = new Intent(Intent. ACTION_VIEW, gmmIntentUri);
            mapIntent.setPackage("com.google.android.apps.maps");
            v.getContext().startActivity(mapIntent);
        }
    });
}

Any solution?  Thanks in advance

A:

You should create a interface and send phoneCall click event to your Activity and from there you can request the permissions. 
Sample Code
public class RecyclerAdapter extends RecyclerView. ViewHolder{
    private OnPhoneCallListener listener;

    public void setListener(OnPhoneCallListener listener){
        this.listener = listener;
    }

    public void bind(final Restaurant restaurant) {
          ..........
          ..........
          ..........

        phoneCall.setOnClickListener(new View. OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener ! = null){
                    listener.onPhoneCallClick(restaurant.getPhone());
                }
            }
        });

          ..........
          ..........
          ..........
    }
    public interface OnPhoneCallListener{
        void onPhoneCallClick(String phoneNumber);
    }
}

From Activity class
// Register for callback event. 
RecyclerAdater.setListener(new OnPhoneCallListener(){

    @Override
    public void onPhoneCallClick(String phoneNumber){
        //This portion will get execute when user will click on call button. 
        // Now here you can check for the permission, if it is granted,
        // you can fire `ACTION_CALL` intent. 
    }
});

