Hi I have implemented HTTP server in Android device. When my app loads, a 
service gets started that handles the method POST. In my handler for HTTP 
Post, I m calling 2 intents and finally a service in 
replaceResourceSegment() method below (using a III party code) to execute 
some scripts after which a Broadcast message is sent to my service. I need 
to send HTTP Response after the Broadcast is received by the service(in the 
receiver). Basically I want to wait till my script gets executed and then 
send the response in Broadcast Receiver. Can some one guide me in this 
implementation?

if(method.equals("POST"))
        {   
        conn.receiveRequestEntity((HttpEntityEnclosingRequest)request);         
    
        HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity();  
        
        String content_type = ""+entity.getContentType();
        JSONReceived = EntityUtils.toString(entity);
        if(content_type.contains("json"))
        {       
        Log.d(TAG,"Content received is: "+JSONReceived);
        bufferedWriter = new BufferedWriter(new FileWriter(new 
File(getFilesDir()+File.separator+constants.UPDATED_SCRIPT_FILE)));
        bufferedWriter.write(JSONReceived);
        bufferedWriter.close();            
        try {
            parseJSON(JSONReceived);
            replaceResourceSegment();                                           
    
        } catch (IOException e) {
            e.printStackTrace();
            Log.d(TAG,"IOException line 157");
        }

Code for sending response back:


HttpResponse postResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, 
"OK");
postResponse.setEntity(new StringEntity("Got it"));
conn.sendResponseHeader(postResponse);
conn.sendResponseEntity(postResponse);


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to