Android Open Source - FlashTransmitter Submit Data Task






From Project

Back to project page FlashTransmitter.

License

The source code is released under:

GNU General Public License

If you think the Android project FlashTransmitter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.catinthedark.task;
/*from  w ww.  j av  a 2s.  c om*/
import android.os.AsyncTask;
import android.os.Build;
import android.util.Log;
import android.widget.Toast;

import com.catinthedark.activity.ReceiveActivity;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.TreeMap;

/**
 * Created by kirill on 01.10.14.
 */
public class SubmitDataTask extends AsyncTask<Object, String, Void> {
    @Override
    protected Void doInBackground(Object... params) {
        try {
            String transmissionResult = (String) params[0];

            String uri = "http://192.168.43.127:3000/graph";
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(uri);

            StringEntity se = new StringEntity(transmissionResult);
            httpPost.setEntity(se);

            httpPost.setHeader("accept", "*/*");
            httpPost.setHeader("content-type", "application/x-www-form-urlencoded");

            HttpResponse httpResponse = httpclient.execute(httpPost);

            InputStream inputStream = httpResponse.getEntity().getContent();

            String result;
            if(inputStream != null) {
                result = convertInputStreamToString(inputStream);
            }
            else {
                result = "Did not work!";
            }
            Log.d(ReceiveActivity.TAG, "Result: " + result);

        } catch (Exception e) {
            Log.d("InputStream", e.getLocalizedMessage());
        }
        return null;
    }

    private static String convertInputStreamToString(InputStream inputStream) throws IOException {
        BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
        String line = "";
        String result = "";
        while((line = bufferedReader.readLine()) != null)
            result += line;

        inputStream.close();
        return result;
    }
}


//// create the albums object
//JsonObject albums = new JsonObject();
//// add a property calle title to the albums object
//albums.addProperty("title", "album1");
//
//        // create an array called datasets
//        JsonArray datasets = new JsonArray();
//
//        // create a dataset
//        JsonObject dataset = new JsonObject();
//        // add the property album_id to the dataset
//        dataset.addProperty("album_id", 1);
//        // add the property album_year to the dataset
//        dataset.addProperty("album_year", 1996);
//
//        datasets.add(dataset);
//
//        albums.add("dataset", datasets);
//
//        // create the gson using the GsonBuilder. Set pretty printing on. Allow
//        // serializing null and set all fields to the Upper Camel Case
//        Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
//        System.out.println(gson.toJson(albums));
//        /* prints
//        {
//              "title": "album1",
//              "dataset": [
//                {
//                  "album_id": 1,
//                  "album_year": 1996
//                }
//              ]
//        }
//        */




Java Source Code List

com.catinthedark.activity.ReceiveActivity.java
com.catinthedark.activity.StartActivity.java
com.catinthedark.activity.TransmitActivity.java
com.catinthedark.flash_transmitter.lib.algorithm.ASCIIScheme.java
com.catinthedark.flash_transmitter.lib.algorithm.CompressedScheme.java
com.catinthedark.flash_transmitter.lib.algorithm.Converter.java
com.catinthedark.flash_transmitter.lib.algorithm.EmptyErrorCorrectionLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.EmptyLogicalCodeLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.EncodingScheme.java
com.catinthedark.flash_transmitter.lib.algorithm.ErrorCorrectionLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.Filter.java
com.catinthedark.flash_transmitter.lib.algorithm.LineCoder.java
com.catinthedark.flash_transmitter.lib.algorithm.LogicalCodeLayer.java
com.catinthedark.flash_transmitter.lib.algorithm.ManchesterLineCoder.java
com.catinthedark.flash_transmitter.lib.algorithm.ManchesterSynchronizer.java
com.catinthedark.flash_transmitter.lib.algorithm.RawDataTranslator.java
com.catinthedark.flash_transmitter.lib.algorithm.Synchronizer.java
com.catinthedark.flash_transmitter.lib.factories.EncodingSchemeFactory.java
com.catinthedark.flash_transmitter.lib.factories.ErrorCorrectionFactory.java
com.catinthedark.flash_transmitter.lib.factories.LineCoderFactory.java
com.catinthedark.flash_transmitter.lib.factories.LogicalCodeFactory.java
com.catinthedark.task.SubmitDataTask.java