2013-12-20 2 views
1

(영어로 실례합니다. 잘 말하지 않습니다.)휴대 전화가 꺼져있을 때 Android 브로드 캐스트 수신기

저는 Android에서 시작되었습니다. 따라서 Android 에뮬레이터를 사용하여 응용 프로그램을 테스트하기 만하면 콘솔에 전화기가 꺼져 있다는 메시지가 표시됩니다.

내가 만든 응용 프로그램은 에뮬레이터의 전원을 끌 때 아무 것도 표시하지 않습니다.

이유에 대해 설명해주세요. 매니페스트

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.anotherbroadcast" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="18" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.broadcastreceiver.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <receiver android:name="com.example.broadcastreceiver.MainActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.ACTION_SHUTDOWN" /> 
      </intent-filter> 
     </receiver> 
    </application> 

</manifest> 

클래스 홈페이지

public class MainActivity extends Activity { 

private BroadcastReceiver the_receiver = new BroadcastReceiver(){ 

    @Override 
    public void onReceive(Context c, Intent i) { 
       if(i.getAction().equals("android.intent.action.ACTION_SHUTDOWN")){ 
        System.out.println("the phone is switched off");  
       } 
    }}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
} 

답변

0

이동하여 BroadcastReceiver에 별도의 클래스에서

. 매니페스트에서 "com.example.broadcastreceiver.MainActivity"가 ActivityBroadcastReceiver이되도록 선언했으나 그렇지 않습니다. 그것은 단지 Activity입니다. 그리고 둘 다있을 수는 없습니다.

+0

+1 고맙습니다. :) – user3123469

관련 문제