如何解决即使应用程序在特定时间关闭,也可以打开电话拨号器
即使我的应用程序已关闭,我也想在特定时间从我的应用程序打开 android 电话拨号程序。
我为此尝试了 AlarmManager -
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this,CallSchaduleBroadcast.class);
intent.putExtra("PHONE_NUMBER",edtPhone.getText().toString());
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,intent,0);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC,timeInMillis,pendingIntent);
这是我在 CallSchaduleBroadcast 类中的 onReceive 方法-
String number = intent.getStringExtra("PHONE_NUMBER");
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:" + number));
context.startActivity(callIntent);
但这给了我以下错误-
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
我正在构建我的应用程序 -
minSdkVersion 21
targetSdkVersion 29
这是完成我的工作的正确方法还是我需要尝试其他东西,例如 Job Scheduler 或 Work Manager。 请帮助我,提前致谢
解决方法
糟糕,我得到了解决方案
int main()
{
// Start with the empty list
struct Node* head = NULL;
int i;
// Insert through a for loop
for (i = 0; i < 5; i++)
AddtoHead(&head,i+10);
printf("hello %d times!\n",i);
PrintFList(head); // --> Segmentation fault!
}
我只需要在 callIntent 中将Flags 设置为FLAG_ACTIVITY_NEW_TASK。
但我仍然想知道是否有使用 Job Scheduler 或 Work Manager 的更好的解决方案。谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。