发送未接来电-Android程序
Send a missed call-Android program
我想编写一个 android 应用程序,它可以向某人发送未接来电。这意味着应用程序调用 sb 大约需要 5 秒。
我知道这段代码开始调用。
private void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
} catch (ActivityNotFoundException e) {
Log.e("helloandroid dialing example", "Call failed", e);
}
}
但我不知道如何停止它(5 秒后)?
Ps.This 问题打了 -1 是因为问题很蠢还是我的英语不好?
没有直接的方法来执行此操作,因为一旦启动 callIntent,控件就会转到调用应用程序。
但是有一些解决方法可以通过使用 java 反射获取 TelephonyManager
的 ITelephony
对象来实现。
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
}catch(Exception e){}
telephonyService.endCall();
最简单的方法是使用延迟处理程序,并在您拨打目标号码后重新拨打自己的电话。希望这不是出于垃圾邮件目的,这是不受欢迎的。在您的代码片段或循环中,您可以拥有以下内容
if (checkPermission(Manifest.permission.CALL_PHONE)) {//targetMSISDN the phone no you are calling out to
String dial = "tel:" + targetMSISDN;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
//startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
//delay a drop call
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 10000ms
Toast.makeText(YourNotSpamActivity.this, "Calling me to end you!", Toast.LENGTH_SHORT).show();
//end call now
String TAG="ERR:";
try {
Log.v(TAG, "Get getTeleService...");
if (checkPermission(Manifest.permission.CALL_PHONE)) {
String dial = "tel:YourPhoneNumber";
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));//call yourself to terminate the first call
}
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG,
"FATAL ERROR: couldn't call ");
Log.e(TAG, "Exception object: " + e);
}
}
}, 10000);
//end the end call
} else {
Toast.makeText(YourNotSpamActivity.this, "Permission Call Phone denied", Toast.LENGTH_SHORT).show();
}
我想编写一个 android 应用程序,它可以向某人发送未接来电。这意味着应用程序调用 sb 大约需要 5 秒。 我知道这段代码开始调用。
private void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
} catch (ActivityNotFoundException e) {
Log.e("helloandroid dialing example", "Call failed", e);
}
}
但我不知道如何停止它(5 秒后)?
Ps.This 问题打了 -1 是因为问题很蠢还是我的英语不好?
没有直接的方法来执行此操作,因为一旦启动 callIntent,控件就会转到调用应用程序。
但是有一些解决方法可以通过使用 java 反射获取 TelephonyManager
的 ITelephony
对象来实现。
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
}catch(Exception e){}
telephonyService.endCall();
最简单的方法是使用延迟处理程序,并在您拨打目标号码后重新拨打自己的电话。希望这不是出于垃圾邮件目的,这是不受欢迎的。在您的代码片段或循环中,您可以拥有以下内容
if (checkPermission(Manifest.permission.CALL_PHONE)) {//targetMSISDN the phone no you are calling out to
String dial = "tel:" + targetMSISDN;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
//startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
//delay a drop call
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 10000ms
Toast.makeText(YourNotSpamActivity.this, "Calling me to end you!", Toast.LENGTH_SHORT).show();
//end call now
String TAG="ERR:";
try {
Log.v(TAG, "Get getTeleService...");
if (checkPermission(Manifest.permission.CALL_PHONE)) {
String dial = "tel:YourPhoneNumber";
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));//call yourself to terminate the first call
}
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG,
"FATAL ERROR: couldn't call ");
Log.e(TAG, "Exception object: " + e);
}
}
}, 10000);
//end the end call
} else {
Toast.makeText(YourNotSpamActivity.this, "Permission Call Phone denied", Toast.LENGTH_SHORT).show();
}