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