小编ria*_*fai的帖子

从系统托盘android firebase FCM中的通知中检索通知值

我正在使用firebase向我的应用发送通知.我想将每台设备上收到的通知保存在本地数据库中.问题是,当应用程序在后台并收到通知时,onMessageReceived()将不会调用该方法,而是根据文档将通知添加到系统托盘中.该文档还提到以下内容,以便在应用程序处于后台时收到通知:

在这些情况下,通知将传递到设备的系统托盘,并且数据有效负载将在启动器活动的附加内容中传递.

因此,当我尝试访问intent中的extras时,找不到通知的键.我的代码在MainActivity.java:

if (getIntent().getExtras() != null) {
        for (String key : getIntent().getExtras().keySet()) {
            Object value = getIntent().getExtras().get(key);
            Toast.makeText(this, "Key: " + key + " Value: " + value, Toast.LENGTH_LONG).show();
        }
    }
Run Code Online (Sandbox Code Playgroud)

我们从服务器发送的通知:

{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
  "body" : "great match!",
  "title" : "Portugal vs. Denmark",
  "icon" : "myicon"
  }
}
Run Code Online (Sandbox Code Playgroud)

任何人都知道如何检索通知中的值?

android android-intent firebase google-cloud-messaging firebase-cloud-messaging

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

Firebase getCurrentUser 在新的 android 活动中返回 null

登录活动:

private FirebaseAuth firebaseAuth;
private FirebaseAuth.AuthStateListener mAuthListener;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    firebaseAuth = FirebaseAuth.getInstance();

    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
                finish();
                startActivity(new Intent(LoginActivity.this, MainActivity.class));

            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

主要活动:

public  FirebaseAuth firebaseAuth;

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    firebaseAuth = …
Run Code Online (Sandbox Code Playgroud)

android android-intent firebase firebase-authentication

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

在两个片段之间添加侦听器

我有两个片段,假设A和B,其中B包含一个列表。我想在片段B上添加一个侦听器,以通知片段A所选列表项。我不知道如何在片段B中初始化侦听器,因为在片段的构造函数中传递参数是一种不好的做法。

注意:片段B包含在片段A中。即片段A中有一个FrameLayout;片段B覆盖了那个FrameLayout。

知道我该怎么做吗?

android listeners android-fragments android-recyclerview

3
推荐指数
2
解决办法
5106
查看次数

如果设备已经在Geofence android内部,则停止初始触发

我在android上使用Geofencing,当创建geo-fence时,如果用户已经在geo-fence中,设备会收到通知,这不是我正在寻找的行为,我只想通知转换ENTER和出口.

这就是我创建地理围栏请求的方式:

private GeofencingRequest createGeoFenceRequest(List<Geofence> geofenceList) {
        return new GeofencingRequest.Builder()

                //The INITIAL_TRIGGER_ENTER is used to notify the user initially if he/she/other
                //is already inside the geo-fence zone
                //.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)

                .addGeofences(geofenceList)
                .build();
    }
Run Code Online (Sandbox Code Playgroud)

在我的GeofenceTransitionService.java中:

@Override
protected void onHandleIntent(@Nullable Intent intent) {

    if (intent != null) {
        geofencingEvent = GeofencingEvent.fromIntent(intent);

        // Retrieve the transition type.
        geoFenceTransition = geofencingEvent.getGeofenceTransition();

    }
}
Run Code Online (Sandbox Code Playgroud)

过渡类型以Geofence.GEOFENCE_TRANSITION_ENTER的形式返回,即使我没有进入,我已经在地理围栏中了.任何人都知道如何阻止这个初始触发器?

android location geolocation geofencing android-geofence

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