1
Activity act = (Activity)mcontext;
            final Intent callIntent = new Intent(Intent.ACTION_CALL);
            String s = list.get(position).phone;
            callIntent.setData(Uri.parse("tel:"+s));

            Dexter.withActivity(act)
                    .withPermission(Manifest.permission.CALL_PHONE)
                    .withListener(new PermissionListener() {
                        @Override public void onPermissionGranted(PermissionGrantedResponse response) {

                            mcontext.startActivity(callIntent);
                        }
                        @Override public void onPermissionDenied(PermissionDeniedResponse response) {
                            Toast.makeText(mcontext, "Accept call permissions first!",
                                Toast.LENGTH_LONG).show();}
                        @Override public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {/* ... */}
                    }).check();

java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity

is the error that shows up at the line Activity act = (Activity)mcontext;. The application crashes when this code is to be executed. Directly putting mcontext in Dexter.withActivity shows an error even before i run the app.

This is the code from an Adapter. The root activity is: public class HodWithPhoneNumber extends Activity

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Chirag
  • 149
  • 2
  • 17
  • +Joe C, No I saw that question earlier. My case is different. The code i have provided is in an adapter. – Chirag Jul 09 '17 at 17:17
  • 1
    Doesn't matter... You have assigned `mcontext` to an Application, not an Activity, as the duplicate states. Wherever you created the adapter, change the context you provided to be an Activity – OneCricketeer Jul 09 '17 at 17:19

0 Answers0