当我开发一个android应用程序时。我想以编程方式拨打电话。关于使用
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
getContext().startActivity(callIntent);
它显示一个错误。我正在使用 FrameLayout 而不是 Activity。
android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
at android.app.ContextImpl.startActivity(ContextImpl.java:1366)
at android.app.ContextImpl.startActivity(ContextImpl.java:1353)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:322)
at com.happiness.lockscreenlibrary.view.LockView$1.onDrag(LockView.java:163)
at android.view.View.dispatchDragEvent(View.java:18339)
at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1492)
at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1478)
at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1478)
at android.view.ViewRootImpl.handleDragEvent(ViewRootImpl.java:5143)
at android.view.ViewRootImpl.access$700(ViewRootImpl.java:108)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3331)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5312)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
我用context.getApplicationContext().startActivity(callIntent);
or context.startActivity(callIntent);
代替了getContext().startActivity(callIntent);
但是它显示了同样的错误。它将如何解决请帮助我。