我使用 "Action to make Phone Call" 但我需要自动拨打电话 5 或 10 分钟
I use "Action to make Phone Call" but I need to make a called automatically for 5 or 10 min
这是一个例子
但我需要自动拨打电话 5 分钟或 10 分钟。我怎样才能做到?
Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("0000000000"))
try{
startActivity(in);
}
您可以使用广播接收器并将动作设置为时间 change.And 设置每 5 分钟发送一次动作到广播接收器的警报。
在您的 activity:
中添加此代码
PendingIntent service = null;
Intent intentForService = new Intent(context.getApplicationContext(), YourService.class);
final AlarmManager alarmManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
final Calendar time = Calendar.getInstance();
time.set(Calendar.MINUTE, 0);
time.set(Calendar.SECOND, 0);
time.set(Calendar.MILLISECOND, 0);
if (service == null) {
service = PendingIntent.getService(context, 0,
intentForService, PendingIntent.FLAG_CANCEL_CURRENT);
}
alarmManager.setRepeating(AlarmManager.RTC, time.getTime()
.getTime(), 60000, service);
创建Broadcast Receiver并在receiver的onReceive()中添加Make Call的代码。
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("BroadcastReceiver", "debut receive");
Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("0000000000"))
startActivity(in);
}
}
希望对您有所帮助。
快乐编码..
这是一个例子 但我需要自动拨打电话 5 分钟或 10 分钟。我怎样才能做到?
Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("0000000000"))
try{
startActivity(in);
}
您可以使用广播接收器并将动作设置为时间 change.And 设置每 5 分钟发送一次动作到广播接收器的警报。 在您的 activity:
中添加此代码PendingIntent service = null;
Intent intentForService = new Intent(context.getApplicationContext(), YourService.class);
final AlarmManager alarmManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
final Calendar time = Calendar.getInstance();
time.set(Calendar.MINUTE, 0);
time.set(Calendar.SECOND, 0);
time.set(Calendar.MILLISECOND, 0);
if (service == null) {
service = PendingIntent.getService(context, 0,
intentForService, PendingIntent.FLAG_CANCEL_CURRENT);
}
alarmManager.setRepeating(AlarmManager.RTC, time.getTime()
.getTime(), 60000, service);
创建Broadcast Receiver并在receiver的onReceive()中添加Make Call的代码。
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("BroadcastReceiver", "debut receive");
Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("0000000000"))
startActivity(in);
}
}
希望对您有所帮助。 快乐编码..