我正试图在几秒钟后结束新的拨出电话。这是我的代码:
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 新手,似乎无法使其正常工作。