Android Open Source - NetworkClipboardAndroid Network Clipboard Service






From Project

Back to project page NetworkClipboardAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project NetworkClipboardAndroid 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.adyrhan.networkclipboard;
/* w w  w . j  ava 2  s .  c  o m*/
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.Charset;

import com.adyrhan.networkclipboard.HttpServer.NewDataListener;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.text.ClipboardManager;
import android.util.Log;

@SuppressWarnings("deprecation")
public class NetworkClipboardService extends Service implements NewDataListener{

  public static final int LISTENING_PORT = 40400;
  private static final String TAG = "NetworkClipboardService";
  public static boolean isRunning;
  private HttpServer httpServer;
  
  @Override
  public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
  }
  
  @Override
  public void onCreate() {
    try {
      super.onCreate();
      httpServer = new HttpServer();
      httpServer.startServer(LISTENING_PORT, this);
      NetworkClipboardService.isRunning = true;
    } catch (PortIOError e) {
      NetworkClipboardService.isRunning = false;
      Log.e(TAG, null, e);
    }
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId){
    return super.onStartCommand(intent, flags, startId);
    
  }
  
  @Override
  public void onDestroy() {
    super.onDestroy();
    Log.d(TAG, "Service is stopping...");
    httpServer.stopServer();
    NetworkClipboardService.isRunning = false;
  }

  @Override
  public void onNewText(String text) {
    try {
      ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
      clipboard.setText(URLDecoder.decode(text, Charset.defaultCharset().name()));
    } catch (UnsupportedEncodingException e) {
      Log.e(TAG, null, e);
    }
  }

}




Java Source Code List

com.adyrhan.networkclipboard.BootReceiver.java
com.adyrhan.networkclipboard.HttpServer.java
com.adyrhan.networkclipboard.NetworkClipboardService.java
com.adyrhan.networkclipboard.PortIOError.java
com.adyrhan.networkclipboard.ServiceControlActivity.java
com.adyrsoft.framework.android.InputStreamUtils.java