Search Unity

How can unity interact with android natively?

Discussion in 'Scripting' started by DoomDude99, Jun 2, 2019.

  1. DoomDude99

    DoomDude99

    Joined:
    May 11, 2019
    Posts:
    54
    I'm trying to make a wallpaper and am at a loss as to how unity can interact with the android api and file system. After looking around, I found two plugins unity2eclipse (which is outdated (works for unity 3.4)) and uLiveWallpaper:

    https://assetstore.unity.com/packages/tools/integration/ulivewallpaper-indie-52110

    While these plugins may be helpful in creating wallpapers, I'm not sure how well they interface with the file system (I'll need to download config files and read them from the app).

    Is there any documentation on this topic?
     
  2. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    789
    DoomDude99 likes this.
  3. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    789
    Here is how I get the Android devices locale by calling Java code:

    Code (CSharp):
    1. private static string GetAndroidLocale()
    2. {
    3.     AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    4.     AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
    5.     AndroidJavaObject currentResources = currentActivity.Call<AndroidJavaObject>("getResources");
    6.     AndroidJavaObject currentConfiguration = currentResources.Call<AndroidJavaObject>("getConfiguration");
    7.     AndroidJavaObject currentLocale = currentConfiguration.Get<AndroidJavaObject>("locale");
    8.  
    9.     string javaCountry = currentLocale.Call<string>("getCountry");
    10.     string javaLanguage = currentLocale.Call<string>("getLanguage");
    11.  
    12.     return $"{javaLanguage}-{javaCountry}";
    13. }
    This is the equivalent of calling currentActivity.getResources().getConfiguration().locale.getCountry() / getLanguage() in Java.
     
    DoomDude99 likes this.