Skip to content
cpritchard edited this page Jul 3, 2014 · 27 revisions

Project Setup

  1. Download the Yerdy Unity package and import it into your Unity project:

    1. Open your Unity project
    2. AssetsImport PackageCustom Package...
    3. Navigate to and select the Yerdy .unitypackage you downloaded
    4. Click Import
  2. On application start, call Yerdy.Init() with your publisher key from one of your scripts:

    Yerdy.Init("<your publisher key>");
    

    NOTE: You can find your publisher key in the Yerdy dashboard on the Account Settings page under Company Details.

  3. If your app supports Android, follow the Android-specific instructions below.

  4. Build and run your app so it can register itself with the Yerdy servers.

  5. Navigate to the Manage page in the Yerdy dashboard to approve your app.

    NOTE: You'll need to repeat steps 4 and 5 for each platform your app runs on.

    NOTE: By default Yerdy logs warnings and errors to the console. You can change this via Yerdy.SetLogLevel(LogLevel level). YRDLogLevel.YRDLogSilent or YRDLogLevel.YRDLogError are recommended for release.

Android Setup

Overriding the Default Manifest

You need to make modifications to the AndroidManifest.xml file in Unity. To use a custom manifest you need to modify the file located at Assets\Plugins\Android\AndroidManifest.xml, if it doesn't it can be copied from [UnityPath]\Editor\Data\PlaybackEngines\androidplayer.

A copy of the needed modifications are included in the Yerdy Unity bundle in the Manifest.xml file, those changes are explained below.

Activities

Yerdy by default uses the Prime31 activity sharing plug-in for Unity compatibility. If you have already customized the AndroidManifest.xml and overwritten the default activities you can either convert your activity to the Prime31 format or call the Yerdy SDK directly from your custom activity.

Calling Yerdy Directly

To call Yerdy directly from your custom activity the following are needed in your activity.

@Override
protected void onDestroy() {
    super.onDestroy();
    Yerdy.getInstance().onDestroy();
}

@Override
protected void onResume() {
    super.onResume();
    Yerdy.getInstance().onResume(this);
}

@Override
protected void onPause() {
    super.onPause();
    Yerdy.getInstance().onPause();
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    YerdyUnity.onKeyDown(keyCode, event);
    return super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    YerdyUnity.onKeyUp(keyCode, event);
    return super.onKeyUp(keyCode, event);
}
	
@Override
public void onBackPressed() {
    YerdyUnity.onBackPressed();
    super.onBackPressed();
}
Using Prime31 Unity Android Activity Sharing

NOTE: If you need to convert your activity or want additional documentation there is extra information available for the Prime31 Unity Android Activity Sharing here.

Using the Prime31 activity sharing requires overriding the default Unity activity declaration in the manifest with the following activity declaration.

<manifest>
    <application>
        <activity android:name="com.prime31.UnityPlayerNativeActivity"
            android:label="@string/app_name"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

META-DATA

Add the following meta-data, service and receiver entries

<manifest>
    <application ...>
        <!--Configures the Prime31 Activity sharing to communicate with Yerdy-->
        <meta-data android:name="com.yerdy.services.YerdyUnity" android:value="UnityPlayerActivityProxy"/>

        <!--Services communicate with the Yerdy Servers-->
        <service android:name="com.yerdy.services.launch.YRDLaunchService"/>
        <service android:name="com.yerdy.services.messaging.YRDMessagingService"/>
        <service android:name="com.yerdy.services.messaging.YRDMessageReportService"/>
        <service android:name="com.yerdy.services.purchases.YRDReportIAPService"/>
        <service android:name="com.yerdy.services.purchases.YRDReportVirtualPurchaseService"/>
        <service android:name="com.yerdy.services.core.YRDCounterService"/>

        <!--Google GCM Support-->
        <receiver android:name="com.yerdy.services.push.gcm.GCMBroadcastRecieverEx"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <!-- Must match package on OS level 10-15 -->
                <category android:name="[YOUR_PACKAGE_NAME]" />
            </intent-filter>
        </receiver>
        <service android:name="com.yerdy.services.push.gcm.GCMIntentService" />
        <meta-data android:name="Yerdy_GCMSenderId" android:value="gcm:[YOUR_GCM_TOKEN]"/>

        <!--Amazon ADM Support-->
        <amazon:enable-feature android:name="com.amazon.device.messaging" android:required="false"/>
        <service android:name="com.yerdy.services.push.adm.ADMIntentService" android:exported="false" />
        <receiver android:name="com.yerdy.services.push.adm.ADMIntentService$ADMBroadcastReciever"
            android:permission="com.amazon.device.messaging.permission.SEND" >

            <!-- To interact with ADM, your app must listen for the following intents. -->
            <intent-filter>
                <action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
                <action android:name="com.amazon.device.messaging.intent.RECEIVE" />
                <!-- Replace the name in the category tag with your app's package name. -->
                <category android:name="[Your package name]" />
            </intent-filter>
        </receiver>

        <!--Yerdy Reciever-->	   
        <receiver android:name="com.yerdy.services.push.YRDLocalReceiver"/>
    </application>
</manifest>

Permissions

The following permissions are needed for full functionality

<manifest>
    <!-- General Permissions -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <!-- Google GCM Support -->
    <permission android:name="[YOUR_PACKAGE_NAME].permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="[YOUR_PACKAGE_NAME].permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!-- Amazon ADM Support -->
    <permission android:name="[Your Package Name].permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="[Your Package Name].permission.RECEIVE_ADM_MESSAGE" />
    <uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <!-- Messaging support -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.VIBRATE"/>

    <!-- Google LVL Validation -->
    <uses-permission android:name="com.android.vending.CHECK_LICENSE" />

    <application ...></application>
</manifest>

Amazon Namespace

You also need to add the Amazon XML namespace to the root manifest tag if your using Amazon Device Messaging

<manifest ... xmlns:amazon="http://schemas.amazon.com/apk/res/android">