我试图在几秒钟后结束新的拨出呼叫。这是我的代码:
public class phonecalls extends Activity {
ComponentName cn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
call();
}
private void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
cn = new ComponentName(getApplicationContext(), Receiver.class);
} catch (ActivityNotFoundException activityException) {
Log.e("dialing-example", "Call failed", activityException);
}
}
}
我的接收者类别是:
public class Receiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
setResultData(null);
}
}
}
我无法中止去电。我是 Android 新手,似乎无法让它工作。
您无法在 Android 中结束通话。当您调用 startActivity(callIntent) 时,您将放弃对本机调用者应用程序的控制。现在只能通过电话应用程序中止呼叫。
除此之外,开始调用后的代码没有多大意义。您没有对您正在创建的 ComponentName 执行任何操作,因此您的接收器的 onReceive 方法永远不会被调用。此外,如果接收者被调用,onReceive 方法中的代码将不会执行任何操作来改变电话呼叫的状态。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)