2013-06-13 25 views

回答

0
  1. 創建廣播reciever

    public class Yourclass extends BroadcastReceiver { 
        @Override 
        public void onReceive(Context context, Intent intent) { 
         Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show(); 
        } 
    
    } 
    

2.註冊廣播reciever

您可以在清單或通過寫Context.registerReceiver() method.

登記本

下面是當應用程序被在定義的狀態調用onRecieve()方法來執行您需要採取的行動清單

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 

    <receiver android:name="MyReceiver"> 
     <intent-filter> 
     <action android:name="android.intent.action.BOOT_COMPLETED"> 
     </action> 
     </intent-filter> 
    </receiver> 

</application> 
  1. 的例子。