Skip to content

Change the way to achieve token while init the app #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 17, 2021
2 changes: 2 additions & 0 deletions messaging/integration_test/src/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ TEST_F(FirebaseMessagingTest, TestReceiveToken) {

EXPECT_TRUE(RequestPermission());

EXPECT_TRUE(::firebase::messaging::IsTokenRegistrationOnInitEnabled());

FLAKY_TEST_SECTION_BEGIN();

EXPECT_TRUE(WaitForToken());
Expand Down
20 changes: 6 additions & 14 deletions messaging/src/android/cpp/messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -713,21 +713,13 @@ void Terminate() {
static void InstallationsGetToken() {
FIREBASE_ASSERT_MESSAGE_RETURN_VOID(internal::IsInitialized(),
kMessagingNotInitializedError);
JNIEnv* env = g_app->GetJNIEnv();

// Intent intent = new Intent(this, RegistrationIntentService.class);
jobject new_intent = env->NewObject(
util::intent::GetClass(),
util::intent::GetMethodId(util::intent::kConstructor), g_app->activity(),
registration_intent_service::GetClass());
Future<std::string> result = GetToken();

// startService(intent);
jobject component_name = env->CallObjectMethod(
g_app->activity(),
util::context::GetMethodId(util::context::kStartService), new_intent);
assert(env->ExceptionCheck() == false);
env->DeleteLocalRef(component_name);
env->DeleteLocalRef(new_intent);
result.OnCompletion(
[](const Future<std::string>& result, void* voidptr) {
NotifyListenerOnTokenReceived(result.result()->c_str());
},
nullptr);
}

static void SubscriptionUpdateComplete(JNIEnv* env, jobject result,
Expand Down