Android:通过服务拨打电话

Dom*_*icM 6 android phone-call

我尝试从服务中拨打电话.我使用的代码是:

Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

它在主要活动内部运行良好,但不是从服务运行.错误发生在最后一行.是否无法在服务中拨打电话?

我怎么能在主要活动上运行这段代码呢?

ρяσ*_*я K 8

尝试从服务内部拨打电话:

Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

  • 这对我不起作用,我收到错误:android.content.ActivityNotFoundException:`No Activity found to handle Intent { act=android.intent.action.CALL flg=0x10000004 }` (2认同)