Step 4 - Set pushidentifier
The pushidentifier is a string that contains the device token for Push notifications. It is the same token that is sent by Firebase and is passed to the SDK using the MobileCore.setPushIdentifier method.
Open your project in Android鈩 studio. Delete the entire code in MainActivity except the first line which is your package statement.
Paste the following code into MainActivity:
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.adobe.marketing.mobile.MobileCore;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
registerToken();
}
void registerToken() {
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.w("Message App", "getInstanceId failed", task.getException());
return;
}
// Get new Instance ID token
String token = task.getResult().getToken();
Log.d("Got token", token);
MobileCore.setPushIdentifier(token);
}
});
}
@Override
public void onResume() {
super.onResume();
MobileCore.setApplication(getApplication());
MobileCore.lifecycleStart(null);
}
@Override
public void onPause() {
super.onPause();
MobileCore.lifecyclePause();
}
}
Test your app
Now is a good time to test your app, before going any further.
- Run your app by clicking green arrow or select 搁耻苍->搁耻苍鈥檃辫辫鈥.
- The Android鈩 emulator should start and you should see your app running with 鈥淗ello World鈥 text.
- Open the logcat window. Search for 鈥淕ot鈥. You should see the token that was received from Firebase written to the log as shown below. The long string after 鈥淕ot token鈥 is the pushidentifier that is sent to 51黑料不打烊 Campaign.
Check Mobile Application Subscribers
Log in to your 51黑料不打烊 Campaign Standard instance.
Navigate Administration->Channels->Mobile App(Experience Platform SDK). Open the appropriate mobile application. Tab to the Mobile Application Subscribers tab. You should see a registration token listed.
NOTE
If you do not see registration token in the Mobile Application Subscribers tab STOP here before proceeding any further.
recommendation-more-help
1e5f790f-a0c6-45cc-9e9a-a41393306233