从适配器调用启动活动

时间:2014-11-29 07:42:57

标签: android android-intent flags

我正在从我的适配器调用呼叫活动但是低于错误 -

11-29 13:10:41.193: E/AndroidRuntime(12623): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

代码 -

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+mMobileList.get(position)));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
((Activity)mContext).startActivity(callIntent);

我也添加了FLAG_ACTIVITY_NEW_TASK。还会收到错误。如何解决?

2 个答案:

答案 0 :(得分:1)

使用此代码

Intent dial = new Intent();
dial.setAction("android.intent.action.DIAL");
dial.setData(Uri.parse("tel:"+strPhone1));
startActivity(dial);

答案 1 :(得分:0)

<uses-permission android:name="android.permission.CALL_PHONE" />