저는 이것이 인기있는 주제라는 것을 알고 있지만, 제 경우에 해당하지 않습니다. 내 디자인에 모듈성을 얻으 려하면서 네트워크 상태 변경을 수신하고 (내 연결성을위한) 일반 게이트웨이 역할을하는 단일 브로드 캐스트 수신기를 만들었습니다. 이 클래스는 ConnectivityReceiver라고 그것은 기본적으로이이다 : 나는 매니페스트에 등록했다사용자 정의 BroadcastReceiver가 작동하지 않습니다.
public class ConnectivityReceiver extends BroadcastReceiver {
private static final String TAG = "ConnectivityReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG,"onReceive called");
Log.d(TAG,"Intent.getAction() is "+intent.getAction());
if(intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)){
Intent out = new Intent(MapFragment.ACTION_LOCAL_CONNECTIVITY_CHANGE);
Log.d(TAG,"Sending broadcast");
context.sendBroadcast(out);
}
}
}
와 꽤 잘 작동된다. 그럼, 연결 변경의 종류에 대해 알고 관심을 가질 것 조각을, 그래서는 다음과 같습니다 간단한 내부 브로드 캐스트 리시버 생성이 하나가 매니페스트에 등록되지 않은
public BroadcastReceiver connectivityReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG,"got connection info!");
}
};
,하지만 내가 그랬어 프래그먼트의 onCreate 메서드와 onDestroy 메서드에서 각각 등록하고 등록을 취소 할만큼주의해야합니다. 이런 식으로 뭔가 :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG,"onCreate");
connectivityReceiver = new ConnectivityReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(MapFragment.ACTION_LOCAL_CONNECTIVITY_CHANGE);
this.getActivity().registerReceiver(connectivityReceiver, intentFilter);
/* Creating a ParseHandler, this will be needed for the PathParser */
mParserHandler = new ParserHandler(getActivity());
}
및
@Override
public void onDestroy(){
Log.d(TAG,"onDestroy");
this.getActivity().unregisterReceiver(connectivityReceiver);
}
하지만 어떤 알 수없는 이유로 체인의 제 2 방송 수신기가 방송을받지입니다
! 처음 발행 된 것 (Manifest에 등록 된 것)이 발행되기 때문에 발행됩니다.아이디어가 있으십니까? 사용자 지정 작업의 이름은 다음과 같습니다
확인public static final String ACTION_LOCAL_CONNECTIVITY_CHANGE = "com.spiral.android.transito.CONNECTIVITY_CHANGE";