How To implement App-indexing feature in to Android Game. ?
Hi, Currently our team is trying to enable App indexing and Autocomplete features in my Android game , for that we created an Sample Android App and tried to implement the App indexing as well as deep-linking .
In Android app side it worked properly. we tested the deep linking with following link
https://developers.google.com/app-indexing/android/test#test-autocompletions
And we tested Autocomplete in App by following link
https://codelabs.developers.google.com/codelabs/app-indexing/#0
so Both works correctly on App side .. And i would like to specify that we have created an Android studio project with the same Package ID as our Unity Project .. Followed all the steps mentioned in Unity's Android Plugin Manual.
For More details i am Including My Java source code...
public class AppIndexingActivity extends UnityPlayerActivity // AppCompactActivity is used in Studio App side
{
private static AppIndexingActivity sInstance;
private GoogleApiClient mClient;
private String mUrl;
private String mTitle;
private String mDescription;
public static AppIndexingActivity GetInstance()
{
if(sInstance == null)
{
sInstance = new AppIndexingActivity();
}
return sInstance;
}
public int initFromUnity ()
{
return 15;
}
public void OnCreateCall(Activity currentActivity)
{
mUrl ="android-app://com.NNGames.starchef_android/https/play.google.com/store/apps/";
mTitle = "Star Chef";
mDescription = "Become a Master Chef and run your own restaurant";
mClient = new GoogleApiClient.Builder(currentActivity).addApi(AppIndex.API).build();
}
public Action getAction()
{
Thing object = new Thing.Builder()
.setName(mTitle)
.setDescription(mDescription)
.setUrl(Uri.parse(mUrl))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
public void OnStartCall()
{
mClient.connect();
PendingResult<Status> result = AppIndex.AppIndexApi.start(mClient,getAction());
result.setResultCallback(new ResultCallback<Status>()
{
@Override
public void onResult(@NonNull Status status)
{
if(status.isSuccess())
{
Log.d(AppIndexingActivity.class.getName(),"App Indexing API Recorded page"+ mTitle +"view successfully.");
}
else
{
Log.e(AppIndexingActivity.class.getName(),"App Indexing API: There was an error recording the page view."+status.toString());
}
}
});
}
My manifest file is as follows ..
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.NNGames.starchef_android">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:icon="@mipmap/ic_launcher"
android:supportsRtl="true">
<activity android:name=".AppIndexingActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="android-app">
</data>
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</application>
</manifest>
The way i am using the plugins.
using UnityEngine;
using System.Collections;
public class AndroidEnableAppIndexing : MonoBehaviour
{
AndroidJavaObject mAppIndexingActivity;
AndroidJavaObject mCurrentActivity;
void Awake ()
{
DontDestroyOnLoad(this.gameObject);
Debug.Log ("In Awake");
#if !UNITY_EDITOR
AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
mCurrentActivity = unity.GetStatic<AndroidJavaObject> ("currentActivity");
AndroidJavaClass appIndexingClass = new AndroidJavaClass ("com.NNGames.starchef_android.AppIndexingActivity");
mAppIndexingActivity = appIndexingClass.CallStatic<AndroidJavaObject> ("GetInstance");
mAppIndexingActivity.Call ("OnCreateCall",mCurrentActivity);
#endif
}
void Start()
{
Debug.Log ("In Start");
#if !UNITY_EDITOR
mAppIndexingActivity.Call ("OnStartCall");
#endif
}
void OnApplicationQuit()
{
Debug.Log("Application is going to quit.");
#if !UNITY_EDITOR
mAppIndexingActivity.Call ("OnStopCall");
#endif
}
}
I included the Jar file and the manifest file in to my Unity project. when i run my game and try to check logs i get an No such static method java language Exception. as follows .
Why is shows such behaviour when i include App indexing apis ?, When i comment the App indexing api's the plugin calls the method properly. Is there any other way to include App indexing Api's in to Unity Game app ?
Thank You.
Your answer
Follow this Question
Related Questions
Unity detect wrong androidSDK version 0 Answers
Android build problem 0 Answers
DLL found in editor but not in build version 2 Answers
CommandInvokationFailure: Gradle build failed. Unity Build 0 Answers