Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 9 Next »

Prerequisites

Step Summary

  1. Add the Initialization code.

  2. Add the wrapper/trigger (transitions or button clicks) into your app.

  3. Follow our ad format guides for their implementation.

  4. Your app is now prepared for monetization with us.

We only mention how to create wrappers and not triggers because the way a trigger is fetch for its use is highly dependant on your specific app code.

Wrappers and Triggers/Events are used for different formats, each ad format page tells you what you need to use (wrapper or trigger) to display it.

Initialize the SDK

We require the SDK to be initialized only once as early as possible so for this purpose using Android’s application is recommended but if your app only has one activity, if using the activity make sure it is never destroyed unless killing the app or placing it in the background, matching then the lifecycle of Application, you can initialize it in onCreate method of that Activity.

Let’s see the recommended method.

Create an Application class and add it to the manifest code to start the app with the Application class.

class Application: Application()
{
    override fun onCreate()
    {
        super.onCreate()
        
		R89SDK.setDebug() //This is for testing purposes, remove it on prod
		R89SDK.setLogLevel(LogLevels.DEBUG) //This is for testing purposes, remove it on prod
		
		R89SDK.initialize(
			appContext = this,
			publisherId = "TestRefinery89ID", /* This is for testing purposes, change it on prod */
			appId = "TestDemoApp", /* This is for testing purposes, change it on prod */
			singleLine = false,
			initializationEvents = null
		)
    }
}

Your publisherId and appId will be provided to you during onboarding process by email, you can also retrieve them from the web interface after login.

This appID is not the same as the Manifest App Id you used in previous steps

Then add this application class to the manifest you already had from the Get Started.

The code for adding the application is the following

Remember that the ".Application" depends on the name of the class. If we named the class MyApplication we would need to put “.MyApplication"

<manifest>
    <application
        android:name=".Application">
    </application>
</manifest>

With this addition you full manifest should look like so:

This is a simplified example, you should have many more lines in the manifest, copy the important bits only.

<manifest>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
    
    <application
        android:name=".Application">
    
    <!-- This is the Sample App ID-->
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-3940256099942544~3347511713"/>
        
    </application>
</manifest>

Add wrappers to your Views

Wrappers are the container inside which the ads will show. You need to add as many as ad slots or ad places you desire.

We recommend you add the wrappers using XML Views, since it’s easier than creating them using code, so something like this:

# activity_main.xml
...
<LinearLayout
    android:id="@+id/ad_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true">
</LinearLayout>
...

and then fetch it in the code for the factory like so:

//Remember to use this Code only once since findViewById is an expensive method
val myWrapper = findViewById<ViewGroup>(R.id.myWrapper)

Follow our Ad Formats guides

How does it works?

We fetch all ad units configurations from our Database and you simply need to place the ad units using the RefineryAdFactory and the r89ConfigurationIDs we provide you. Incorporate them into the desired views.

Check Android - Ad Formats to see how each format is implemented.

  • No labels