android中使用BindServices的通知

android中使用BindServices的通知,android,service,notifications,smack,Android,Service,Notifications,Smack,我正在使用android中的smack开发聊天应用程序。我有一个关于显示通知的问题。在登录到列表视图后,我将向用户显示一个状态为的好友列表。现在我想向用户显示他在同一活动中与其他用户聊天时收到的不同用户聊天次数的通知 如何做到这一点?请帮帮我。任何示例代码或教程都将非常有用 我正在使用绑定服务登录并从服务器获取好友列表 like that ::-> public class WifiService extends Service { private final IBinder mBin

我正在使用android中的smack开发聊天应用程序。我有一个关于显示通知的问题。在登录到
列表视图
后,我将向用户显示一个状态为的好友列表。现在我想向用户显示他在同一活动中与其他用户聊天时收到的不同用户聊天次数的通知

如何做到这一点?请帮帮我。任何示例代码或教程都将非常有用

我正在使用绑定服务登录并从服务器获取好友列表

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;
}
}