Android Open Source - expo-connect Screen Data Receiver






From Project

Back to project page expo-connect.

License

The source code is released under:

GNU General Public License

If you think the Android project expo-connect 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 it.polimi.camparollo.expoconnect.datatransfer;
//  www.  java2  s  .  c om
import it.polimi.camparollo.expoconnect.recommendations.SingleRestaurant;
import it.polimi.camparollo.expoconnect.recommendations.RestaurantListActivity;
import it.polimi.camparollo.expoconnect.wifi.StartActivity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.Log;

public class ScreenDataReceiver {
  
  private ReceiverTask task = new ReceiverTask(); 
  private Activity context;
  
  
  public ScreenDataReceiver(Activity context) {
    super();
    this.context = context;
  }

  public void receiveData(){
    
    task.execute();
    
  }
  
  public class ReceiverTask extends AsyncTask<Void, Void, String> {

    @Override
    protected String doInBackground(Void... params) {
      
      try {
        
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket client = serverSocket.accept();

        Log.d(StartActivity.TAG, "Processing incoming data");
        InputStream inputstream = client.getInputStream();
              InputStreamReader ir = new InputStreamReader(inputstream);
              BufferedReader br = new BufferedReader(ir, 8*1024);
              
              String inputLine;
              StringBuilder sb = new StringBuilder();
              while((inputLine = br.readLine()) != null)
                sb.append(inputLine);
              br.close();   
              
              inputstream.close();
        serverSocket.close();
        
        Log.d(StartActivity.TAG, "Received data: " + sb.toString());
        return sb.toString();
        
      } catch (IOException e) {
        e.printStackTrace();
      }
      return "";
    }

    @Override
    protected void onPostExecute(String receivedData) {
      
      SharedPreferences settings = context.getSharedPreferences(StartActivity.TAG, 0);
      SharedPreferences.Editor editor = settings.edit();
      editor.putString("Data", receivedData);
      editor.commit();

      
      Intent i = new Intent(context, RestaurantListActivity.class);
      i.putExtra("Data", receivedData);
      context.startActivity(i);
      
    }
    
    
  }
}




Java Source Code List

it.polimi.camparollo.expoconnect.datatransfer.IPAddressSender.java
it.polimi.camparollo.expoconnect.datatransfer.RESTClient.java
it.polimi.camparollo.expoconnect.datatransfer.Restaurant.java
it.polimi.camparollo.expoconnect.datatransfer.ScreenDataReceiver.java
it.polimi.camparollo.expoconnect.exceptions.CannotEnableWifiP2pException.java
it.polimi.camparollo.expoconnect.recommendations.RestaurantListActivity.java
it.polimi.camparollo.expoconnect.recommendations.RestaurantListAdapter.java
it.polimi.camparollo.expoconnect.recommendations.SingleRestaurant.java
it.polimi.camparollo.expoconnect.uilisteners.ConnectionInfo.java
it.polimi.camparollo.expoconnect.uilisteners.PeersListUpdater.java
it.polimi.camparollo.expoconnect.utils.ScalingUtilities.java
it.polimi.camparollo.expoconnect.wifi.CustomWifiP2pManager.java
it.polimi.camparollo.expoconnect.wifi.InfoActionListener.java
it.polimi.camparollo.expoconnect.wifi.StartActivity.java
it.polimi.camparollo.expoconnect.wifi.WiFiDirectBroadcastReceiver.java
it.polimi.camparollo.expoconnectserver.CommandReceiver.java
it.polimi.camparollo.expoconnectserver.InfoActionListener.java
it.polimi.camparollo.expoconnectserver.ServiceStarterActivity.java
it.polimi.camparollo.expoconnectserver.uilisteners.ConnectionInfo.java
it.polimi.camparollo.expoconnectserver.uilisteners.PeersListUpdater.java
it.polimi.camparollo.expoconnectserver.wifi.ConnectService.java
it.polimi.camparollo.expoconnectserver.wifi.IPAddressReceiver.java
it.polimi.camparollo.expoconnectserver.wifi.ScreenDataSender.java
it.polimi.camparollo.expoconnectserver.wifi.WiFiDirectBroadcastReceiver.java