小编Rel*_*elm的帖子

如何从Android应用程序连接到多个firebase数据库

我正在尝试在Firebase中创建一个项目,该项目将负责所有应用程序的一个常见问题.

也就是说,我想创建应用程序,然后让这些应用程序访问项目的特定Firebase数据库.

查看Firebase Android文档,我找不到使用以下方法将数据发送到另一个项目中的另一个firebase数据库的方法,但是引用是另一个项目.

DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("example");
        ref.push().setValue(d).addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                finish();
            }
        });
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-realtime-database

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

Firebase Firestore:如何在Android上将文档对象转换为POJO

使用实时数据库,可以这样做:

MyPojo pojo  = dataSnapshot.getValue(MyPojo.Class);
Run Code Online (Sandbox Code Playgroud)

作为一种映射对象的方法,人们如何做到这一点Firestore

代码:

FirebaseFirestore db = FirebaseFirestore.getInstance();
        db.collection("app/users/" + uid).document("notifications").get().addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                DocumentSnapshot document = task.getResult();
                if (document != null) {
                    NotifPojo notifPojo = document....// here
                    return;
                }

            } else {
                Log.d("FragNotif", "get failed with ", task.getException());
            }
        });
Run Code Online (Sandbox Code Playgroud)

java android firebase google-cloud-firestore

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

如何在Service_worker.js所在的目录上注册服务工作者的作用域

我的目录如下.

public_html/
sw/
Run Code Online (Sandbox Code Playgroud)

"sw /"是我想要放置所有服务工作者的地方,但是那些服务工作者的范围是"public_html /"中的所有文件.

JS

<script>
if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('sw/notifications.js', { scope: '../sw/' }).then(function(reg) {
    // registration worked
    console.log('Registration succeeded. Scope is ' + reg.scope);
  }).catch(function(error) {
    // registration failed
    console.log('Registration failed with ' + error);
  });
};
</script>
Run Code Online (Sandbox Code Playgroud)

我如何允许这种范围?

javascript scope service-worker

10
推荐指数
2
解决办法
8920
查看次数

Android:如何 OnConflictStrategy.REPLACE 但保留一个特定字段

我在 Android Room 中有一个 DAO,插入时使用 OnConflictStrategy.REPLACE,有一个布尔字段downloaded,如果用户下载了该对象,该字段将更改为 true,我想在冲突时替换整个对象,但保留该字段的状态( downloaded) 在数据库中。

public interface DAOTemplate<T> {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    @NonNull
    void insert(T... messages);

    @Delete
    void delete(T message);

    @Update
    void update(T message);
}
Run Code Online (Sandbox Code Playgroud)

java android android-room android-architecture-components

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

Firebase功能:如何存储简单的cookie以记住经过身份验证的用户

我只想记住用户返回网站并在5分钟后计算视图.我这样做了,在使用时可以工作Firebase Serve,但是在部署后没有存储cookie.

在应用程序的某个地方.

app.use(cookieSession({ name: 'session', keys: ['utl__key_s1', 'utl__key_s2'] }));
Run Code Online (Sandbox Code Playgroud)

试图检查会话是否存在且不超过5分钟.

function sessionExists(req) {
    const t = req.session.viewTime;

    if (t == null) {
        req.session.viewTime = + new Date();
        return false;
    }

    const fiveMinutes = ((1000) * 60) * 5;
    if (((+new Date()) - t) > fiveMinutes) {
        req.session = null;
        return false;
    }

    return true;
}
Run Code Online (Sandbox Code Playgroud)

然后我发现问题是我们必须使用__session.我真的不明白.我可以获得上述代码示例的上下文示例吗?

javascript node.js express firebase google-cloud-functions

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

Android架构组件:房间:没有这样的表格

我正在尝试使用新的Architecture组件,但是当我尝试运行时,我得到:

"错误:(375,24)错误:查询有问题:[SQLITE_ERROR] SQL错误或缺少数据库(没有这样的表:帖子)"

以下是我的课程.

**实体 :**

@Entity
    public static class Post {
        @PrimaryKey
        private String id;

        @ColumnInfo(name = "data")
        private String data;

        public String getId() {
            return id;
        }

        public void setData(String data) {
            this.data = data;
        }

        public String getData() {
            return data;
        }

        public void setId(String id) {
            this.id = id;
        }
    }
Run Code Online (Sandbox Code Playgroud)

DAO:

    @Dao
    public interface PostDao {
        @Query("SELECT * FROM posts")
        LiveData<List<Post>> getAll();

        @Insert
        void insertAll(Post... posts);

        @Insert
        void insert(Post post);

        @Delete
        void delete(Post post);
    } …
Run Code Online (Sandbox Code Playgroud)

java android android-architecture-components

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

如何在新的Android架构组件中正确使用Dagger2

我正在尝试使用新的架构组件,但我还是匕首的新手,而且我缺少了东西.

使用下面的代码,我得到一个NullPointerException,找不到位置.如果还有其他我需要修复或改进的地方,请建议.

代码: ViewModel

public class PostsVM extends ViewModel {
    private LiveData<StoryPost> post;
    private Repository          repository;

    @Inject
    public PostsVM(Repository repository) {
        this.repository = repository;
    }

    public void init() {
        if (this.post != null) {
            return;
        }
        post = repository.getPosts();
    }

    public LiveData<StoryPost> getPost() {
        return post;
    }
}
Run Code Online (Sandbox Code Playgroud)

知识库

@Singleton
public class Repository {
    private final MutableLiveData<StoryPost> data = new MutableLiveData<>();

    public LiveData<StoryPost> getPosts() {
        //
        new GetUser(post.getUid()) {
            @Override
            public void onSuccess(@NonNull User user) {
                // this is where …
Run Code Online (Sandbox Code Playgroud)

java android model-view dagger-2 android-architecture-components

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

Angular4:如何通过路由器添加的子节点将数据从父节点传递给子节点

继续这个问题Angular 4 ^:如何让一个组件的多个子组件与每个子组件定位其自己的路由器插座,我可以将一些子组件注入多个父组件,现在我想从那些组件中传递数据父母,异步,对孩子.试过@Input,似乎无法获胜.

儿童

export class UserheaderComponent implements OnInit, AfterViewInit, OnChanges {
  loading;
  @Input() data;
  user = {
    name: '______________',
    icon: '',
    username: '_________',
    uid: '________'
  };
  constructor(private router: Router) {
  }

  goToUser(uid) {
    this.router.navigate(['user'], { queryParams: { uid: uid } });
  }

  ngOnInit() {
    this.user = this.data;
    console.log(this.data);
  }

  ngAfterViewInit() {
    console.log(this.data);
  }

  ngOnChanges(changes: SimpleChanges) {
    console.log(changes);
  }
}
Run Code Online (Sandbox Code Playgroud)

家长Html

  <router-outlet name='userprofile-userhead' [data]="currentUser"></router-outlet>
Run Code Online (Sandbox Code Playgroud)

家长TS

export class UserprofileComponent {
  public currentUser;

  constructor(
    private userFactory: UserFactory,
    private router: Router, …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

Dagger singleton每次创建新实例

我有一个模块如下.

@Module
public class AppModule {
    private final Application app;

    public AppModule(Application app) {
        this.app = app;
    }

    @Provides
    @Architecture.ApplicationContext
    Context provideContext() {
        return app;
    }

    @Provides //scope is not necessary for parameters stored within the module
    public Context context() {
        return provideContext();
    }

    @Singleton
    @Provides
    Application provideApp() {
        return app;
    }

    @Singleton
    @Provides
    SoundsRepository provideSoundsRepository(Context context, SoundsDAO soundsDAO) {
        return new SoundsRepository(context, soundsDAO);
    }
}
Run Code Online (Sandbox Code Playgroud)

像这样的组件.

@Singleton
@Component(modules = AppModule.class)
public interface AppComponent {

    void inject(Global global);

    void inject(MainActivity …
Run Code Online (Sandbox Code Playgroud)

java android dependency-injection dagger-2

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

Google Play 商店:如何上传更多 APK 以支持不同的 CPU 架构

我想为每个 APK 支持不同的 CPU 架构(例如 ARM、x86 和 MIPS)。如何上传更多 APK,我已切换到高级模式,但将新 APK 上传到 Alpha按钮替换了之前的 APK。

附件是我的控制台在 APK 部分的外观。

在此处输入图片说明

将感谢您的帮助。

供参考,这是我的 gradle :

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "app_id_here"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        jackOptions {
            enabled false
            additionalParameters('jack.incremental': 'true')
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        javaMaxHeapSize '4096m'
    }

    splits {
        abi {
            enable true
            reset()
            include 'x86', 'x86_64', 'arm64-v8a', 'armeabi-v7a', 'armeabi'
            universalApk …
Run Code Online (Sandbox Code Playgroud)

android google-play google-play-developer-api

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