Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Regarding android java in c#

Discussion in 'Android' started by Ziron999, Sep 29, 2015.

  1. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    278
    How does one use these things in c#:

    PackageManager
    Intent
    Reflection (NOT System.Reflection)
    ConnectivityManager
    NetworkInfo

    i'm guess it would be a namespace like
    Code (CSharp):
    1. using android.blahblah
    I cannot find this information anywhere.
     
  2. 128bit

    128bit

    Joined:
    Oct 8, 2014
    Posts:
    117
    Unity does not expose any native android API. You need to create an native plugin for native android code.
    See for an example:
     
  3. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    278
    so there is no way to just do instead of "using blahblah;" to do a AndroidJavaClass ajc = new AndroidJavaClass("com.android.????");
     
  4. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    278
    here is more specific details:
    Code (CSharp):
    1. public void checkifonline()
    2.     {
    3.         bool haveConnectedWifi = false;
    4.         bool haveConnectedMobile = false;
    5.  
    6.         ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    7.         NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    8.         for (NetworkInfo ni : netInfo)
    9.         {
    10.             if (ni.getTypeName().equalsIgnoreCase("WIFI"))
    11.                 if (ni.isConnected())
    12.                     haveConnectedWifi = true;
    13.             if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
    14.                 if (ni.isConnected())
    15.                     haveConnectedMobile = true;
    16.         }
    17.  
    18.         if (haveConnectedWifi == false && haveConnectedMobile == false)
    19.         {
    20.  
    21.             // TODO (could make massage and than finish();
    22.         }
    23.     }
    has worked for people without doing things like that..how did they do it? it is public void so they did it in c# somehow