我是新来的android请帮助。
我尝试使用这段代码......
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);
没有工作:它突然停止了 我提到了必要的权限
答案 0 :(得分:0)
请尝试以下代码。
new Handler().post(new Runnable() {
@Override
public void run() {
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);
context.startActivity(intent);
}
});
您将从服务onStart()
方法获取上下文。 Context
的InPlace可以使用getApplicationContext()