2017-02-20 6 views
-1

브로드 캐스트 리시버가 연결 변경을 위해 작동하지만 안드로이드 N에서 작동하지 않는 모든 장치에서 제대로 작동하지만 안드로이드 N에서 작동하지 않습니다. N에있는 것 또는 아닙니다. 왜 이런 일이 일어나는 지 아는 사람이 있습니까?Netwakeork 브로드 캐스트 리시버가 안드로이드 N에서 작동하지 않음 N

매니페스트 파일

다음
<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.admin.movies"> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<application 
    android:name=".MovieSingleton" 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".SplashActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <receiver 
     android:name=".NetworkBroadcastReceiver" 
     android:exported="false" 
     android:enabled="true"> 
     <intent-filter> 
      <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> 
     </intent-filter> 
    </receiver> 
</application> 

내 방송 수신기

public class NetworkBroadcastReceiver extends BroadcastReceiver { 

private static final String TAG = NetworkBroadcastReceiver.class.getSimpleName(); 

public NetworkBroadcastReceiver() { 

} 

@Override 
public void onReceive(Context context, Intent intent) { 
    Log.d(TAG, "onReceive: network change"); 
    if(isOnline(context)){ 
     Log.d(TAG, "onReceive: connected"); 
    } else { 
     Log.d(TAG, "onReceive: not connected"); 
    } 
} 


public boolean isOnline(Context mContext) { 
    ConnectivityManager connMgr = (ConnectivityManager) 
      mContext.getSystemService(Context.CONNECTIVITY_SERVICE); 
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); 
    return (networkInfo != null && networkInfo.isConnected()); 
} 

}

+2

https://developer.android.com/topic/performance/background-optimization.html 및 https://developer.android.com/about/versions/nougat/android-7.0-changes.html#bg-opt – CommonsWare

답변

0

많은 앱이 브로드 캐스트를 수신 등록하기 때문에, 하나의 네트워크 스위치 수있다 그들 모두가 깨어나게해라. p 방송을 한 번에 처리합니다.

Android Nougat에서는 BroadcastReceiver를 Context.registerReceiver()에 등록해야합니다.

이 변경 사항은 Android 7.0 백그라운드 최적화 및 성능 향상의 일부입니다.