Skip to content
Snippets Groups Projects
Commit bc31d9e1 authored by Peter Joseph De Jonckheere CESM2014's avatar Peter Joseph De Jonckheere CESM2014
Browse files

Added upload file logic

parent 644176da
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ package com.example.pharmacy.frontEnd;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
......@@ -16,6 +17,9 @@ import android.widget.Spinner;
import android.widget.Switch;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
/**
* Created by pharmacy on 16/02/2018.
*/
......@@ -62,7 +66,15 @@ public class AdvancedSettings extends AppCompatActivity {
@Override
public void onClick(View view) {
//DO UPLOAD THINGS HERE
File file = SaveFile.zipFiles(view.getContext());
Intent sendIntent = new Intent(Intent.ACTION_SEND);
if(file.exists() && (file != null)){
sendIntent.setType("notificationapp/zip");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT,"Sharing File...");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Sharing File...");
startActivity(Intent.createChooser(sendIntent, "Share File"));
}
}
});
populateSpinners();
......
......@@ -5,14 +5,19 @@ import android.content.SharedPreferences;
import android.os.Environment;
import android.util.Log;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* Created by pharmacy on 12/02/2018.
......@@ -116,6 +121,43 @@ public class SaveFile {
recordTimeStamp(sent, clicked, acknowledged, context);
}
public static File zipFiles(Context context) {
File file = null;
if (isExternalStorageMounted()) {
File dir = getDirectory(context);
if (dir.isDirectory()) {
file = new File(dir, "ZIPFILE.zip");
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file);
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos));
File[] files = dir.listFiles();
try {
for(int i = 0; i < files.length; i++){
byte[] buffer = new byte[1024];
FileInputStream fis = new FileInputStream(files[i]);
zos.putNextEntry(new ZipEntry(files[i].getName()));
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
fis.close();
}
}
finally {
zos.close();
}
} catch (IOException e) {
}
}
}
return file;
}
public static void recordNotificationType(Context context) {
SharedPreferences shared = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
int sound = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment