알람 설정으로 10초마다 호출하는 부분까지는 완성 되었는데.. 이 파일안에서 뭐좀 하려니 모두 안되네요; ㅠㅠ

폰번호또는 기기 고유 ID 를 가져와서 로그로 찍으려니 안되네요..ㅠㅠ

 

엑티비티에서 폰번호 가져오는 부분 설정하고 하면 잘 되는데..

꼭 다른 .java 파일에서는 안됩니다.

 

아래 public class GatewayToMain extends MainActivity 라고 선언하면 메인엑티비티쪽에 작성된

함수을 현재 페이지에서 호출은 되는데 import 되어 있는 기능들이 동작하지 않는 이유를 모르겠네요.

 

직접 메인엑티비티에 작성하고 메인엑티비티에서 실행하면 잘 되는데 꼭 다른 파일(class) 에서는 안되니 ㅠㅠ

메인엑티비티의 함수들을 다른 클래스에서 쉽게 불러와서 바로 사용 할 수 없는건가요?

 

자바가 처음이고 android 개발 2주차인지라...... 개념이 확실하게 잡히지 않은 초보인지라.. 도움 부탁드려요ㅠㅠ

 

 

--------------------------------------------------------------------------------------------------------------------------------------------------

package goldrgom.mytest;

 

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;


public class AlarmService_Service extends BroadcastReceiver {
 
 GatewayToMain gatewayClass = new GatewayToMain();
 

//-> 알람설정으로 10초마다 호출
 public void onReceive(Context context, Intent intent) {     

  String phoneNum;
  phoneNum = gatewayClass.getPhoneNumbers(); 
  Log.d("test", phoneNum);  
 }
 
 public class GatewayToMain extends MainActivity {
     //-> 전화번호 가져오기
     public String getPhoneNumbers() {
      TelephonyManager phoneNumber = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
      return phoneNumber.getLine1Number();
     }  
 }
}

 

11-20 07:56:21.590: D/AndroidRuntime(3982): Shutting down VM
11-20 07:56:21.590: W/dalvikvm(3982): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
11-20 07:56:21.600: E/AndroidRuntime(3982): FATAL EXCEPTION: main
11-20 07:56:21.600: E/AndroidRuntime(3982): java.lang.RuntimeException: Unable to start receiver goldrgom.mytest.AlarmService_Service: java.lang.IllegalStateException: System services not available to Activities before onCreate()
11-20 07:56:21.600: E/AndroidRuntime(3982):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2236)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at android.app.ActivityThread.access$1500(ActivityThread.java:130)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at android.os.Looper.loop(Looper.java:137)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at android.app.ActivityThread.main(ActivityThread.java:4745)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at java.lang.reflect.Method.invokeNative(Native Method)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at java.lang.reflect.Method.invoke(Method.java:511)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at dalvik.system.NativeStart.main(Native Method)
11-20 07:56:21.600: E/AndroidRuntime(3982): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
11-20 07:56:21.600: E/AndroidRuntime(3982):  at android.app.Activity.getSystemService(Activity.java:4410)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at goldrgom.mytest.AlarmService_Service$GatewayToMain.getPhoneNumbers(AlarmService_Service.java:26)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at goldrgom.mytest.AlarmService_Service.onReceive(AlarmService_Service.java:19)
11-20 07:56:21.600: E/AndroidRuntime(3982):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2229)
11-20 07:56:21.600: E/AndroidRuntime(3982):  ... 10 more
11-20 07:56:21.600: D/dalvikvm(3968): GC_FOR_ALLOC freed 72K, 9% free 5289K/5763K, paused 61ms, total 68ms
11-20 07:56:21.610: I/dalvikvm-heap(3968): Grow heap (frag case) to 6.011MB for 590096-byte allocation
11-20 07:56:21.670: D/dalvikvm(3968): GC_CONCURRENT freed 1K, 9% free 5864K/6407K, paused 14ms+4ms, total 60ms
11-20 07:56:22.400: I/Choreographer(3968): Skipped 50 frames!  The application may be doing too much work on its main thread.
11-20 07:56:22.431: D/gralloc_goldfish(3968): Emulator without GPU emulation detected.
11-20 07:56:23.536: I/Choreographer(3968): Skipped 72 frames!  The application may be doing too much work on its main thread.
11-20 07:56:24.881: I/Choreographer(3968): Skipped 110 frames!  The application may be doing too much work on its main thread.
11-20 07:56:24.940: I/Choreographer(3968): Skipped 32 frames!  The application may be doing too much work on its main thread.