2014-01-22 2 views
-1

나는 안드로이드에서 헤로인을 사용하여 채팅 응용 프로그램을 작업 중입니다. 알림 표시에 대한 질문이 있습니다. ListView에 로그인 한 후 상태가 친구 목록을 사용자에게 표시하고 있습니다. 이제는 다른 사용자의 채팅 횟수 알림을 사용자에게 표시하고 다른 사용자와 같은 활동에 대해 채팅하고 싶습니다.안드로이드에서 BindServices를 사용하여 알림

어떻게해야합니까? 도와주세요. . 모든 샘플 코드 또는 자습서는 유용 할 것입니다.

로그인 및 서버에서 친구 목록 가져 오기를 위해 바인드 서비스를 사용하고 있습니다.

답변

0
like that ::-> 

public class WifiService extends Service { 

private final IBinder mBinder = new MyBinder(); 

@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
    // TODO Auto-generated method stub 

    boolean networkStatus = haveNetworkConnection(); 
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); 
    NetworkInfo netInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); 
    Notification not; 
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    if(networkStatus == true || netInfo.isConnected() == true){ 
     not = new Notification(R.drawable.on, "Wi-Fi Connector", System.currentTimeMillis()); 
    } else { 
     not = new Notification(R.drawable.off, "Wi-Fi is not connector", System.currentTimeMillis()); 
    } 


    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), Notification.FLAG_ONGOING_EVENT);   
    not.flags = Notification.FLAG_ONGOING_EVENT; 
    if(networkStatus == true || netInfo.isConnected() == true){ 
     not.setLatestEventInfo(this, "Wi-Fi Connector" , "Wi-Fi is connected. You can download data.", contentIntent); 
    } else { 
     not.setLatestEventInfo(this, "Wi-Fi Connector" , "Wi-Fi is not connected. You can not download data.", contentIntent); 
    } 

    mNotificationManager.notify(1, not); 

    return Service.START_NOT_STICKY; 
} 

@Override 
public IBinder onBind(Intent intent) { 
    return mBinder; 
} 

public class MyBinder extends Binder { 
    WifiService getService() { 
     return WifiService.this; 
    } 
} 

private boolean haveNetworkConnection() { 
    boolean haveConnectedWifi = false; 
    boolean haveConnectedMobile = false; 

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 
    NetworkInfo[] netInfo = cm.getAllNetworkInfo(); 
    for (NetworkInfo ni : netInfo) { 
     if (ni.getTypeName().equalsIgnoreCase("WIFI")) 
      if (ni.isConnected()) 
       haveConnectedWifi = true; 
     if (ni.getTypeName().equalsIgnoreCase("MOBILE")) 
      if (ni.isConnected()) 
       haveConnectedMobile = true; 
    } 
    return haveConnectedWifi || haveConnectedMobile; 
} 
} 
관련 문제