小编Ste*_*ail的帖子

使用地理围栏时如何通知来自 BroadcastReceiver 的调用活动

我根据地理围栏文档定义了一个 BroacastReceiver,以便在用户与地理围栏交互时接收 ENTRY 和 EXIT 更新。我的问题是,该应用程序将在路上使用,因此,当用户驾驶并进入地理围栏时,我会收到有关此情况的通知,并且当他退出地理围栏时也会发生同样的情况。但是,当收到退出事件时,我需要从客户端和 Google 地图地图中删除触发的地理围栏。这两个都存在于我的 MapsActivity 中(这是我根据文档设置接收器和事件通知过程的地方),因此我想removeGeofences(...)从接收器调用我的活动的方法。我查看了大量有关此事的帖子,但似乎没有一个涵盖地理围栏用例。我尝试通过代码动态地声明接收器,而不是通过清单静态地声明,但在这种情况下,我需要意图过滤器,而我无法找到地理围栏的意图过滤器。关于如何实现这一目标有什么想法吗?

广播接收器:

class GeofenceReceiver : BroadcastReceiver() {
    private val TAG = GeofenceReceiver::class.java.simpleName

    override fun onReceive(context: Context?, intent: Intent?) {
        val geofencingEvent = GeofencingEvent.fromIntent(intent)
        if (geofencingEvent.hasError()) {
            val errorMessage = GeofenceStatusCodes
                .getStatusCodeString(geofencingEvent.errorCode)
            Log.e(TAG, "error: $errorMessage")
            return
        }

        // Get the transition type.
        val geofenceTransition = geofencingEvent.geofenceTransition

        // Test that the reported transition was of interest.
        if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
            geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT
        ) {

            // Get the geofences that …
Run Code Online (Sandbox Code Playgroud)

android google-maps broadcastreceiver kotlin android-geofence

4
推荐指数
1
解决办法
452
查看次数

将 Firebase 实时数据库 json 响应从 _InternalLinkedHashMap<Object?, Object?> 转换为 Map<String,dynamic>

我的 Firebase 实时数据库中有一个子数据库,如下所示: 在此输入图像描述

以下是我在 Flutter 应用程序中通过 firebase 调用收到的 JSON:

{
  "gameAnalytics" : {
    "log" : {
      "20210926073039AbMc4uSXywqpK9OcusSV" : {
        "cityID" : "newYork",
        "countryCode" : "USA",
        "gameID" : "20210927065000Upper90IndnewYofootbiGZYy",
        "gamePaymentMethod" : "payAtPitch",
        "players" : {
          "umZ5ezrtI6a3UoCDWFDc3hInoNA2" : {
            "pnam" : "Mario Rest",
            "url" : "https://i.ibb.co/blahblah.jpg"
          }
        },
        "sportID" : "football",
        "status" : {
          "202109261130395laHd8h77R" : "completing, send back",
          "20210926113039BcUQ8RdbHs" : "payAtPitch",
          "20210926113039Ck9JsD1uf1" : "playersAdded"
        },
        "timeAndDateString" : "20210926073039",
        "totalCost" : 999,
        "type" : "ADD",
        "userWhoAddedID" : "umZ5ezrtI6a3UoCDWFDc3hInoNA2",
        "wantsToBeOrganizer" : true
      }, …
Run Code Online (Sandbox Code Playgroud)

json dart firebase firebase-realtime-database flutter

4
推荐指数
1
解决办法
1908
查看次数

使用 Koin 注入 CoroutineDispatcher

我正在阅读Google 的数据层指南,在链接的部分中,他们有以下片段:

class NewsRemoteDataSource(
  private val newsApi: NewsApi,
  private val ioDispatcher: CoroutineDispatcher
) {
    /**
     * Fetches the latest news from the network and returns the result.
     * This executes on an IO-optimized thread pool, the function is main-safe.
     */
    suspend fun fetchLatestNews(): List<ArticleHeadline> =
        // Move the execution to an IO-optimized thread since the ApiService
        // doesn't support coroutines and makes synchronous requests.
        withContext(ioDispatcher) {
            newsApi.fetchLatestNews()
        }
    }
}

// Makes news-related network synchronous requests.
interface NewsApi …
Run Code Online (Sandbox Code Playgroud)

android kotlin koin kotlin-coroutines

4
推荐指数
1
解决办法
2726
查看次数

导航菜单项单击不起作用

我为我的应用程序创建了一个侧菜单(导航菜单)并覆盖了 OnOptionsItemSelected(MenuItem item) 方法,以便在单击每个菜单项时添加一些自定义行为。但是,在编写了一些代码之后,当点击第一个菜单项时(nav_home <- id)将显示 Toast,当我点击它时没有任何反应,我无法弄清楚这里的问题......

    @Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(mToggle.onOptionsItemSelected(item)) {
        return true;
    }
    // When a menu item is clicked, then depending on it's id start a new Activity
    switch (item.getItemId()) {
        case R.id.nav_home:
            Toast.makeText(this, "Clicked", Toast.LENGTH_SHORT).show();
            break;
        default:
            return super.onOptionsItemSelected(item);
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

这是我的整个 MainActivity 类:

package com.dcv.spdesigns.dokkancards;

import android.content.Intent;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

import …
Run Code Online (Sandbox Code Playgroud)

java android switch-statement onclicklistener

2
推荐指数
1
解决办法
2749
查看次数

检查 Firestore 中的任何文档是否包含子字符串

我在 Firestore 中收集了大量具有随机 ID 的文档,每个文档都有两个字段:名称和描述。我希望我的应用程序允许用户输入一系列字符,然后向他展示包含该字符序列(例如名称字段)的所有文档。使用 Firebase 及其查询是否可行?如果可以,您能给我一个 Kotlin 或 Java 代码示例吗?我知道有一些方法,例如hasChild()child("child name").exists(),但由于我还不知道用户正在查找哪个文档,如果我没有弄错的话,我无法使用它们。

例如,如果我有 3 个具有以下名称(“mike”、“michael”、“dave”)的文档的集合,并且用户输入“mi”,我希望能够检索其名称的文档是“迈克”和“迈克尔”。

android firebase google-cloud-firestore

2
推荐指数
1
解决办法
7736
查看次数

在 javaFX 8 中添加 Button 节点会引发异常 - javafx.fxml.LoadException:无效标识符

我在创建的 StackPane 布局中添加了两个图像视图,但是当我尝试在 StackPane 布局中添加按钮节点时,虽然图像工作得很好,但按钮不允许程序运行并抛出此错误我无法弄清楚的例外:

> > Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: javafx.fxml.LoadException: Invalid identifier.
/C:/Users/Steli/Dropbox/Java_Projects/IntelliJ%20IDEA%20Projects/DokkanCardsPreview/out/production/DokkanCardsPreview/fxml/home.fxml:33
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:901)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at …
Run Code Online (Sandbox Code Playgroud)

java exception intellij-idea fxml javafx-8

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

指针算法出错了

我正在尝试使用a char *来存储一个字符串,因为指针指向给char定字符串中第一个的内存位置,我尝试使用指针arithmetic(ptr++)来移动到下一个char(因为它们是按顺序存储的) .但是,在我的示例程序中,"string"大小是22,但是当我尝试运行for循环时,如下所示,它只运行12次.知道为什么吗?我是否错过了关于指针算法如何工作的重要内容?

#include <stdio.h>

int main(void) {
  char *strVar = "testfordifferentlength";
  int i,timesCalled=0;
  printf("\nLength = %d\n\n",strlen(strVar));
  for(i=0;i <= strlen(strVar);i++){
    printf("%c",*strVar);
    strVar++;
    timesCalled++;
  }
  printf("\n\nFor loop run %d times!\n",timesCalled);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c pointers pointer-arithmetic

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

malloc和指针问题

昨天我们在课堂上看到了这个节目,我对它的输出有疑问.

malloc.c:

#include <stdlib.h>

int *create_array(int);

int *create_array(int elements) {
    int i,*x = (int *) malloc(elements*sizeof(int));

    for(i=0;i < elements;i++) {
        x[i] = i;
    }
    free(x);
    return x;
} 

int main(void) {
    int j, *arr;
    arr = create_array(5);
    for(j=0;j<5;j++) {
        printf("%d\n",arr[j]);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

问题(S):

当我运行程序时,我得到这个作为输出:

1627793032
1627793104
2
3
4
Run Code Online (Sandbox Code Playgroud)

但是,前2个元素不应该分别为0和1吗?这里打印的值对我来说就像是记忆地址,对不对?另外,这是由于某些错误造成的undefined behavior吗?

c malloc pointers

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