您的位置:首页 > 移动开发

The source code of the Receiver class of the famous IM app

2014-05-09 23:48 459 查看
package cn.com.xetion.receiver;

import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.widget.RemoteViews;
import cn.com.xetion.LogF;
import cn.com.xetion.activity.LoginActivity;
import cn.com.xetion.network.HttpClient;
import cn.com.xetion.network.HttpRequest;
import cn.com.xetion.network.HttpResponse;
import cn.com.xetion.protocol.http.GetNavInfo;
import cn.com.xetion.protocol.http.GetNavInfo.Result;
import cn.com.xetion.store.Config;
import cn.com.xetion.util.AndroidUtil;
import java.io.IOException;
import java.util.Map;

public class ExitReceiver extends BroadcastReceiver
{
private AlarmManager mAlarmManagerPush;
private PendingIntent mPendingIntentPush;

private void getPush(Context paramContext)
{
String address;
HttpRequest localHttpRequest;
HttpClient localHttpClient;
if (isTest())
{
address = "http://221.179.173.107/mnav/";
localHttpRequest = GetNavInfo.wrapper(address + "getnetsystemconfig.aspx", "13641264614", AndroidUtil.getVersionName(paramContext), "0", "0", "0", "0", "0");
localHttpClient = new HttpClient();
}
try
{
HttpResponse localHttpResponse = localHttpClient.send(localHttpRequest);
if (localHttpResponse != null)
{
byte[] arrayOfByte = localHttpResponse.getBytes();
if (arrayOfByte != null)
{
Map localMap = GetNavInfo.parse(arrayOfByte).getNodeAndValues();
((String)((Map)localMap.get("servers")).get("push-noland-msg"));
String localint = (String)((Map)localMap.get("servers")).get("push-land-msg");
Intent localIntent = new Intent();
localIntent.setClass(paramContext, LoginActivity.class);
showMessageNotification(paramContext, 1, 2130838574, "系统消息", localint, localIntent);
}
}
return;
address = "http://mnav.xetion.com.cn/mnav/";
}
catch (IOException localIOException)
{
while (true)
localIOException.printStackTrace();
}
}

private void pushAlarm(Context paramContext)
{
if (this.mAlarmManagerPush == null)
this.mAlarmManagerPush = ((AlarmManager)paramContext.getSystemService("alarm"));
if (this.mPendingIntentPush == null)
this.mPendingIntentPush = PendingIntent.getBroadcast(paramContext, 0, new Intent("cn.com.xetion.getpush"), 268435456);
this.mAlarmManagerPush.set(0, 7000L + System.currentTimeMillis(), this.mPendingIntentPush);
LogF.d("push", "pushAlarm(Context context)");
}

private void showMessageNotification(Context paramContext, int paramInt1, int paramInt2, String paramString1, String paramString2, Intent paramIntent)
{
NotificationManager localNotificationManager = (NotificationManager)paramContext.getSystemService("notification");
Notification localNotification = new Notification(paramInt2, paramString1, System.currentTimeMillis());
paramIntent.putExtra("cn.com.xetion.logic.MessageLogic.EXTRA_MESSAGE_TITLE", paramString1);
localNotification.setLatestEventInfo(paramContext.getApplicationContext(), paramString1, paramString2, PendingIntent.getActivity(paramContext, 1, paramIntent, 134217728));
localNotification.flags = 16;
localNotification.contentView.setImageViewResource(16908294, 2130838573);
localNotificationManager.notify(1, localNotification);
}

public boolean isTest()
{
return Config.isTest();
}

public void onReceive(Context paramContext, Intent paramIntent)
{
int i;
if ("cn.com.xetion.exit".equals(paramIntent.getAction()))
paramContext.sendBroadcast(new Intent("cn.com.xetion.toexit"));
do
return;
while (!("android.net.conn.CONNECTIVITY_CHANGE".equals(paramIntent.getAction())));
NetworkInfo localNetworkInfo = (NetworkInfo)paramIntent.getParcelableExtra("networkInfo");
if ((localNetworkInfo != null) && (localNetworkInfo.isConnected()))
i = 1;
while (true)
{
while (true)
{
long l;
do
{
if (i == 0);
l = Config.getExitTime(paramContext);
}
while (System.currentTimeMillis() - l <= 604800000L);
Config.setExitTime(paramContext, -1L);
getPush(paramContext);
}
i = 0;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android im sms app