-2

How can i solve the this problem? I don't see System.out.println I want to see System.out.println ethe of in. I see error in logcat. My codes are in the external java class.

My codes are here:

package com.example.test;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class bilgiCek extends AppCompatActivity {
    public static void telefonBilgi(){
        TelephonyManager bilgiler = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); // Error is here.

        String simUlke = bilgiler.getSimCountryIso();
        String netUlke = bilgiler.getNetworkCountryIso();
        String imei = bilgiler.getImei();
        String simNo = bilgiler.getSimSerialNumber();
        String sesMail = bilgiler.getVoiceMailNumber();
        System.out.println("İmei Numarası" + imei);
    }

}

Error outpu are here:

> Task :app:compileDebugJavaWithJavac FAILED
C:\Users\90505\AndroidStudioProjects\test\app\src\main\java\com\example\test\smsOkuma.java:16: error: non-static method getSystemService(String) cannot be referenced from a static context
        TelephonyManager bilgiler = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
                                                       ^
1 error

FAILURE: Build failed with an exception
Makyen
  • 31,849
  • 12
  • 86
  • 121
test3r123
  • 1
  • 2
  • Add this as a comment. – Prasanna Anbazhagan Jun 08 '20 at 02:14
  • Please don't make more work for others by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under a [CC BY-SA license](//creativecommons.org/licenses/by-sa/4.0), for SE to distribute the content (i.e. regardless of your future choices). By SE policy, the non-vandalized version is distributed. Thus, any vandalism will be reverted. Please see: [How does deleting work? …](//meta.stackexchange.com/q/5221). If permitted to delete, there's a "delete" button below the post, on the left, but it's only in browsers, not the mobile app. – Makyen Jun 08 '20 at 02:16

1 Answers1

0

add the non-stati context as parameter as below

  public static void telefonBilgi(Context context){
    TelephonyManager bilgiler = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
    String simUlke = bilgiler.getSimCountryIso();
    String netUlke = bilgiler.getNetworkCountryIso();
    String imei = bilgiler.getImei();
    String simNo = bilgiler.getSimSerialNumber();
    String sesMail = bilgiler.getVoiceMailNumber();
    System.out.println("İmei Numarası" + imei);
}

This might work