rendered paste bodypackage com.silentone.myprofilux;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class C2DMReceiver extends BroadcastReceiver {
//private CustomerBean customer = null;
//private RegisterManager reg = null;
int UserId = 0;
private boolean auth = false;
//private CustLogin cl = null;
public C2DMReceiver()
{
// cl = new CustLogin();
}
public void onReceive(Context context, Intent intent)
{
Log.i("Recieve","2");
System.out.println("CD2M - Intent Received!");
if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION"))
{
handleRegistration(context, intent);
}
else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE"))
{
handleMessage(context, intent);
}
}
private void handleRegistration(Context context, Intent intent)
{
String registration = intent.getStringExtra("registration_id");
if (intent.getStringExtra("error") != null)
{
System.out.println("CD2M - There was an error with your device registration!");
// Registration failed, should try again later.
}
else if (intent.getStringExtra("unregistered") != null)
{
// unregistration done, new messages from the authorized sender will be rejected
System.out.println("CD2M - You have been unregistered!");
}
else if (registration != null)
{
// Send the registration ID to the 3rd party site that is sending the messages.
// This should be done in a separate thread.
// When done, remember that all registration is done.
// UserId = customer.getId();
// Log.i("id",String.valueOf(UserId));
RequestThread rt = new RequestThread();
rt.RegId = RegId;
Thread t = new Thread(rt);
t.start();
//Log.i("reg",String.valueOf(RegId) );
}
}
private void handleMessage(Context context, Intent intent)
{
Bundle extras = intent.getExtras();
String message = (String)extras.get("message");
//System.out.println("Alert:" + message);
Toast.makeText(context,"myProfilux Alert: "+message,1).show();
//System.out.println("CD2M - You have been alerted!");
}
}
class RequestThread implements Runnable {
public String RegId;
public void run() {
uploadDeviceInfo();
}
private boolean uploadDeviceInfo(){
Socket s;
OutputStream out;
InputStream in;
String serialNumber = "1337";
String remoteIp = "ipip.com";
try {
s = new Socket("myprofilux.com", 80);
out = s.getOutputStream();
in = s.getInputStream();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
bw.write("GET http://www.myprofilux.com/rs/updateDevice.php?sn="+serialNumber+"&did="+RegId+"&ip="+remoteIp+ " HTTP/1.1" + "\r\n");
bw.write("Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*\r\n");
bw.write("Accept-Language: en-us\r\n");
bw.write("User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)\r\n");
bw.write("Accept-Encoding: gzip, deflate\r\n");
bw.write("If-Modified-Since: Fri, 30 Sep 2011 16:49:52 GMT; length=1\r\n");
bw.write("Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*\r\n");
bw.write("Host: 192.168.2.119" + "\r\n");
bw.write("Connection: Keep-alive\r\n");
bw.write("\r\n");
bw.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String buffer = "";
while ((buffer = br.readLine()) != null) {
System.out.println("Response: " + buffer);
}
s.close();
System.out.println("Uploaded device info!");
System.out.println("CD2M - Your registration code is: " + RegId);
} catch (Exception _ex) {
System.out.println("Failed to upload device info!");
Log.e("ghlCom", "Failed to login.");
complete = 0;
}
}
}