|
|
| |
android.net.conn.CONNECTIVITY CHANGE |
|
|
|
8³â Àü |
¾Èµå·ÎÀ̵忡¼ ³×Æ®¿öÅ©°¡ ²÷°å´ÂÁö ½Ç½Ã°£À¸·Î ¾Ë¾Æº¸´Â ¹æ¹ýÀ¸·Î ¾Æ·¡¿Í °°ÀÌ »ç¿ëÇϽô ºÐµéµµ ÀÖÀ» °ÍÀÌ´Ù.
// Broadcast Listener µî·Ï (onCreate³ª onResume¿¡ ÇÒ´ç)
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
try{
registerReceiver(mNetworkStateReceiver, filter);
}catch (Exception e){
if (RingQConfig.DEBUG) e.printStackTrace();
}
// Broadcast Listener ÇØÁ¦ (onDestroy³ª onPause¿¡ ÇÒ´ç)
try {
if (mNetworkStateReceiver != null) unregisterReceiver(mNetworkStateReceiver);
} catch (IllegalArgumentException e) {
if (RingQConfig.DEBUG) e.printStackTrace();
}
// ¿©±â¿¡¼ ³×Æ®¿öÅ© »óŸ¦ üũ ÇÏ¸é µÈ´Ù.
BroadcastReceiver mNetworkStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// ³×Æ®¿öÅ© üũ
}
};
À§¿Í °°Àº ¹æ¹ýÀ¸·Î ÇÏ¸é µ¿ÀÛÀÌ Àß µÈ´Ù.
ÇÏÁö¸¸!!!!
±¸±Û¿¡¼ »õ·Î¿î N¹öÀüÀ» °³¹ß Çϸé¼, ¸î°¡Áö »ç¿ëÀ» ÁßÁöÇϱ⸦ ±ÇÀåÇÏ´Â ActionÀÌ ÀÖ´Ù.
ºê·Îµåij½ºÆ®¸¦ ¼ö½ÅÇϵµ·Ï ¸Å´ÏÆ佺Ʈ¿¡ µî·ÏµÇ¾î ÀÖ´õ¶óµµ, Preview¸¦ ´ë»óÀ¸·Î ÇÏ´Â ¾ÛÀºCONNECTIVITY_ACTION ºê·Îµåij½ºÆ®¸¦ ¼ö½ÅÇÏÁö ¾Ê½À´Ï´Ù. Æ÷±×¶ó¿îµå¿¡¼ ½ÇÇàµÇ´Â ¾ÛÀºContext.registerReceiver()·Î BroadcastReceiver¸¦ µî·ÏÇÏ¿© ¿©ÀüÈ÷ ¸ÞÀÎ ½º·¹µå¿¡¼CONNECTIVITY_CHANGE¸¦ ¼ö½ÅÇÒ ¼ö ÀÖ½À´Ï´Ù.
¾ÛÀº ACTION_NEW_PICTURE ¶Ç´Â ACTION_NEW_VIDEO ºê·Îµåij½ºÆ®¸¦ ¼Û¼ö½ÅÇÒ ¼ö ¾ø½À´Ï´Ù. ÀÌ ÃÖÀûÈ´Â Preview¸¦ ´ë»óÀ¸·Î ÇÏ´Â ¾Û »Ó¸¸ ¾Æ´Ï¶ó ¸ðµç ¾Û¿¡ ¿µÇâÀ» ¹ÌĨ´Ï´Ù.
Ãâó : https://developer.android.com/preview/features/background-optimization.html?hl=ko
µü º¸½Ã¸é ¾Æ½Ã°ÚÁö¸¸, CONNECTIVITY_CHANGE¸¦ »ç¿ëÇÏ¸é µÇ°Ú³×!
¶ó´Â ÇØ°áÃ¥ÀÌ ³ª¿É´Ï´Ù.
±×·³, CONNECTIVITY_CHANGE´Â ¾î¶»°Ô »ç¿ëÇÏ¸é µÉ±î¿ä?
// AndroidManifest.xml
<!-- Network -->
<receiver android:name=".receiver.NetworkChangeReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" >
</action>
</intent-filter>
</receiver>
À§¿Í °°ÀÌ AndroidManifest¿¡ BroadCastReceiver¸¦ µî·Ï ½ÃÅ°½Ã±¸¿ä.
package com.namuon.ringq.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class NetworkChangeReceiver extends BroadcastReceiver {
public static final String EVENT_NETWORK_CHAGED = "network_changed";
@Override
public void onReceive(final Context context, final Intent intent) {
// ¿©±â¿¡¼ ³×Æ®¿öÅ© »óŸ¦ üũ ÇÏ½Ã¸é µË´Ï´Ù.
// Âü°í·Î ¾Æ·¡¿Í °°ÀÌ ³×Æ®¿öÅ© »óÅ°¡ ¹Ù²¼À» ¶§, ·ÎÄà Brocast¸¦ ³¯·Á¼
// ȸ鿡 ¾Ë¸° ÈÄ, È¸é º°·Î ¾Ë¸Â°Ô Á¦¾î ÇÏ´Â °Íµµ ÁÁÀº ¹æ¹ý Àεí Çϳ׿ä.
Intent mIntent = new Intent(EVENT_NETWORK_CHAGED);
context.sendBroadcast(mIntent)
}
}
ÀÌ·¸°Ô »ç¿ëÇÏ¸é ¹®Á¦ ¾øÀÌ ³×Æ®¿öÅ© °ü¸®°¡ °¡´ÉÇÒ µí Çϳ׿ä.
Âü°íÇϼ¼¿ä. |
|
̵̧ : 274 |
̵̧
¸ñ·Ï
|
|
| |
|