Android SDK Setup
To integrate AppsOnAir Android SDK to your Android native Apps with Java or Kotlin, follow the below steps
1. Basic Requirements for service usage
- Install or update Android Studio to its latest version.
- Make sure that your project meets these requirements:
- Targets API level 21 (LOLLIPOP) or higher
- Uses Android 5.0 or higher
- Requires Gradle version
7.0+
- Uses Jetpack (AndroidX), which includes meeting these version requirements:
compileSdkVersion
29 or later
- Set up a physical device or use an emulator to run your app.
- Create or login to your AppsOnAir (AoA) Account
- Goto the your app details page -> App services tab -> API key tab to get your AoA services API Key
2. Add AppsOnAir Gradle Plugin and SDK
When creating a new project from Android Studio Artic Fox (or newer) the allprojects{...} is no longer added in the project level gradle.so need add in settings.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
...
maven { url 'https://jitpack.io' }
}
}
android.useAndroidX=true
android.enableJetifier=true
2.1 open your root build.gradle file, add the following
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
2.2 Add the following to your dependencies section.
dependencies {
implementation 'com.github.apps-on-air:AppsOnAir-Android-SDK:Tag'
}
Make sure to press "Sync Now" on the banner that pops up after saving!
3. Add required code
Add meta-data to the app module's AndroidManifest.xml file under the application tag
<!-- add meta-data inside application tag -->
<application>
<!-- App icon for dialog -->
<meta-data
android:name="com.appsonair.icon"
android:resource="@drawable/app_icon" />
<!-- App name for dialog -->
<meta-data
android:name="com.appsonair.name"
android:value="app_name" />
</application>
4. Add the AppsOnAirServices Initialization code and usage
You can call initialization at your preferencehowever, we recommend that you add the initialization code in Main Launcher Activity(MainActivity.java) file onCreate
method as follows:
- Java
- Kotlin
import com.appsonair.AppsOnAirServices
public class MainActivity extends AppCompatActivity {
private static final String APPSONAIR_APP_ID = "########-####-####-####-############";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//AppsOnAirServices Initialization
AppsOnAirServices.setAppId(APPSONAIR_APP_ID, true);
}
}
import com.appsonair.AppsOnAirServices
class MainActivity : AppCompatActivity() {
private val APPSONAIR_APP_ID = "########-####-####-####-############"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//AppsOnAirServices Initialization
AppsOnAirServices.setAppId(APPSONAIR_APP_ID, true);
}
}
5. Set Custom UI (Optional step)
If you want to show a custom alert for app updates and maintenance dialogue then in the setAppId
initialization function, set the second parameter as false
. Now, call checkForAppUpdate
function to show a custom alert for app updates and maintenance dialogue to match your design requirements. To use this method where needed, use the same import statement as in the previous step. Use this method as follows:
- Java
- Kotlin
import com.appsonair.AppsOnAirServices;
import com.appsonair.UpdateCallBack;
public class MainActivity extends AppCompatActivity {
private static final String APPSONAIR_APP_ID = "########-####-####-####-############";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//AppsOnAirServices Initialization
AppsOnAirServices.setAppId(APPSONAIR_APP_ID, false);
AppsOnAirServices.checkForAppUpdate(MainActivity.this, new UpdateCallBack() {
@Override
public void onSuccess(String response) {
Log.d("response", ""+response);
// Do your code to show your custom UI.
}
@Override
public void onFailure(String message) {
Log.e("message", ""+message);
}
});
}
}
import com.appsonair.AppsOnAirServices;
import com.appsonair.UpdateCallBack;
class MainActivity : AppCompatActivity() {
private val APPSONAIR_APP_ID = "########-####-####-####-############"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//AppsOnAirServices Initialization
AppsOnAirServices.setAppId(APPSONAIR_APP_ID, false);
AppsOnAirServices.checkForAppUpdate(this, object : UpdateCallBack {
override fun onSuccess(response: String) {
Log.d("response", "" + response)
// Do your code to show your custom UI.
}
override fun onFailure(message: String) {
Log.e("message", "" + message)
}
});
}
}