可以在后台打电话
我在日志中得到“呼叫...”,但没有打电话。我正在使用工人。我还尝试了AlarmManager,服务,广播电视台,但它没有用。
public void doAction(){
context = getApplicationContext();
long phone = Long.parseLong(Preferences.getLastNum(context));
String message = Preferences.getLastMessage(context);
String action = Preferences.getAction(context);
Log.i(TAG, action);
if(action != null) {
if (action.equals("call")) {
Log.i(TAG, "calling...");
Intent i = new Intent(Intent.ACTION_CALL);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_FROM_BACKGROUND);
i.setData(Uri.parse("tel:" + phone));
context.startActivity(i);
} else if (action.equals("sms")){
Log.i(TAG, "sending...");
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(String.valueOf(phone), null, message, null, null);
}
} else{
Log.i(TAG, "ERROR: action = null");
}
Preferences.clearPreferences(context, "0");
}
I get "calling..." in logs, but it doesn't call. I'm using WorkManager. I also tried AlarmManager, Service, BroadcastReceiver, but it didn't work.
public void doAction(){
context = getApplicationContext();
long phone = Long.parseLong(Preferences.getLastNum(context));
String message = Preferences.getLastMessage(context);
String action = Preferences.getAction(context);
Log.i(TAG, action);
if(action != null) {
if (action.equals("call")) {
Log.i(TAG, "calling...");
Intent i = new Intent(Intent.ACTION_CALL);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_FROM_BACKGROUND);
i.setData(Uri.parse("tel:" + phone));
context.startActivity(i);
} else if (action.equals("sms")){
Log.i(TAG, "sending...");
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(String.valueOf(phone), null, message, null, null);
}
} else{
Log.i(TAG, "ERROR: action = null");
}
Preferences.clearPreferences(context, "0");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论