即使应用程序不是在后台运行,我也希望启动诸如whatsapp和facebook messenger之类的来电活动。
此刻,只有在应用程序在后台运行时,呼叫活动才会启动。
public class callActivity extends AppCompatActivity {
Button acceptCall;
Button delinceCall;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call);
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
acceptCall = findViewById(R.id.answer_call_btn);
delinceCall = findViewById(R.id.reject_call_btn);
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
acceptCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendToVideoCall();
}
});
}
private void sendToVideoCall() {
Intent mainIntent = new Intent(callActivity.this, videoCallActivity.class);
startActivity(mainIntent);
finish();
}
}