`
longgangbai
  • 浏览: 7315827 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

androidpn的学习研究(四)androidpn-client客户端几个类说明

 
阅读更多

  在androidpn的客户端几个重要的类:

                ServiceManager:管理消息服务和加载相关的配置。

                ConnectivityReceiver:处理网络状态的广播。

                NotificationReceiver:处理服务端发送的推送消息。

                NotificationService:后台服务用户响应服务端的消息。需要在AndroidManifest.xml.注册。

                NotificationSettingsActivity:推送信息设置页面。

                PersistentConnectionListener:监控连接关闭和重连事件的监听。

                PhoneStateChangeListener:监听手机状态的事件监听类。

                ReconnectionThread:重连的线程类。

                Notifier:客户端发送通知的类。

                NotificationIQ:消息的数据包。

 

 

ServiceManager中获取属性信息的方法:

    private Properties loadProperties() {
        //        InputStream in = null;
        //        Properties props = null;
        //        try {
        //            in = getClass().getResourceAsStream(
        //                    "/org/androidpn/client/client.properties");
        //            if (in != null) {
        //                props = new Properties();
        //                props.load(in);
        //            } else {
        //                Log.e(LOGTAG, "Could not find the properties file.");
        //            }
        //        } catch (IOException e) {
        //            Log.e(LOGTAG, "Could not find the properties file.", e);
        //        } finally {
        //            if (in != null)
        //                try {
        //                    in.close();
        //                } catch (Throwable ignore) {
        //                }
        //        }
        //        return props;

        Properties props = new Properties();
        try {
            int id = context.getResources().getIdentifier("androidpn", "raw",
                    context.getPackageName());
            props.load(context.getResources().openRawResource(id));
        } catch (Exception e) {
            Log.e(LOGTAG, "Could not find the properties file.", e);
            // e.printStackTrace();
        }
        return props;
    }

 

 

SharedPreferences的使用:

        sharedPrefs = context.getSharedPreferences(
                Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
        Editor editor = sharedPrefs.edit();
        editor.putString(Constants.API_KEY, apiKey);
        editor.putString(Constants.VERSION, version);
        editor.putString(Constants.XMPP_HOST, xmppHost);
        editor.putInt(Constants.XMPP_PORT, Integer.parseInt(xmppPort));
        editor.putString(Constants.CALLBACK_ACTIVITY_PACKAGE_NAME,
                callbackActivityPackageName);
        editor.putString(Constants.CALLBACK_ACTIVITY_CLASS_NAME,
                callbackActivityClassName);
        editor.commit();

 

获取手机的设备id:

TelephonyManager       telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        // wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        // connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

        // Get deviceId
        deviceId = telephonyManager.getDeviceId();

 Notifier中发送通知的方法:

            // Notification
            Notification notification = new Notification();
            notification.icon = getNotificationIcon();
            notification.defaults = Notification.DEFAULT_LIGHTS;
            if (isNotificationSoundEnabled()) {
                notification.defaults |= Notification.DEFAULT_SOUND;
            }
            if (isNotificationVibrateEnabled()) {
                notification.defaults |= Notification.DEFAULT_VIBRATE;
            }
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notification.when = System.currentTimeMillis();
            notification.tickerText = message;

            //            Intent intent;
            //            if (uri != null
            //                    && uri.length() > 0
            //                    && (uri.startsWith("http:") || uri.startsWith("https:")
            //                            || uri.startsWith("tel:") || uri.startsWith("geo:"))) {
            //                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
            //            } else {
            //                String callbackActivityPackageName = sharedPrefs.getString(
            //                        Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, "");
            //                String callbackActivityClassName = sharedPrefs.getString(
            //                        Constants.CALLBACK_ACTIVITY_CLASS_NAME, "");
            //                intent = new Intent().setClassName(callbackActivityPackageName,
            //                        callbackActivityClassName);
            //                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            //            }

            Intent intent = new Intent(context,
                    NotificationDetailsActivity.class);
            intent.putExtra(Constants.NOTIFICATION_ID, notificationId);
            intent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
            intent.putExtra(Constants.NOTIFICATION_TITLE, title);
            intent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
            intent.putExtra(Constants.NOTIFICATION_URI, uri);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                    intent, PendingIntent.FLAG_UPDATE_CURRENT);

            notification.setLatestEventInfo(context, title, message,
                    contentIntent);
            notificationManager.notify(random.nextInt(), notification);

 

androidpn用户名和密码来源:

XmppManager的注册任务(RegisterTask)中run方法:

            if (!xmppManager.isRegistered()) {
                final String newUsername = newRandomUUID();
                final String newPassword = newRandomUUID();

                Registration registration = new Registration();

                PacketFilter packetFilter = new AndFilter(new PacketIDFilter(
                        registration.getPacketID()), new PacketTypeFilter(
                        IQ.class));

 

分享到:
评论
2 楼 longgangbai 2013-07-28  
liangjoy_chen 写道
我对注册用户这块代码进行了修改。用手机的imsi号替代uid作为username进行注册。然后在打开软件时候提示username重复无法连接到服务端。这个有什么好的解决办法?希望可以帮忙解决下

国际移动用户识别码(IMSI:International Mobile SubscriberIdentification Number)是区别移动用户的标志,储存在SIM卡中,可用于区别移动用户的有效信息。其总长度不超过15位,同样使用0~9的数字。其中MCC是移动用户所属国家代号,占3位数字,中国的MCC规定为460;MNC是移动网号码,最多由两位数字组成,用于识别移动用户所归属的移动通信网;MSIN是移动用户识别码,用以识别某一移动通信网中的移动用户。
imsi的百科地址:
http://baike.baidu.com/view/715091.htm
1 楼 liangjoy_chen 2013-07-23  
我对注册用户这块代码进行了修改。用手机的imsi号替代uid作为username进行注册。然后在打开软件时候提示username重复无法连接到服务端。这个有什么好的解决办法?希望可以帮忙解决下

相关推荐

    androidpn-client-0.5.0和androidpn-server-0.5.0-bin

    客户端主要包含以下几个关键部分: 1. **注册过程**:当用户安装应用后,客户端会通过与服务器进行交互,获取一个唯一的设备ID,并注册到服务器的推送列表中。 2. **后台监听**:客户端在后台持续运行,通过保持一...

    androidpn-server-0.5.0-bin、androidpn-client-0.5.0、androidpn-demoapp-0.5.0

    这个项目包括三个主要组件:服务器端(androidpn-server)、客户端库(androidpn-client)以及一个演示应用(androidpn-demoapp)。我们来逐一解析这些组件及其相关知识点。 1. **AndroidPN-Server-0.5.0-bin**: 这...

    androidPn-client

    在Android平台上,`androidPn-client`项目是一个专门为实现Push Notification服务客户端而设计的应用程序。Push Notification(简称PN)是一种让服务器向移动设备推送消息的技术,通常用于实时更新应用状态或者提醒...

    androidpn-client 0.5 推送

    在"androidpn-client-0.5.01111"源码包中,我们可以找到以下几个关键模块: 1. **MainActivity**:主活动类,启动客户端并处理用户交互。 2. **PushManager**:推送管理器,负责客户端的注册、连接、断开和消息处理...

    androidpn-client-pc(有问题吧CSDN噢)

    在进行压力测试时,我们需要关注以下几个方面: 1. **网络连接管理**:客户端需要有效地建立和维护与服务器的连接,确保在高并发情况下连接的稳定性和效率。 2. **消息处理**:客户端接收到推送消息后,如何正确...

    androidpn 客户端模拟代码

    在“模拟androidpn客户端的代码”中,我们可能会涉及到以下几个关键知识点: 1. **注册过程**:客户端需要先注册到AndroidPN服务端,通常会提供一个唯一的设备标识(如IMEI或Android ID)以及应用程序的唯一标识...

    androidpn客户端与服务端

    接下来是客户端部分,`androidpn-client-0.5.0`包含了客户端的源代码。客户端的职责包括: 1. **注册**:客户端在启动时会连接到服务端,并注册其设备以便接收通知。这通常涉及到获取GCM或FCM的注册ID并将其发送到...

    androidpn 消息推送客户端+服务器端

    客户端的实现包括以下几个关键点: 1. **注册过程**:首次启动时,客户端会获取设备的IMEI(国际移动设备身份码)或Google提供的GCM(Google Cloud Messaging)注册ID,并将这些信息发送到服务器进行注册。 2. **...

    androidpn server+client

    标题"androidpn server+client"表明我们将讨论的是AndroidPN的服务器端和客户端组件。服务器端负责处理推送通知的发送和管理,而客户端则是安装在Android设备上的应用,接收并处理来自服务器的通知。 在描述...

    AndroidPN_Demo Example

    《AndroidPN_Demo Example——深入理解Android推送通知》 ...通过学习和研究这个示例,不仅可以掌握AndroidPN的使用,还能对Android推送通知有更深入的理解,从而在实际项目中更好地运用这一技术。

    Androidpn源码

    客户端(androidpn-client)部分主要包含以下几个关键组件: 1. **注册模块**:用户安装应用后,首先需要注册设备以获取唯一的设备ID,这个ID用于服务器识别并推送消息给特定设备。源码中,注册过程涉及网络通信,...

    XMPP消息推送Demo【服务器+客户端】

    在实现XMPP消息推送的过程中,开发者需要对以下几个关键概念有深入理解: 1. **连接管理**:客户端需要建立并维护一个持久的TCP连接到服务器,确保消息能实时传递。 2. **身份验证**:服务器需要验证每个客户端的...

    推送客户端

    在开发过程中,开发者需要关注以下几个方面: 1. 授权管理:确保客户端能正确处理服务器的身份验证和授权。 2. 异常处理:对网络异常、连接超时等情况进行妥善处理,提供良好的用户体验。 3. 资源管理:有效地管理...

    android推送

    这包括以下几个步骤: 1. 注册:应用在启动时向GCM/FCM服务器注册,获取一个唯一的注册ID。 2. 接收:应用需要实现一个BroadcastReceiver来监听接收到的推送消息。 3. 处理:收到消息后,根据消息内容决定是否显示...

    android电子商城

    6. **androidpn-client-0.5.0**:对应的客户端库,可能用于接收服务器端的推送通知,增强应用的实时性。 通过研究这个项目,开发者不仅可以学习到Android应用开发的基本技能,还能深入理解电商系统的架构设计和实现...

    android推送服务器和android客户端

    在实际开发中,客户端需要考虑以下几点: 1. 注册过程:客户端启动时需要向服务器注册,获取设备令牌。 2. 消息处理:客户端需要有一个消息处理服务,即使应用在后台也能接收并处理推送消息。 3. 用户权限:确保应用...

Global site tag (gtag.js) - Google Analytics