├── .gitignore
├── File Share
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── io
│ │ └── github
│ │ └── karuppiah7890
│ │ └── fileshare
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── io
│ │ │ └── github
│ │ │ └── karuppiah7890
│ │ │ └── fileshare
│ │ │ ├── FileReceiver.java
│ │ │ ├── FileSender.java
│ │ │ ├── ReceiverService.java
│ │ │ ├── ReceiverThread.java
│ │ │ ├── SenderService.java
│ │ │ └── SenderThread.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── io
│ └── github
│ └── karuppiah7890
│ └── fileshare
│ └── ExampleUnitTest.java
├── FileSharerDemoApp
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── io
│ │ └── github
│ │ └── karuppiah7890
│ │ └── filesharer
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── io
│ │ │ └── github
│ │ │ └── karuppiah7890
│ │ │ └── filesharer
│ │ │ ├── DashBoard.java
│ │ │ ├── ReceiverActivity.java
│ │ │ └── SenderActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_dash_board.xml
│ │ ├── activity_receiver.xml
│ │ └── activity_sender.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── io
│ └── github
│ └── karuppiah7890
│ └── filesharer
│ └── ExampleUnitTest.java
├── LICENSE.md
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | .idea
4 | /local.properties
5 | /.idea/workspace.xml
6 | /.idea/libraries
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/File Share/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/File Share/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "25.0.0"
7 |
8 | defaultConfig {
9 | minSdkVersion 9
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | publish {
26 | groupId = 'io.github.karuppiah7890'
27 | artifactId = 'fileshare'
28 | publishVersion = '0.1.0'
29 | desc = 'An Android library to send and receive files among Android devices in a WiFi LAN.'
30 | licences = ['MIT']
31 | uploadName='FileShare'
32 | website = 'https://github.com/Android-File-Share/FileShare'
33 | }
34 |
35 | dependencies {
36 | compile fileTree(dir: 'libs', include: ['*.jar'])
37 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
38 | exclude group: 'com.android.support', module: 'support-annotations'
39 | })
40 | compile 'com.android.support:appcompat-v7:25.0.0'
41 | testCompile 'junit:junit:4.12'
42 | }
43 |
--------------------------------------------------------------------------------
/File Share/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\3521\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/File Share/src/androidTest/java/io/github/karuppiah7890/fileshare/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.fileshare;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("io.github.karuppiah7890.fileshare.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/File Share/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
15 |
19 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/File Share/src/main/java/io/github/karuppiah7890/fileshare/FileReceiver.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.fileshare;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Handler;
6 | import android.os.Messenger;
7 | import android.util.Log;
8 |
9 | import java.io.IOException;
10 | import java.net.ServerSocket;
11 |
12 | public class FileReceiver {
13 |
14 | private final boolean mDebug = true;
15 |
16 | private final int MIN_PORT_NUMBER = 1024;
17 | private final int MAX_PORT_NUMBER = 65536;
18 | private final String PORT = "PORT";
19 | private final String MESSENGER = "MESSENGER";
20 |
21 | // Constants start from 2001
22 | public static final int CODE = 2001;
23 | public static final int LISTENING = 2002;
24 | public static final int CONNECTED = 2003;
25 | public static final int RECEIVING_FILE = 2004;
26 | public static final int FILE_RECEIVED = 2005;
27 | public static final int RECEIVE_ERROR = 2006;
28 |
29 | private Context context;
30 | private Handler mHandler;
31 |
32 | private Intent i;
33 |
34 | public FileReceiver(Context context, Handler mHandler) {
35 | this.context = context;
36 | this.mHandler = mHandler;
37 | }
38 |
39 | private boolean isPortAvailable(int port) {
40 |
41 | boolean available;
42 |
43 | if (port < MIN_PORT_NUMBER || port > MAX_PORT_NUMBER) {
44 | throw new IllegalArgumentException("Invalid port: " + port);
45 | }
46 |
47 | ServerSocket ss = null;
48 |
49 | try {
50 | ss = new ServerSocket(port);
51 | ss.setReuseAddress(true);
52 | available = true;
53 | } catch (IOException e) {
54 | available = false;
55 | } finally {
56 |
57 | if (ss != null) {
58 | try {
59 | ss.close();
60 | } catch (IOException e) {
61 |
62 | }
63 | }
64 | }
65 |
66 | return available;
67 | }
68 |
69 | private int getRandomPort() {
70 |
71 | int port;
72 |
73 | do{
74 | port = (int) (MIN_PORT_NUMBER + 1 + Math.floor(Math.random()*(MAX_PORT_NUMBER - MIN_PORT_NUMBER-1)));
75 |
76 | if(mDebug)
77 | Log.i("FileReceiver","Trying port : " + port);
78 |
79 | }while(!isPortAvailable(port));
80 |
81 | return port;
82 |
83 | }
84 |
85 | public void getFile(){
86 |
87 | int port = getRandomPort();
88 |
89 | if(mDebug)
90 | Log.i("FileReceiver","Port : " + port);
91 |
92 | i = new Intent(context,ReceiverService.class);
93 |
94 | i.putExtra(PORT,port);
95 | i.putExtra(MESSENGER,new Messenger(mHandler));
96 |
97 | context.startService(i);
98 |
99 | }
100 |
101 | public void close() {
102 | context.stopService(i);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/File Share/src/main/java/io/github/karuppiah7890/fileshare/FileSender.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.fileshare;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.DhcpInfo;
6 | import android.net.wifi.WifiManager;
7 | import android.os.Handler;
8 | import android.os.Messenger;
9 | import android.text.format.Formatter;
10 | import android.util.Log;
11 |
12 | import java.io.File;
13 | import java.net.InetAddress;
14 |
15 | public class FileSender {
16 |
17 | private final boolean mDebug = true;
18 |
19 | private final String PORT = "PORT";
20 | private final String MESSENGER = "MESSENGER";
21 | private final String FILE = "FILE";
22 | private final String RECEIVER_IP = "RECEIVER_IP";
23 |
24 | // Constants start from 1001
25 | public static final int CONNECTING = 1001;
26 | public static final int CONNECTED = 1002;
27 | public static final int SENDING_FILE = 1003;
28 | public static final int FILE_SENT = 1004;
29 | public static final int SEND_ERROR = 1005;
30 |
31 | private Context context;
32 | private int port;
33 | private Handler mHandler;
34 |
35 | private final WifiManager manager;
36 | private final DhcpInfo dhcp;
37 |
38 | Intent i;
39 |
40 | public FileSender(Context context, Handler mHandler) {
41 | this.context = context;
42 | this.mHandler = mHandler;
43 | manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
44 | dhcp = manager.getDhcpInfo();
45 | }
46 |
47 | private InetAddress getMyIP() {
48 | final String address = Formatter.formatIpAddress(dhcp.ipAddress); // ipAddress - IP address of my device, assigned through dhcp
49 | InetAddress myIP = null;
50 |
51 | try {
52 |
53 | myIP = InetAddress.getByName(address);
54 | if(mDebug)
55 | Log.i("FileSender","My IP : " + myIP.toString());
56 |
57 | } catch (Exception e) {
58 | if(mDebug)
59 | Log.e("FileSender","Cannot find my own IP. Error : " + e.toString());
60 | }
61 |
62 | return myIP;
63 | }
64 |
65 | private InetAddress getReceiverIP() {
66 | final String address = Formatter.formatIpAddress(dhcp.gateway); // gateway - default gateway IP address
67 | InetAddress receiverIP = null;
68 |
69 | try {
70 |
71 | receiverIP = InetAddress.getByName(address);
72 |
73 | if(mDebug)
74 | Log.i("FileSender","Receiver IP : " + receiverIP.toString());
75 |
76 | } catch (Exception e) {
77 | if(mDebug)
78 | Log.e("FileSender","Cannot find receiver's IP. Error : " + e.toString());
79 | }
80 |
81 | return receiverIP;
82 | }
83 |
84 | public void sendFile(File file,int code) {
85 |
86 | if(!file.exists()){
87 | mHandler.obtainMessage(SEND_ERROR,"File " + file.getName() + " doesn't exist").sendToTarget();
88 | return;
89 | }
90 |
91 | if(!file.isFile()){
92 | mHandler.obtainMessage(SEND_ERROR,file.getName() + " is a folder, not file").sendToTarget();
93 | return;
94 | }
95 |
96 | this.port = code;
97 |
98 | InetAddress receiverIP = getReceiverIP();
99 |
100 | i = new Intent(context,SenderService.class);
101 |
102 | i.putExtra(RECEIVER_IP,receiverIP);
103 | i.putExtra(PORT,port);
104 | i.putExtra(MESSENGER,new Messenger(mHandler));
105 | i.putExtra(FILE,file);
106 |
107 |
108 | context.startService(i);
109 | }
110 |
111 | public void close() {
112 | if(context!=null && i!=null)
113 | context.stopService(i);
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/File Share/src/main/java/io/github/karuppiah7890/fileshare/ReceiverService.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.fileshare;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.IBinder;
7 | import android.os.Messenger;
8 |
9 | public class ReceiverService extends Service {
10 |
11 | private final String PORT = "PORT";
12 | private final String MESSENGER = "MESSENGER";
13 |
14 | private int port;
15 | private Messenger messenger;
16 |
17 | @Override
18 | public int onStartCommand(Intent intent, int flags, int startId) {
19 |
20 | Bundle b = intent.getExtras();
21 |
22 | port = (int) b.get(PORT);
23 | messenger = (Messenger) b.get(MESSENGER);
24 |
25 | ReceiverThread receiverThread = new ReceiverThread(port,messenger);
26 |
27 | receiverThread.start();
28 |
29 | return START_REDELIVER_INTENT;
30 | }
31 |
32 | @Override
33 | public IBinder onBind(Intent intent) {
34 | return null;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/File Share/src/main/java/io/github/karuppiah7890/fileshare/ReceiverThread.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.fileshare;
2 |
3 | import android.os.Environment;
4 | import android.os.Message;
5 | import android.os.Messenger;
6 | import android.os.RemoteException;
7 | import android.util.Log;
8 |
9 | import java.io.DataInputStream;
10 | import java.io.DataOutputStream;
11 | import java.io.File;
12 | import java.io.FileOutputStream;
13 | import java.io.IOException;
14 | import java.net.ServerSocket;
15 | import java.net.Socket;
16 |
17 | public class ReceiverThread extends Thread {
18 |
19 | private int port;
20 | private Messenger messenger;
21 | private ServerSocket listenerSocket;
22 | private Socket communicationSocket;
23 | private int PKT_SIZE = 60*1024;
24 |
25 | public ReceiverThread(int port,Messenger messenger){
26 | this.port = port;
27 | this.messenger = messenger;
28 | File folder = new File(Environment.getExternalStorageDirectory() + "/FileSharer/");
29 |
30 | folder.mkdirs();
31 | }
32 |
33 | @Override
34 | public void run() {
35 |
36 | Message message;
37 |
38 | try {
39 | listenerSocket = new ServerSocket(port);
40 |
41 | message = Message.obtain();
42 | message.what = FileReceiver.CODE;
43 | message.obj = port;
44 | messenger.send(message);
45 |
46 | message = Message.obtain();
47 | message.what = FileReceiver.LISTENING;
48 | message.obj = "";
49 | messenger.send(message);
50 |
51 | communicationSocket = listenerSocket.accept();
52 |
53 | message = Message.obtain();
54 | message.what = FileReceiver.CONNECTED;
55 | message.obj = "";
56 | messenger.send(message);
57 |
58 | DataInputStream in = new DataInputStream(communicationSocket.getInputStream());
59 |
60 | message = Message.obtain();
61 | message.what = FileReceiver.RECEIVING_FILE;
62 | message.obj = "";
63 | messenger.send(message);
64 |
65 | // Read File Name and create Output Stream
66 | String fileName = in.readUTF();
67 |
68 | File receiveFile = new File(Environment.getExternalStorageDirectory() + "/FileSharer/" + fileName);
69 |
70 | DataOutputStream dout = new DataOutputStream(new FileOutputStream(receiveFile,true));
71 |
72 | // Read File Size
73 | long fileSize = in.readLong();
74 |
75 | int totalLength = 0;
76 | int length = 0;
77 | byte[] receiveData = new byte[PKT_SIZE];
78 |
79 | long startTime = System.currentTimeMillis();
80 |
81 | // Get the file data
82 | while( fileSize>0 && ( ( length = in.read( receiveData,0,(int) Math.min(receiveData.length,fileSize) ))!= -1) )
83 | {
84 | dout.write(receiveData, 0, length);
85 |
86 | totalLength += length;
87 |
88 | fileSize -= length;
89 | }
90 |
91 | long stopTime = System.currentTimeMillis();
92 |
93 | dout.close();
94 |
95 | double time = (stopTime - startTime) / 1000.0;
96 |
97 | double speed = (totalLength / time) / 1048576.0;
98 |
99 | message = Message.obtain();
100 | message.what = FileReceiver.FILE_RECEIVED;
101 | message.obj = receiveFile;
102 |
103 | messenger.send(message);
104 |
105 | } catch (Exception e){
106 |
107 | e.printStackTrace();
108 |
109 | message = Message.obtain();
110 | message.what = FileReceiver.RECEIVE_ERROR;
111 | message.obj = e.toString();
112 |
113 | try {
114 | messenger.send(message);
115 | } catch (RemoteException re) {
116 | Log.e("ReceiverThread","Error in sending an error message! Error : " + re.toString());
117 | re.printStackTrace();
118 | }
119 |
120 | } finally {
121 |
122 | try {
123 |
124 | if(communicationSocket!=null)
125 | communicationSocket.close();
126 |
127 | if(listenerSocket!=null)
128 | listenerSocket.close();
129 |
130 | } catch (IOException ioe) {
131 | Log.e("ReceiverThread","Error in closing sockets. Error : " + ioe.toString());
132 | ioe.printStackTrace();
133 | }
134 | }
135 |
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/File Share/src/main/java/io/github/karuppiah7890/fileshare/SenderService.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.fileshare;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.IBinder;
7 | import android.os.Messenger;
8 |
9 | import java.io.File;
10 | import java.net.InetAddress;
11 |
12 | public class SenderService extends Service {
13 |
14 | private final String PORT = "PORT";
15 | private final String MESSENGER = "MESSENGER";
16 | private final String FILE = "FILE";
17 | private final String RECEIVER_IP = "RECEIVER_IP";
18 |
19 | private InetAddress receiverIP;
20 | private int port;
21 | private Messenger messenger;
22 | private File file;
23 |
24 | @Override
25 | public int onStartCommand(Intent intent, int flags, int startId) {
26 |
27 | Bundle b = intent.getExtras();
28 |
29 | receiverIP = (InetAddress) b.get(RECEIVER_IP);
30 | port = (int) b.get(PORT);
31 | messenger = (Messenger) b.get(MESSENGER);
32 | file = (File) b.get(FILE);
33 |
34 | SenderThread senderThread = new SenderThread(receiverIP,port,file,messenger);
35 |
36 | senderThread.start();
37 |
38 | return START_REDELIVER_INTENT;
39 | }
40 |
41 |
42 | @Override
43 | public IBinder onBind(Intent intent) {
44 | return null;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/File Share/src/main/java/io/github/karuppiah7890/fileshare/SenderThread.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.fileshare;
2 |
3 | import android.os.Message;
4 | import android.os.Messenger;
5 | import android.os.RemoteException;
6 | import android.util.Log;
7 |
8 | import java.io.DataInputStream;
9 | import java.io.DataOutputStream;
10 | import java.io.File;
11 | import java.io.FileInputStream;
12 | import java.io.IOException;
13 | import java.net.InetAddress;
14 | import java.net.Socket;
15 |
16 | public class SenderThread extends Thread {
17 |
18 | private InetAddress receiverIP;
19 | private int port;
20 | private File fileToSend;
21 | private Messenger messenger;
22 | private Socket senderSocket;
23 | private int PKT_SIZE = 60*1024;
24 |
25 | public SenderThread(InetAddress receiverIP, int port, File fileToSend, Messenger messenger){
26 | this.receiverIP = receiverIP;
27 | this.port = port;
28 | this.messenger = messenger;
29 | this.fileToSend = fileToSend;
30 | }
31 |
32 | @Override
33 | public void run() {
34 | Message message;
35 |
36 | try {
37 |
38 | message = Message.obtain();
39 | message.what = FileSender.CONNECTING;
40 | message.obj = "";
41 | messenger.send(message);
42 |
43 | senderSocket = new Socket(receiverIP,port);
44 |
45 | message = Message.obtain();
46 | message.what = FileSender.CONNECTED;
47 | message.obj = "";
48 | messenger.send(message);
49 |
50 | DataOutputStream out = new DataOutputStream(senderSocket.getOutputStream());
51 |
52 | message = Message.obtain();
53 | message.what = FileSender.SENDING_FILE;
54 | message.obj = "";
55 | messenger.send(message);
56 |
57 | // Send File Name
58 | out.writeUTF(fileToSend.getName());
59 |
60 | DataInputStream din = new DataInputStream(new FileInputStream(fileToSend));
61 |
62 | // Send File Size
63 | long fileSize = fileToSend.length();
64 | out.writeLong(fileSize);
65 |
66 | int totalLength = 0;
67 | int length = 0;
68 | byte[] sendData = new byte[PKT_SIZE];
69 |
70 | long startTime = System.currentTimeMillis();
71 |
72 | // Send the file data
73 | while ((length = din.read(sendData)) != -1) {
74 |
75 | out.write(sendData, 0, length);
76 |
77 | totalLength += length;
78 |
79 | }
80 |
81 | long stopTime = System.currentTimeMillis();
82 |
83 | din.close();
84 |
85 | double time = (stopTime - startTime) / 1000.0;
86 |
87 | double speed = (totalLength / time) / 1048576.0;
88 |
89 | message = Message.obtain();
90 | message.what = FileSender.FILE_SENT;
91 | message.obj = "";
92 |
93 | messenger.send(message);
94 |
95 | } catch (Exception e){
96 |
97 | e.printStackTrace();
98 |
99 | message = Message.obtain();
100 | message.what = FileSender.SEND_ERROR;
101 | message.obj = e.toString();
102 |
103 | try {
104 | messenger.send(message);
105 | } catch (RemoteException re) {
106 | Log.e("SenderThread","Error in sending an error message! Error : " + re.toString());
107 | re.printStackTrace();
108 | }
109 |
110 | } finally {
111 |
112 | try {
113 |
114 | if(senderSocket!=null)
115 | senderSocket.close();
116 |
117 | } catch (IOException ioe) {
118 | Log.e("SenderThread","Error in closing sockets. Error : " + ioe.toString());
119 | ioe.printStackTrace();
120 | }
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/File Share/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | File Share
3 |
4 |
--------------------------------------------------------------------------------
/File Share/src/test/java/io/github/karuppiah7890/fileshare/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.fileshare;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/FileSharerDemoApp/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | /build
3 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 | defaultConfig {
7 | applicationId "io.github.karuppiah7890.filesharer"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 |
28 | compile 'com.android.support:appcompat-v7:25.0.0'
29 | compile project(":File Share")
30 | compile 'com.droidninja:filepicker:1.0.6'
31 | testCompile 'junit:junit:4.12'
32 | }
33 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\3521\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/androidTest/java/io/github/karuppiah7890/filesharer/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.filesharer;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("io.github.karuppiah7890.filesharer", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/java/io/github/karuppiah7890/filesharer/DashBoard.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.filesharer;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | public class DashBoard extends AppCompatActivity implements View.OnClickListener {
10 |
11 | Button bSend,bReceive;
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 |
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_dash_board);
18 |
19 | bSend = (Button) findViewById(R.id.bSend);
20 | bReceive = (Button) findViewById(R.id.bReceive);
21 |
22 | bSend.setOnClickListener(this);
23 | bReceive.setOnClickListener(this);
24 | }
25 |
26 | @Override
27 | public void onClick(View view) {
28 | int id = view.getId();
29 |
30 | switch (id){
31 | case R.id.bSend :
32 | startActivity(new Intent(DashBoard.this,SenderActivity.class));
33 | break;
34 |
35 | case R.id.bReceive :
36 | startActivity(new Intent(DashBoard.this,ReceiverActivity.class));
37 | break;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/java/io/github/karuppiah7890/filesharer/ReceiverActivity.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.filesharer;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.os.Looper;
6 | import android.os.Message;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.View;
9 | import android.widget.TextView;
10 | import android.widget.Toast;
11 |
12 | import java.io.File;
13 |
14 | import io.github.karuppiah7890.fileshare.FileReceiver;
15 |
16 | public class ReceiverActivity extends AppCompatActivity {
17 |
18 | FileReceiver fileReceiver;
19 | TextView tvCode;
20 |
21 | private final Handler mHandler = new Handler(Looper.getMainLooper()) {
22 | @Override
23 | public void handleMessage(Message msg) {
24 | switch (msg.what) {
25 | case FileReceiver.CODE :
26 | tvCode.setText((int)msg.obj + "");
27 | break;
28 |
29 | case FileReceiver.LISTENING :
30 | Toast.makeText(ReceiverActivity.this,"Listening...",Toast.LENGTH_SHORT).show();
31 | break;
32 |
33 | case FileReceiver.CONNECTED:
34 | Toast.makeText(ReceiverActivity.this,"Connected!",Toast.LENGTH_SHORT).show();
35 | break;
36 |
37 | case FileReceiver.RECEIVING_FILE :
38 | Toast.makeText(ReceiverActivity.this,"Receiving File!",Toast.LENGTH_SHORT).show();
39 | break;
40 |
41 | case FileReceiver.FILE_RECEIVED :
42 | File file = (File) msg.obj;
43 | Toast.makeText(ReceiverActivity.this,file.getName() + " Received!",Toast.LENGTH_SHORT).show();
44 | Toast.makeText(ReceiverActivity.this,"Stored in " + file.getAbsolutePath(),Toast.LENGTH_SHORT).show();
45 | fileReceiver.close();
46 | break;
47 |
48 | case FileReceiver.RECEIVE_ERROR :
49 | Toast.makeText(ReceiverActivity.this,"Error occured : " + (String)msg.obj,Toast.LENGTH_SHORT).show();
50 | fileReceiver.close();
51 | break;
52 | }
53 | }
54 | };
55 |
56 | public void getFile(View view) {
57 |
58 | fileReceiver = new FileReceiver(this,mHandler);
59 |
60 | fileReceiver.getFile();
61 |
62 | }
63 |
64 | @Override
65 | protected void onCreate(Bundle savedInstanceState) {
66 | super.onCreate(savedInstanceState);
67 | setContentView(R.layout.activity_receiver);
68 |
69 | tvCode = (TextView) findViewById(R.id.tvCode);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/java/io/github/karuppiah7890/filesharer/SenderActivity.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.filesharer;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 | import android.os.Looper;
8 | import android.os.Message;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.util.Log;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.EditText;
14 | import android.widget.Toast;
15 |
16 | import java.io.File;
17 | import java.util.ArrayList;
18 |
19 | import droidninja.filepicker.FilePickerBuilder;
20 | import droidninja.filepicker.FilePickerConst;
21 | import io.github.karuppiah7890.fileshare.FileSender;
22 |
23 | public class SenderActivity extends AppCompatActivity {
24 |
25 | private ArrayList docPaths;
26 | private EditText etCode;
27 | private FileSender fileSender;
28 | Button bPickFile;
29 |
30 | private final Handler mHandler = new Handler(Looper.getMainLooper()) {
31 | @Override
32 | public void handleMessage(Message msg) {
33 | switch (msg.what) {
34 | case FileSender.CONNECTING :
35 | Toast.makeText(SenderActivity.this,"Connecting...",Toast.LENGTH_SHORT).show();
36 | break;
37 |
38 | case FileSender.CONNECTED :
39 | Toast.makeText(SenderActivity.this,"Connected!",Toast.LENGTH_SHORT).show();
40 | break;
41 |
42 | case FileSender.SENDING_FILE :
43 | Toast.makeText(SenderActivity.this,"Sending File!",Toast.LENGTH_SHORT).show();
44 | break;
45 |
46 | case FileSender.FILE_SENT :
47 | Toast.makeText(SenderActivity.this,"File Sent!",Toast.LENGTH_SHORT).show();
48 | fileSender.close();
49 | bPickFile.setEnabled(true);
50 | break;
51 |
52 | case FileSender.SEND_ERROR :
53 | Toast.makeText(SenderActivity.this,"Error occured : " + (String)msg.obj,Toast.LENGTH_SHORT).show();
54 | fileSender.close();
55 | bPickFile.setEnabled(true);
56 | break;
57 | }
58 | }
59 | };
60 |
61 | @Override
62 | protected void onCreate(Bundle savedInstanceState) {
63 | super.onCreate(savedInstanceState);
64 | setContentView(R.layout.activity_sender);
65 |
66 | etCode = (EditText) findViewById(R.id.etCode);
67 | bPickFile = (Button) findViewById(R.id.bPickFile);
68 | }
69 |
70 | private void sendMyFile(String filePath) {
71 |
72 | Log.i("SenderActivity","File Path : " + filePath);
73 | Toast.makeText(this,filePath,Toast.LENGTH_SHORT).show();
74 |
75 | File file = new File(filePath);
76 |
77 | fileSender = new FileSender(this,mHandler);
78 |
79 | if(!etCode.getText().toString().equals("")){
80 | int code = Integer.parseInt(etCode.getText().toString());
81 | fileSender.sendFile(file,code);
82 | }
83 |
84 |
85 | }
86 |
87 | public void pickAFile(View view){
88 | FilePickerBuilder.getInstance().setMaxCount(1)
89 | .setActivityTheme(R.style.AppTheme)
90 | .pickDocument(this);
91 |
92 | view.setEnabled(false);
93 | }
94 |
95 | @Override
96 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
97 | switch (requestCode)
98 | {
99 | case FilePickerConst.REQUEST_CODE_DOC:
100 | if(resultCode== Activity.RESULT_OK && data!=null)
101 | {
102 | docPaths = new ArrayList<>();
103 | docPaths.addAll(data.getStringArrayListExtra(FilePickerConst.KEY_SELECTED_DOCS));
104 | sendMyFile(docPaths.get(0));
105 | }
106 | break;
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/layout/activity_dash_board.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
22 |
23 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/layout/activity_receiver.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
21 |
22 |
31 |
32 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/layout/activity_sender.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
22 |
23 |
33 |
34 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Android-File-Share/FileShare/d90523139f1aec60eacfcf98642f5a14973926a3/FileSharerDemoApp/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Android-File-Share/FileShare/d90523139f1aec60eacfcf98642f5a14973926a3/FileSharerDemoApp/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Android-File-Share/FileShare/d90523139f1aec60eacfcf98642f5a14973926a3/FileSharerDemoApp/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Android-File-Share/FileShare/d90523139f1aec60eacfcf98642f5a14973926a3/FileSharerDemoApp/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Android-File-Share/FileShare/d90523139f1aec60eacfcf98642f5a14973926a3/FileSharerDemoApp/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | File Sharer
3 |
4 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/FileSharerDemoApp/src/test/java/io/github/karuppiah7890/filesharer/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package io.github.karuppiah7890.filesharer;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Karuppiah N
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FileShare
2 |
3 | Now implement LAN file sharing feature in your Android App using FileShare library with ease!
4 |
5 | ## Adding FileShare to your Android project
6 | The library is published in the jCenter repository. So you just add this in your App's `build.gradle` file, in `dependencies` :
7 |
8 | ```gradle
9 | compile 'io.github.karuppiah7890:fileshare:0.1.0'
10 | ```
11 |
12 | ## API Usage
13 | See the [API Usage](https://github.com/Android-File-Share/FileShare/wiki/API-Usage) Wiki page
14 |
15 | ## Demo App
16 |
17 | FileSharer is a Demo App that is built using FileShare library. You can see the source code in the [FileSharerDemoApp](https://github.com/Android-File-Share/FileShare/tree/master/FileSharerDemoApp) folder. The APK for the Demo App is available in the releases.
18 |
19 | I am yet to do some automation. These are the steps to use the App and to see how the Demo App works based on FileShare
20 |
21 | Install the App in two Android devices.
22 |
23 | In Receiver device :
24 |
25 | 1. Create WiFi hotspot
26 | 2. Open App
27 | 3. click "Get File"
28 | 4. The app should show a code on top of the button. And say "Listening" as a Toast
29 |
30 | In Sender device :
31 |
32 | 1. Connect to hotspot created by receiver
33 | 2. Open App
34 | 3. Type the code you saw in Receiver device
35 | 4. Click "Pick File and Send"
36 | 5. Pick a file (only docs can be picked) and select Done on top right
37 |
38 | The file should get sent and you will see Toast messages accordingly in between for "Connected" , "Sending file", "Receiving file" etc in the two devices and finally the Receiver device will also show the location of the stored file as a Toast
39 |
40 |
41 |
42 | ## License
43 | The library is available under [MIT License](https://github.com/Android-File-Share/FileShare/blob/master/LICENSE.md)
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 | classpath 'com.novoda:bintray-release:0.3.4'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Android-File-Share/FileShare/d90523139f1aec60eacfcf98642f5a14973926a3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':FileSharerDemoApp', ':File Share'
2 |
--------------------------------------------------------------------------------