我有一个正在开发的与木板连接的应用程序。如果木板检测到跌倒,则应用会拨打用户设置的号码。但是,该应用程序仅在打开时才能运行。我希望该应用程序在后台运行,以便即使用户随便浏览网页或执行其他操作,如果发生跌倒,该应用程序都能够执行调用功能。下面,我添加了执行上述调用函数的代码。
@ Override
public int onStartCommand(Intent intent, int flags, int startId) {
public void displayEvent(@AccelerationEvent int event, int data)
{
if (mCurrentDetectEvent == FeatureAccelerationEvent.DetectableEvent.FREE_FALL) {
Context context = getContext();
mShakeImage.start();
button.setOnClickListener(v -> {
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
System.exit(0);
});
new Handler().postDelayed(() -> {
new AlertDialog.Builder(context)
.setTitle("Alert")
.setMessage("This is an alert")
.show();
//---------------call function from CallScreen()------------------------------------
Intent intent = new Intent(context.getApplicationContext(), CallScreen.class);
context.startActivity(intent);
}, 10000);
}