Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by abhinandand91 · May 05, 2016 at 01:49 PM · unity 5pluginplugins

Why Android App-Indexing feature not works in Unity project when import it as a plugin.?

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 MainActivity extends UnityPlayerActivity { private static MainActivity sInstance; private GoogleApiClient mClient; private String mUrl; private String mTitle; private String mDescription;

 public static MainActivity GetInstance()
 {
     if(sInstance == null)
     {
         sInstance = new MainActivity();
     }
     return sInstance;
 }


 public int initFromUnity ()
 {
     return  15;
 }

 public void OnCreateCall(Activity currentActivity)
 {
     mUrl ="android-app://com.MyGames.firstgame/https/play.google.com/store/apps/";
     mTitle = "Master 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(MainActivity.class.getName(),"App Indexing API Recorded page"+ mTitle +"view successfully.");
                 }
                 else
                 {
                     Log.e(MainActivity.class.getName(),"App Indexing API: There was an error recording the page view."+status.toString());
                 }
             }
         });
     }

     public void  OnStopCall()
     {
         AppIndex.AppIndexApi.end(mClient, getAction());
         PendingResult<Status> result = AppIndex.AppIndexApi.end(mClient,getAction());
         mClient.disconnect();
         result.setResultCallback(new ResultCallback<Status>()
         {
             @Override
             public void onResult(@NonNull Status status)
             {
                 if (status.isSuccess())
                 {
                     Log.d(MainActivity.class.getName(), "App Indexing API Recorded page " + mTitle + " view end successfully.");
                 }
                 else
                 {
                     Log.e(MainActivity.class.getName(), "App Indexing API: There was an error recording the page view." + status.toString());
                 }

             }
         });
     }


=========================================================== public class AndroidEnableAppIndexing : MonoBehaviour { AndroidJavaObject mAppIndexingActivity; AndroidJavaObject mCurrentActivity; AndroidJavaClass appIndexingClass;

 void Awake ()
 {

     Debug.Log ("In Awake");
     #if !UNITY_EDITOR

     AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");

     mCurrentActivity = unity.GetStatic<AndroidJavaObject> ("currentActivity");

     appIndexingClass = new AndroidJavaClass ("com.MyGames.firstgame.MainActivity");

     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
 }

}

==================================================== In Unity project deep linking is working properly ,, but when i include the Jar File and try to access the methods from Jar file it shows the error No such method found as follows.. alt text

One more observation is when i Comment the methods OnCreateCall(), OnStartCall,OnStopCall() ,which include google client API's "initFromUnity" method is called successfully .. do i need to add any class in unity project related to AppIndexing in a way that it should connect to the google client and work properly in Game.

screen-shot-2016-05-04-at-125242-pm.png (43.7 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image abhinandand91 · May 05, 2016 at 01:53 PM 0
Share

"Only after including the Google client related API's is shows AndroidJavaException no such static method .. When i Comment them i can call all the methods from the plugins properly."

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ricardo_arango · May 19, 2016 at 11:12 PM

What the error is saying is that the static method MainActivity doesn't exist. You need to double check your code to see if there is an error. I just did a test like this:

 using UnityEngine;
 using System.Collections;
 public class NewBehaviourScript : MonoBehaviour {
     AndroidJavaObject mAppIndexingActivity;
     void Start () {
         Debug.Log ("Start");
         AndroidJavaClass appIndexingClass = new AndroidJavaClass ("com.unity3d.ProductName.AppIndexingActivity");
         Debug.Log ("appIndexingClass: " + appIndexingClass);
         mAppIndexingActivity = appIndexingClass.CallStatic<AndroidJavaObject> ("GetInstance");
         Debug.Log ("mAppIndexingActivity: " + mAppIndexingActivity);
     }
 }

And:

 package com.unity3d.ProductName;
 public class AppIndexingActivity {
     private static AppIndexingActivity sInstance;
     public static AppIndexingActivity GetInstance()
     {
         if(sInstance == null)
         {
             sInstance = new AppIndexingActivity();
         }
         return sInstance;
     }
 }

The method was found correctly.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aman1234 · Jul 04, 2016 at 11:16 AM 0
Share

Hi,

i am also trying to work on this and want to reach at best solution..Could you please let me know is there any plugin for this??? or any video so that i can find out the whole scenario of implementation..

thanks

avatar image Mebans · Nov 04, 2016 at 06:00 AM 0
Share

I tried this code but I want to open url. The following code does not work because the class is static.

private Intent myIntent;

Uri uri = Uri.parse("http://www.google.com"); myIntent= new Intent(Intent.ACTION_VIEW, uri); startActivity(myIntent);

Could you help?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

82 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

play services resolver error after installing GoogleMobileAds plugin 2 Answers

Problems sharing textures with plugin in Unity 5 0 Answers

Error on building "Unable to Find Plugins folder StandaloneWindows(64): Native VR plugins will not be loaded" 2 Answers

Unity Android Plugin onActivityResult not called 0 Answers

Native Plugin to get Users phone number 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges