-
Add the UserProfile library to your project using the app's gradle file.
-
Import the UserProfile library (and any other SDK library) in your application's main activity.
import com.adobe.marketing.mobile.*;
Required: The setApplication()
method must be called once in the onCreate()
method of your main activity. For more details, see Initial Configuration
-
The UserProfile extensions must be registered with the SDK core before calling any Target API.
This may be done after calling the
setApplication()
method in theonCreate()
method. Here is code sample which calls these setup methods:
public class MobileApp extends Application {
@Override
public void onCreate() {
super.onCreate();
MobileCore.setApplication(this);
try {
UserProfile.registerExtension();
} catch (Exception e) {
//Log the exception
}
}
}
Here are the public classes in the UserProfile extension:
Allows you to create/update a batch of user profile attributes:
- If the attribute does not exist, it will be created.
- If the attribute exists, the value will be updated.
- A null attribute value removes the attribute.
public static void updateUserAttribute(String attributeName,
Object attributeValue)
UserProfile.updateUserAttribute("username", "Will Smith");
Sets the user profile attributes key and value.
Allows you to create/update a batch of user profile attributes:
- String, Integer, Boolean, Double, Array, Map are valid type of user profile attributes.
- We do not allow custom objects to be saved as a
UserProfile
attribute. - If the attribute does not exist, it will be created.
- If the attribute already exists, then the value will be updated.
- A null attribute value will remove the attribute.
public static void updateUserAttributes(Map<String, Object> attributeMap)
HashMap<String, Object> profileMap = new HashMap<>();
profileMap.put("username","Will Smith");
profileMap.put("usertype","Actor");
UserProfile.updateUserAttributes(profileMap);
Removes the given attribute name.
public static void removeUserAttribute(String attributeName)
UserProfile.removeUserAttribute("itemsAddedToCart");