Newbie Coding problem

Put your problem here if it does not fit any of the other categories.

Newbie Coding problem

Postby PatrickGlose » Mon Sep 13, 2010 9:23 am

I just don't know where to go from here. I seem to have problems getting tvMessage on lines 50 and 54 to resolve, probably because the String is not passed yet. But when I try build the tvMessage first, I get other errors I can not resolve. I am sure there are other coding problems too, but I have to get past this one before I can find others.
FYI - This program will (hopefully) eventually be used to pass SMS, PhoneState, and Calendar events to the PMR on a Samsung TV, 650 series and above. Thanks for looking and for any help you can give me.

Code: Select all
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import android.util.Log;

public final class CreateMessage extends BroadcastReceiver {
   
   
   
   @Override
   public void onReceive(Context context, Intent intent) {
      // TODO Auto-generated method stub
      
   
   
      //String requestURI = "http://" + host + ":52235/pmr/MessageBoxService.xml";
      String serviceURI = "/PMR/control/MessageBoxService";
      int portnr = 52235;
      String host = "192.168.1.10";
      String tvMessage = null;
      
      
      try {
         
         Socket s = new Socket(host, portnr);         
         PrintWriter out = new PrintWriter(s.getOutputStream(), true);
           BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
           // send headers
           out.println("POST " + serviceURI + " HTTP/1.0");          
           out.println("Host: " + host);
           //out.println("Referrer: http://redbull/");
           //out.println("User-Agent: MsgBoxService");
           //out.println("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
           //out.println("Keep-Alive: 60");
           //out.println("Connection: keep-alive");          
          
           out.println("Content-Type: text/xml; charset=UTF-8");
           out.println("Content-Length: " + tvMessage.length());
           out.println("SOAPACTION: \"urn:samsung.com:service:MessageBoxService:1#AddMessage\"");
           out.println("Connection: close");
           out.println(); // don't forget extra line break after headers
           out.println(tvMessage);
           out.println();          
          
           String fullResponse = "";
           String receiveHeaders;
           while ((receiveHeaders = in.readLine()) != null) {
              fullResponse += receiveHeaders + "\n";
           }
          
      
          
                     
           out.close();
          in.close();
          s.close();      
         
      } catch (UnknownHostException e) {
         Log.e ("Error resolving host: " + host + "\n" + e.getMessage(),
               "Error sending messsage");
      
      } catch (IOException e) {
         Log.e ("Error resolving host: " + host + "\n" + e.getMessage(),
               "Error sending messsage");
         
      }      
      
   }

   /**
    * Compiles message based on messageBody and messageType
    *
    * Does not fully support the Schedule Reminder: location is fixed, as there is no input field in the
    * GUI
    *
    * @param messageBody
    * @param messageType
    * @param receiverNumber
    * @param receiverName
    * @param senderNumber
    * @param senderName
    * @return PMS SOAP message
    */
String messageTypes[] = new String [] {"SMS", "Incoming Call", "Schedule Reminder"};
   String compileSoapMessage(String messageBody, String messageType, Object receiverNumber, Object receiverName, Object senderNumber, Object senderName, int getIndexOnIcc) {      
      Date d = new Date();
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
      SimpleDateFormat timeFormatter = new SimpleDateFormat("kk:mm:ss");      
      

      String header = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
      header += "<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" >\n";
      header += "<s:Body><u:AddMessage xmlns:u=\"urn:samsung.com:service:MessageBoxService:1\">\n";
      
      String tvMessage = header + "<MessageType>text/xml</MessageType>\n";
      tvMessage += "<MessageID>" + "messageID" + "</MessageID>\n";//TODO edit
      tvMessage += "<Message>\n";
      tvMessage += "&lt;Category&gt;" + messageType + "&lt;/Category&gt;\n";
      tvMessage += "&lt;DisplayType&gt;" + "displayType" + "&lt;/DisplayType&gt;\n";//TODO edit

      if (messageType.equals(messageTypes[0])) // SMS
      {
         tvMessage += "&lt;ReceiveTime&gt;\n";
         tvMessage += "&lt;Date&gt;" + formatter.format(d) + "&lt;/Date&gt;\n";
         tvMessage += "&lt;Time&gt;" + timeFormatter.format(d) + "&lt;/Time&gt;\n";
         tvMessage += "&lt;/ReceiveTime&gt;\n";
         tvMessage += "&lt;Receiver&gt;\n";
         tvMessage += "&lt;Number&gt;" + "receiverNumber.getText()" + "&lt;/Number&gt;\n";//TODO edit
         tvMessage += "&lt;Name&gt;" + "receiverName.getText()" + "&lt;/Name&gt;\n";//TODO edit
         tvMessage += "&lt;/Receiver&gt;\n";
         tvMessage += "&lt;Sender&gt;\n";
         tvMessage += "&lt;Number&gt;" + "getOriginatingAddress" + "&lt;/Number&gt;\n";//TODO edit
         tvMessage += "&lt;Name&gt;" + "senderName.getText()" + "&lt;/Name&gt;\n";//TODO edit
         tvMessage += "&lt;/Sender&gt;\n";
         tvMessage += "&lt;Body&gt;" + "getMessageBody" + "&lt;/Body&gt;\n";//TODO edit
      }
      else if (messageType.equals(messageTypes[1])) // incoming call
      {
         tvMessage += "&lt;CallTime&gt;\n";
         tvMessage += "&lt;Date&gt;" + formatter.format(d) + "&lt;/Date&gt;\n";
         tvMessage += "&lt;Time&gt;" + timeFormatter.format(d) + "&lt;/Time&gt;\n";
         tvMessage += "&lt;/CallTime&gt;\n";
         tvMessage += "&lt;Callee&gt;\n";
         tvMessage += "&lt;Number&gt;" + "receiverNumber.getText()" + "&lt;/Number&gt;\n";//TODO edit
         tvMessage += "&lt;Name&gt;" + "receiverName.getText()" + "&lt;/Name&gt;\n";//TODO edit
         tvMessage += "&lt;/Callee&gt;\n";
         tvMessage += "&lt;Caller&gt;\n";
         tvMessage += "&lt;Number&gt;" + "senderNumber.getText()" + "&lt;/Number&gt;\n";//TODO edit
         tvMessage += "&lt;Name&gt;" + "senderName.getText()" + "&lt;/Name&gt;\n";//TODO edit
         tvMessage += "&lt;/Caller&gt;\n";
      }
      else if (messageType.equals(messageTypes[2])) // Schedule reminder
      {
         tvMessage += "&lt;StartTime&gt;\n";
         tvMessage += "&lt;Date&gt;" + formatter.format(d) + "&lt;/Date&gt;\n";
         tvMessage += "&lt;Time&gt;" + timeFormatter.format(d) + "&lt;/Time&gt;\n";
         tvMessage += "&lt;/StartTime&gt;\n";
         tvMessage += "&lt;Owner&gt;\n";
         tvMessage += "&lt;Number&gt;" + "receiverNumber.getText()" + "&lt;/Number&gt;\n";//TODO edit
         tvMessage += "&lt;Name&gt;" + "receiverName.getText()" + "&lt;/Name&gt;\n";//TODO edit
         tvMessage += "&lt;/Owner&gt;\n";
         tvMessage += "&lt;Subject&gt;" + "Drinks!" + "&lt;/Subject&gt;\n";
         tvMessage += "&lt;EndTime&gt;\n";
         tvMessage += "&lt;Date&gt;" + formatter.format(d) + "&lt;/Date&gt;\n";
         tvMessage += "&lt;Time&gt;" + timeFormatter.format(d) + "&lt;/Time&gt;\n";
         tvMessage += "&lt;/EndTime&gt;\n";         
         tvMessage += "&lt;Location&gt;" + "location unknown" + "&lt;/Location&gt;\n";
         tvMessage += "&lt;Body&gt;" + messageBody + "&lt;/Body&gt;\n";
         
      }
      

      tvMessage += "</Message>\n";
      tvMessage += "</u:AddMessage>\n";
      tvMessage += "</s:Body>\n";
      tvMessage += "</s:Envelope>\n";
      
      return tvMessage;
   }
      
   }
   
   
   
   


PatrickGlose
Freshman
Freshman
 
Posts: 5
Joined: Tue Aug 31, 2010 3:00 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 13 guests