2011-01-25 202 views

回答

8

定義你的廣播接收器:

private final BroadcastReceiver    receiver 
    = new BroadcastReceiver() { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     // Do something 
    } 
}; 

填寫您的接收器中的onResume:

@Override 
protected void onResume() { 
    super.onResume(); 

    IntentFilter filter = new IntentFilter(); 
    filter.addAction("SOME_ACTION"); 
    registerReceiver(receiver, filter); 
} 

註銷接收器的onPause:

@Override 
protected void onPause() { 
    super.onPause(); 

    unregisterReceiver(receiver); 
} 
+0

我應該付出的許可清單文件? – shyam 2012-04-25 05:04:06