Мы постоянно публикуем обновления документации, которые могут быть недоступны на вашем языке. Наиболее актуальные сведения содержатся в версии на английском языке.
We're releasing a new version of our Android SDK. Want to get early access and try out the new features?
You can find:
Improved support for customers with super apps or separate BI systems
Added flexibility for retrieving adid information, higher limits on event deduplication, and improved caching and replaying of information from the SDK
Refined information on attribution callbacks, simplified debugging, and more intuitive method names
The Adjust Android SDK enables you to track attribution, events, and much more in your Android app. Follow the steps in this guide to set up your app to work with the Adjust SDK. You can also check out our example apps on GitHub.
To start using the Adjust SDK, you will need to add it to your project as a dependency.
Важно:
The minimum supported Android API level for the Adjust SDK integration is 9 (Gingerbread). The minimum supported Android API level for the web view extension is 17 (Jelly Bean).
Maven
Add the following to your build.gradle file:
dependencies {
implementation 'com.adjust.sdk:adjust-android:4.33.5'
implementation 'com.android.installreferrer:installreferrer:2.2'
// Add the following if you are using the Adjust SDK inside web views on your app
implementation 'com.adjust.sdk:adjust-android-webbridge:4.33.5'
}
Add as an archive
The Android SDK is available as an AAR archive and the web view SDK is available as a JAR. You can download these from our releases page.
Apps in the Google Play Store need to use the Google Advertising ID to identify devices. To enable the Google Advertising ID for our SDK, you need to integrate Google Play Services. To do this, add the Google Play Services library to your project. Add the following dependency to the dependencies section of your build.gradle file.
The App Set ID is available in Adjust SDK v4.33.5 and above.
The App Set Identifier is a unique identifier that enables you to measure information from any of your apps that a user has installed on their device. All apps by the same developer share the same App Set ID, meaning you can gather meaningful insights from users across all your apps. To record a device's App Set ID, you need to add the following permission to your build.gradle file:
If your app targets children, you should remove the AD_ID permission to prevent the Adjust SDK from reading it. See Set up apps for children for instructions.
The Adjust SDK requires the following permissions. Add them to your AndroidManifest.xml file if they are not already present:
The install referrer is a unique identifier which you can use to attribute an app install to a source. The Adjust SDK requires this information to perform attribution. There are 4 methods you can use to gather this information:
If you are using Proguard, make sure you have added the following setting in your Proguard file:
-keep public class com.android.installreferrer.** { *; }
INSTALL_REFERRER intent
If you are working with a store that supports the INSTALL_REFERRER intent, you can capture this with a broadcast receiver. Add the following receiver inside the application tag in your AndroidManifest.xml:
This receiver will retrieve the install referrer and pass it to the Adjust backend.
If you are using a different broadcast receiver, you will need to set it up to communicate with Adjust. Follow these instructions to enable communication with the Adjust broadcast receiver.
Huawei Referrer API
As of v4.21.1, the Adjust SDK supports install tracking on Huawei devices using Huawei App Gallery v10.4 and later. You do not need to make any changes to start using the Huawei Referrer API.
Meta referrer integration
The Adjust SDK supports the Meta Install Referrer in v4.36.0 and above. To enable this feature:
In your Application class, find or add the onCreate method. Add the following code to initialize the Adjust SDK:
import com.adjust.sdk.Adjust;
import com.adjust.sdk.AdjustConfig;
public class GlobalApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
String appToken = "{YourAppToken}";
String environment = AdjustConfig.ENVIRONMENT_SANDBOX;
AdjustConfig config = new AdjustConfig(this, appToken, environment);
Adjust.onCreate(config);
}
}
Совет:
You can find your app token in your Adjust dashboard.
Set the environment variable to either sandbox or production mode.
Важно:
When running tests you should ensure that your environment is set to AdjustConfig.ENVIRONMENT_SANDBOX. Change this to AdjustConfig.ENVIRONMENT_PRODUCTION before you submit your application to the App Store.
Before you start, you will need to obtain the reference to your WebView object. Once you have done this:
Call webView.getSettings().setJavaScriptEnabled(true) to enable Javascript in the web view.
Start the default instance of AdjustBridgeInstance by calling AdjustBridge.registerAndGetInstance(getApplication(), webview). This will register the Adjust bridge as a Javascript interface in the web view.
Call AdjustBridge.setWebView() to set a new WebView if needed.
Call AdjustBridge.unregister() to unregister the AdjustBridgeInstance and WebView.
Once you have completed these steps, your activity should look like this:
Add your references to the Javascript files. Use these in your HTML file to initialize the Adjust SDK:
let yourAppToken = '{YourAppToken}';
let environment = AdjustConfig.EnvironmentSandbox;
let adjustConfig = new AdjustConfig(yourAppToken, environment);
Adjust.onCreate(adjustConfig);
Совет:
You can find your app token in your Adjust dashboard.
Важно:
When running tests you should ensure that your environment is set to AdjustConfig.EnvironmentSandbox. Change this to AdjustConfig.EnvironmentProduction before you submit your application to the App Store.
let environment = AdjustConfig.EnvironmentSandbox;
let environment = AdjustConfig.EnvironmentProduction;
You need to set up session tracking so that the SDK can pass session information to the Adjust backend. Follow the instructions below to set this up in your app.
API level 14 and higher
Add a private class that implements the ActivityLifecycleCallbacks interface. If you don't have access to this interface, your app is targeting an Android API level lower than 14. You will have to update each activity by following the instructions below. If you have Adjust.onResume and Adjust.onPause calls on your app's activities, remove them.
Edit the onActivityResumed(Activity activity) method and add a call to Adjust.onResume(). Edit the onActivityPaused(Activity activity) method and add a call to Adjust.onPause().
Add the onCreate() method to your Adjust SDK configuration step. Call registerActivityLifecycleCallbacks with an instance of the created ActivityLifecycleCallbacks class:
import com.adjust.sdk.Adjust;
import com.adjust.sdk.AdjustConfig;
public class GlobalApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
String appToken = "{YourAppToken}";
String environment = AdjustConfig.ENVIRONMENT_SANDBOX;
AdjustConfig config = new AdjustConfig(this, appToken, environment);
Adjust.onCreate(config);
registerActivityLifecycleCallbacks(new AdjustLifecycleCallbacks());
}
private static final class AdjustLifecycleCallbacks implements ActivityLifecycleCallbacks {
@Override
public void onActivityResumed(Activity activity) {
Adjust.onResume();
}
@Override
public void onActivityPaused(Activity activity) {
Adjust.onPause();
}
//...
}
}
API level 9 to 13
If the minSdkVersion in your gradle file is between 9 and 13, consider changing it to 14 or above. This will simplify the integration process. Check the Android dashboard for information about the market share of major versions.
You need to call certain methods when pausing or resuming an
Activity. This is so that the Adjust SDK does not miss the start or end of a session. To do this, follow these steps for each Activity in your app:
In your Activity's onResume method, call Adjust.onResume(). Create the method if needed.
In your Activity's onPause method, call Adjust.onPause(). Create the method if needed.
After these steps, your activity should look like this:
Repeat these steps for each Activity in your app. Depending on your coding style, you might want to add this in a common superclass of all your activities.
Well done! You should now be able to build and run your app. Enable logging to check for any issues. You are ready to start attributing your users with the Adjust SDK.