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无法强制转换为android.app.Activity
是显示在Activity act = (Activity)mcontext;
行的错误。当要执行此代码时,应用程序崩溃。直接将mcontext
放入Dexter.withActivity
,即使在我运行应用之前也会显示错误。
这是适配器的代码。根活动是:public class HodWithPhoneNumber extends Activity