# Android: Access system APIs (not sensors) with Processing. "Cannot make a static reference to a non static method. " 

**URL:** <https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732>\
**Category:** Processing for Android\
**Created:** [May 11, 2020, 3:36am UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732 "2020-05-11T03:36:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evlmnkey](https://avatars.discourse-cdn.com/v4/letter/e/aeb1de/32.png) [@Evlmnkey](https://discourse.processing.org/u/Evlmnkey)\
**Post date:** [May 11, 2020, 3:36am UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/1 "2020-05-11T03:36:26Z")

</div>

Hey guys, so im pretty confident with regular processing but this java-Android stuff is killing me. Here is my problem:

I want the result of this API: [https://developer.android.com/reference/android/telephony/CellSignalStrengthLte](https://developer.android.com/reference/android/telephony/CellSignalStrengthLte) , specifically the getDbm() method.

I read a lot, even bought an eBook, but all examples I found only read sensors. They then include a lot of objects like listeners, managers etc. I tried to find those for android.telephony but no real success.

I know this could be solved by “learning java” but I really only need this one thing. Any help?

The (to me) obvious but wrong import android.content.Context; import android.telephony.TelephonyManager; import android.telephony.CellSignalStrengthLte;

and then: var = CellSignalStrengthLte.getDbm(); fails with cannot make a static reference to a non static method.

Any help would be fantastic!

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [May 11, 2020, 6:59am UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/2 "2020-05-11T06:59:48Z")

</div>

Could you post the code you managed until now?

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [May 11, 2020, 9:30am UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/3 "2020-05-11T09:30:59Z")

</div>

@Evlmnkey === your error has nothing to see with android; very classical java stuff!

---

<div class="post-metadata">

**Author:** ![Evlmnkey](https://avatars.discourse-cdn.com/v4/letter/e/aeb1de/32.png) [@Evlmnkey](https://discourse.processing.org/u/Evlmnkey)\
**Post date:** [May 11, 2020, 10:22am UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/4 "2020-05-11T10:22:56Z")

</div>

Its totally a Java problem, I know. Unfortuately I only really need this one nugget and would be fine otherwise. Don’t have the time to learn java from the ground up for that. So This:

```auto
import android.content.Context;
import android.telephony.TelephonyManager;
import android.telephony.CellSignalStrengthLte;

Context context;
CellSignalStrengthLte foo;

int myResult;

void setup() {
  fullScreen();
  context = getActivity(); 
}

void draw() {
  background(0);
   myResult = foo.getDbm();
    text(str(myResult), 0, 0, width, height);
}

```

crashes with a NullPointerException: java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.telephony.CellSignalStrengthLte.getDbm()’ on a null object reference

I am pretty sure I need to initialize “foo” somehow but how? And where would I find out on the page I linked with all the android APIs?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [May 11, 2020, 11:05am UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/5 "2020-05-11T11:05:29Z")

</div>

Activity and context are different things

```auto
import android.app.Activity;
import android.content.Context;

Activity act;
Context cnxt;

void setup() {
  act = this.getActivity();
 cnxt = act.getApplicationContext();
}

```

---

<div class="post-metadata">

**Author:** ![Evlmnkey](https://avatars.discourse-cdn.com/v4/letter/e/aeb1de/32.png) [@Evlmnkey](https://discourse.processing.org/u/Evlmnkey)\
**Post date:** [May 11, 2020, 11:56am UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/6 "2020-05-11T11:56:07Z")

</div>

I see, I played around with that a bit but don’t really see how that is relevant to my problem.

I just need to read the output of the getSignalStrengthLte.getDbm() method into a variable. How can I do that in processing?

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [May 11, 2020, 3:07pm UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/7 "2020-05-11T15:07:04Z")

</div>

@Evlmnkey ===

- The error you put is note the same as the first one…
- you have to create an instance of TelephonyManager, then see code below (from yours, without trying to modify)
- dont forget to ask permissions on runtime

```auto

import android.Manifest;///for asking permissions run time
import android.telephony.CellInfo;
import java.util.List;
import android.telephony.CellInfoLte;
import android.telephony.CellSignalStrengthLte;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;///for knowing wether your phone is running more than //LollyPop
import android.telephony.TelephonyManager;

Context context;
CellSignalStrengthLte foo;
TelephonyManager telephonyManager;
Activity act;
int myResult;
int MyVersion = Build.VERSION.SDK_INT;

void setup() {
  fullScreen();
  act = this.getActivity();
  context = getActivity().getApplicationContext();
  if (MyVersion > Build.VERSION_CODES.LOLLIPOP_MR1) {
                //here ask for permissions on runtime (access coarse location && read phone state)
};

   telephonyManager = (TelephonyManager) act.getSystemService(Context.TELEPHONY_SERVICE);//get instance of TelephonyManager
   
   List<CellInfo> cellInfoList = telephonyManager.getAllCellInfo();//create a list for all infos about the phone cells

    for (final CellInfo info : cellInfoList) {
  
               println(info);

                if (info instanceof CellInfoLte) {//as you want to use Lte
                   foo = ((CellInfoLte) info).getCellSignalStrength();
                   println(foo);
                   myResult = foo.getDbm();//the value you are wanting to get
                     
                }
    }

};

void draw() {
  background(0);
   myResult = foo.getDbm();
    text(str(myResult), 0, 0, width, height);
};

```

---

<div class="post-metadata">

**Author:** ![Evlmnkey](https://avatars.discourse-cdn.com/v4/letter/e/aeb1de/32.png) [@Evlmnkey](https://discourse.processing.org/u/Evlmnkey)\
**Post date:** [May 11, 2020, 5:06pm UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/8 "2020-05-11T17:06:34Z")

</div>

Thanks so much! unfortunately, this whole permission thing keeps biting me.

This is what I did:

```auto
import android.Manifest;///for asking permissions run time
import android.telephony.CellInfo;
import java.util.List;
import android.telephony.CellInfoLte;
import android.telephony.CellSignalStrengthLte;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;///for knowing wether your phone is running more than //LollyPop
import android.telephony.TelephonyManager;

Context context;
CellSignalStrengthLte foo;
TelephonyManager telephonyManager;
Activity act;
int myResult;
int MyVersion = Build.VERSION.SDK_INT;

void setup() {
  fullScreen();
  act = this.getActivity();
  context = getActivity().getApplicationContext();
  if (MyVersion > Build.VERSION_CODES.LOLLIPOP_MR1) {
    requestPermission("android.permission.ACCESS_COARSE_LOCATION", "initLoc");
    requestPermission("android.permission.READ_PHONE_STATE", "initPS");
    requestPermission("android.permission.ACCESS_NETWORK_STATE", "initNW");

                //here ask for permissions on runtime (access coarse location && read phone state)
};

   telephonyManager = (TelephonyManager) act.getSystemService(Context.TELEPHONY_SERVICE);//get instance of TelephonyManager
   
   List<CellInfo> cellInfoList = telephonyManager.getAllCellInfo();//create a list for all infos about the phone cells

    for (final CellInfo info : cellInfoList) {
  
               println(info);

                if (info instanceof CellInfoLte) {//as you want to use Lte
                   foo = ((CellInfoLte) info).getCellSignalStrength();
                   println(foo);
                   myResult = foo.getDbm();//the value you are wanting to get                
                }
    }
};

void draw() {
  background(0);
   myResult = foo.getDbm();
    println(myResult);
};

void initLoc(boolean granted) {
  if (granted) {   
    println("init location manager");
  } else {
    println("location is not available");
exit();
  }
}
void initPS(boolean granted) {
  if (granted) {   
    println("Phonestate Granted");
  } else {
    println("Phonestate not granted");
exit();
  }
}

void initNW(boolean granted) {
  if (granted) {   
    println("NW Granted");
  } else {
    println("NW not granted");
   exit();
  }
}

```

I added both permissions you said I would need, (and toyed around with some others like “network state”, but the app keeps crashing on launch with:  
“FATAL EXCEPTION: Animation Thread  
Process: processing.test.sketch\_200511b, PID: 16376  
java.lang.SecurityException: Not allowed to access cell info”

**Without ever asking for any permission**  
Is there a syntax/unterstanding-problem? I thought the permission-line would call the specified function, which then just runs through and the code continues. What is wrong with that line of thinking?

Again, thanks so much for your help! I realize this is pretty far on the “LMGTFY”-side of questions but I really tried and this whole Android/Java-Lingo is just massively confusing if you’re not used to it.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [May 11, 2020, 5:09pm UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/9 "2020-05-11T17:09:49Z")

</div>

@Evlmnkey == ok; that is a way to ask “pernicious permissions” ( not the best but…) - and so, whap happens (about your previous and changed errors)-  
I f it works (i am not sure!) put answered for others…

---

<div class="post-metadata">

**Author:** ![Evlmnkey](https://avatars.discourse-cdn.com/v4/letter/e/aeb1de/32.png) [@Evlmnkey](https://discourse.processing.org/u/Evlmnkey)\
**Post date:** [May 11, 2020, 5:12pm UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/10 "2020-05-11T17:12:44Z")

</div>

No it does not work. I misformatted my post and you were so quick, sorry. Explanation at the bottom. The app crashes with missing permissions on startup (but never asks).

Any ideas for me to try?

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [May 11, 2020, 5:15pm UTC](https://discourse.processing.org/t/android-access-system-apis-not-sensors-with-processing-cannot-make-a-static-reference-to-a-non-static-method/20732/11 "2020-05-11T17:15:57Z")

</div>

@Evlmnkey=== yes, i have posted here a lot of times “how to get permissions” on runtime—try to look (and dont forget that the first time you are launching the app it will ask you ‘do you accept?’)
