【问题标题】:Use applicaiton while mobile is locked android studio在手机被锁定时使用应用程序 android studio
【发布时间】:2021-06-06 01:05:50
【问题描述】:

如何在 android studio 中制作在移动设备被锁定时工作的应用程序。假设在任何紧急情况下,如果用户在手机上滑动或按下锁定按钮 2 次,它将在手机被锁定时将其位置发送到保存的紧急号码。有什么想法吗?

【问题讨论】:

标签: java android firebase google-api


【解决方案1】:

由于您的应用程序未在使用中,并且您想监听某些特定事件并执行特定任务,因此您应该使用Service。您可以按照此答案中的说明创建LockService

https://stackoverflow.com/a/30030372/4491971

您可以编写将位置发送到保存的紧急号码的操作,而不是按照该答案中的说明开始活动。

package com.example.userpresent;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

public class ScreenReceiver extends BroadcastReceiver {

    public static boolean wasScreenOn = true;

    @Override
    public void onReceive(final Context context, final Intent intent) {
       if(intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
            // YOUR OPERATION CAN BE DONE HERE
        }
    }
}

【讨论】:

    猜你喜欢
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多