gpt4 book ai didi

android - 错误 : not an enclosing class: MainActivity

转载 作者:行者123 更新时间:2023-11-29 00:57:13 25 4
gpt4 key购买 nike

这是我收到错误的代码:错误:不是封闭类:MainActivity。请帮我看看我的代码有什么问题。

public class MyFirebaseMessagingSerivce extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN", s);
}

public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);

}
public void onCreate() {
super.onCreate();
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( MainActivity.this, new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult)
{
String updatedToken = instanceIdResult.getToken();
Log.e("Updated Token",updatedToken);

}
});
}

}

最佳答案

Can we use this one in FirebaseMessagingService?

FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener() 方法用于在 Activity 中获取 token

onNewToken() 方法用于在 FirebaseMessagingService 中获取 token

有关更多信息,请查看 Frank van Puffelen how onNewToken and FirebaseInstanceId.getInstance().getInstanceId() will work 的答案

同时检查 FirebaseMessagingService

示例代码

public class MainActivity extends AppCompatActivity {

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

FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( MainActivity.this, new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult)
{
String updatedToken = instanceIdResult.getToken();
Log.e("Updated Token",updatedToken);

}
});


}

}

关于android - 错误 : not an enclosing class: MainActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53773833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com