小编Nit*_*ani的帖子

在Android中解锁设备的屏幕时启动服务

我希望在屏幕解锁时运行我的服务,并在屏幕锁定时停止它.我查看了这些答案并实施了它们.但是,当我锁定我的屏幕时,服务会根据需要停止,但是当我解锁屏幕时,它不会再次启动.

运行此服务的代码如下:

public class PhonePositionService extends Service {
@Override
    public void onCreate() {
    //ADDED CODE
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    BroadcastReceiver mReceiver = new BootCompletedIntentReceiver();
    registerReceiver(mReceiver, filter);
    {...}
    }
@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
    int icon = R.drawable.ic_stat_bright;
    startForeground(NOTIFICATION_ID, getCompatNotification(icon));
    if (backgroundThread != null) {
      backgroundThread.start();
    }
    return START_STICKY;
  }
}
Run Code Online (Sandbox Code Playgroud)

在其他一些文件中,我的广播接收器代码如下:

public class BootCompletedIntentReceiver extends BroadcastReceiver {
 @Override
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   if(Intent.ACTION_SCREEN_ON.equals(action)) …
Run Code Online (Sandbox Code Playgroud)

service android

13
推荐指数
1
解决办法
634
查看次数

如何在Android应用程序中提供输入并自定义其点击操作时自定义虚拟键盘​​的"输入"?

当一些应用程序用户在Android应用程序中输入一些输入时,我正在寻找一种定制(或处理)虚拟键盘的"输入"的方法,例如,当他在Android应用程序中按" Enter "时(在某些应用程序中) EditText上),或者当他已经完成了给他的输入,然后在该点(或之前)我可以自定义的一些应用程序虚拟键盘,虚拟键盘的"Enter"键(比如,它是" ')的文本,如’ "等等.此外,如果点击或按下虚拟键盘按钮(如Enter键),也可能执行某些(其他)操作.任何形式的帮助将不胜感激.

user-interface android user-experience android-edittext

9
推荐指数
1
解决办法
206
查看次数

即使应用程序在前台,如何让 FCM 显示通知?

如果不是数据消息,让 FCM 处理设备上的通知。

即使应用程序在前台,如何强制 Android 使用 FCM 显示通知?我不想建立自己的通知。

我正在向我的应用程序发送两种类型的消息:数据消息和普通通知消息。数据消息被处理onMessageReceived(),无论应用程序是在后台还是前台或被杀死都可以。但现在我也通过 Firebase 控制台发送正常的通知消息,当应用程序在后台时会自动显示,但当应用程序在前台时会onMessageReceived()被调用。在这里,我需要以某种方式告诉 FCM 显示内容,而不必构建通知。

我试过:

@Override public void onMessageReceived(RemoteMessage remoteMessage) {
        if(remoteMessage.getData() == null || !remoteMessage.getData().containsKey("specificKey")) {
            // notification msg, let FCM handle it
            super.onMessageReceived(remoteMessage); // this is not working - I want FCM to show notification the same as if the app was in background. 
            return;
        } else {
          // data message, I'm handling it on my own and showing a custom notification, working …
Run Code Online (Sandbox Code Playgroud)

android android-notifications firebase-cloud-messaging

5
推荐指数
1
解决办法
3923
查看次数