0% found this document useful (0 votes)
2 views

Codes bluetooth email camera - converted

The document contains Java code snippets for Bluetooth device discovery and sending emails using SMTP with Gmail, as well as sending SMS messages using Twilio. It includes error handling for email sending and location retrieval, and utilizes classes such as DiscoveryListener and Session for Bluetooth and email functionalities. Additionally, it demonstrates the integration of user location retrieval and display in a GUI application.

Uploaded by

suhaskadam0011
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Codes bluetooth email camera - converted

The document contains Java code snippets for Bluetooth device discovery and sending emails using SMTP with Gmail, as well as sending SMS messages using Twilio. It includes error handling for email sending and location retrieval, and utilizes classes such as DiscoveryListener and Session for Bluetooth and email functionalities. Additionally, it demonstrates the integration of user location retrieval and display in a GUI application.

Uploaded by

suhaskadam0011
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Bluetooth code :- send email code :- System.err.println("Error sending email: " + e.

send email code :- System.err.println("Error sending email: " + e.getMessage()); Bluetooth code :- send email code :- System.err.println("Error sending email: " + e.getMessage()); Bluetooth code :- send email code :- System.err.println("Error sending email: " + e.getMessage());

import javax.bluetooth.*; import java.util.Properties; } import javax.bluetooth.*; import java.util.Properties; } import javax.bluetooth.*; import java.util.Properties; }

import javax.microedition.io.*; import javax.mail.*; } import javax.microedition.io.*; import javax.mail.*; } import javax.microedition.io.*; import javax.mail.*; }

import java.io.IOException; import javax.mail.internet.*; public static void main(String[] args) { import java.io.IOException; import javax.mail.internet.*; public static void main(String[] args) { import java.io.IOException; import javax.mail.internet.*; public static void main(String[] args) {

public class BluetoothExample { public class SendEmail { // Replace with recipient email, subject and message body public class BluetoothExample { public class SendEmail { // Replace with recipient email, subject and message body public class BluetoothExample { public class SendEmail { // Replace with recipient email, subject and message body

public static void main(String[] args) { private static final String SMTP_HOST = "smtp.gmail.com"; String toEmail = "[email protected]"; public static void main(String[] args) { private static final String SMTP_HOST = "smtp.gmail.com"; String toEmail = "[email protected]"; public static void main(String[] args) { private static final String SMTP_HOST = "smtp.gmail.com"; String toEmail = "[email protected]";

try { private static final String SMTP_PORT = "587"; String subject = "Test Email from Java"; try { private static final String SMTP_PORT = "587"; String subject = "Test Email from Java"; try { private static final String SMTP_PORT = "587"; String subject = "Test Email from Java";

final Object inquiryCompletedEvent = new Object(); private static final String USERNAME = "[email protected]"; String body = "Hello!\nThis is a simple email sent from Java."; final Object inquiryCompletedEvent = new Object(); private static final String USERNAME = "[email protected]"; String body = "Hello!\nThis is a simple email sent from Java."; final Object inquiryCompletedEvent = new Object(); private static final String USERNAME = "[email protected]"; String body = "Hello!\nThis is a simple email sent from Java.";

DiscoveryListener listener = new DiscoveryListener() { private static final String PASSWORD = "your_email_password_or_app_password"; sendEmail(toEmail, subject, body); DiscoveryListener listener = new DiscoveryListener() { private static final String PASSWORD = "your_email_password_or_app_password"; sendEmail(toEmail, subject, body); DiscoveryListener listener = new DiscoveryListener() { private static final String PASSWORD = "your_email_password_or_app_password"; sendEmail(toEmail, subject, body);

public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { public static void sendEmail(String toEmail, String subject, String body) { } public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { public static void sendEmail(String toEmail, String subject, String body) { } public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { public static void sendEmail(String toEmail, String subject, String body) { }

try { Properties props = new Properties(); } try { Properties props = new Properties(); } try { Properties props = new Properties(); }

System.out.println("Device found: " + btDevice.getFriendlyName(false)); props.put("mail.smtp.auth", "true"); </content> System.out.println("Device found: " + btDevice.getFriendlyName(false)); props.put("mail.smtp.auth", "true"); </content> System.out.println("Device found: " + btDevice.getFriendlyName(false)); props.put("mail.smtp.auth", "true"); </content>

} catch (IOException e) { props.put("mail.smtp.starttls.enable", "true"); </create_file> } catch (IOException e) { props.put("mail.smtp.starttls.enable", "true"); </create_file> } catch (IOException e) { props.put("mail.smtp.starttls.enable", "true"); </create_file>

System.out.println("Device found: " + btDevice.getBluetoothAddress()); props.put("mail.smtp.host", SMTP_HOST); System.out.println("Device found: " + btDevice.getBluetoothAddress()); props.put("mail.smtp.host", SMTP_HOST); System.out.println("Device found: " + btDevice.getBluetoothAddress()); props.put("mail.smtp.host", SMTP_HOST);

} props.put("mail.smtp.port", SMTP_PORT); } props.put("mail.smtp.port", SMTP_PORT); } props.put("mail.smtp.port", SMTP_PORT);

} Session session = Session.getInstance(props, new Authenticator() { } Session session = Session.getInstance(props, new Authenticator() { } Session session = Session.getInstance(props, new Authenticator() {

public void inquiryCompleted(int discType) { protected PasswordAuthentication getPasswordAuthentication() { public void inquiryCompleted(int discType) { protected PasswordAuthentication getPasswordAuthentication() { public void inquiryCompleted(int discType) { protected PasswordAuthentication getPasswordAuthentication() {

synchronized (inquiryCompletedEvent) { return new PasswordAuthentication(USERNAME, PASSWORD); synchronized (inquiryCompletedEvent) { return new PasswordAuthentication(USERNAME, PASSWORD); synchronized (inquiryCompletedEvent) { return new PasswordAuthentication(USERNAME, PASSWORD);

inquiryCompletedEvent.notifyAll(); } inquiryCompletedEvent.notifyAll(); } inquiryCompletedEvent.notifyAll(); }

} }); } }); } });

} try { } try { } try {

public void serviceSearchCompleted(int transID, int respCode) {} Message message = new MimeMessage(session); public void serviceSearchCompleted(int transID, int respCode) {} Message message = new MimeMessage(session); public void serviceSearchCompleted(int transID, int respCode) {} Message message = new MimeMessage(session);

public void servicesDiscovered(int transID, ServiceRecord[] records) {} message.setFrom(new InternetAddress(USERNAME)); public void servicesDiscovered(int transID, ServiceRecord[] records) {} message.setFrom(new InternetAddress(USERNAME)); public void servicesDiscovered(int transID, ServiceRecord[] records) {} message.setFrom(new InternetAddress(USERNAME));

}; message.setRecipients( }; message.setRecipients( }; message.setRecipients(

DiscoveryAgent agent = LocalDevice.getLocalDevice().getDiscoveryAgent(); Message.RecipientType.TO, InternetAddress.parse(toEmail)); DiscoveryAgent agent = LocalDevice.getLocalDevice().getDiscoveryAgent(); Message.RecipientType.TO, InternetAddress.parse(toEmail)); DiscoveryAgent agent = LocalDevice.getLocalDevice().getDiscoveryAgent(); Message.RecipientType.TO, InternetAddress.parse(toEmail));

agent.startInquiry(DiscoveryAgent.PREKNOWN, listener); message.setSubject(subject); agent.startInquiry(DiscoveryAgent.PREKNOWN, listener); message.setSubject(subject); agent.startInquiry(DiscoveryAgent.PREKNOWN, listener); message.setSubject(subject);

synchronized (inquiryCompletedEvent) { message.setText(body); synchronized (inquiryCompletedEvent) { message.setText(body); synchronized (inquiryCompletedEvent) { message.setText(body);

inquiryCompletedEvent.wait(); Transport.send(message); inquiryCompletedEvent.wait(); Transport.send(message); inquiryCompletedEvent.wait(); Transport.send(message);

} System.out.println("Email sent successfully to " + toEmail); } System.out.println("Email sent successfully to " + toEmail); } System.out.println("Email sent successfully to " + toEmail);

} catch (BluetoothStateException | InterruptedException e) { } catch (MessagingException e) { } catch (BluetoothStateException | InterruptedException e) { } catch (MessagingException e) { } catch (BluetoothStateException | InterruptedException e) { } catch (MessagingException e) {

e.printStackTrace(); }}} e.printStackTrace(); e.printStackTrace(); }}} e.printStackTrace(); e.printStackTrace(); }}} e.printStackTrace();

1 2 3 1 2 3 1 2 3

Sms code :- Current location code :- String inputLine; Sms code :- Current location code :- String inputLine; Sms code :- Current location code :- String inputLine;

import com.twilio.Twilio; import java.awt.HeadlessException; StringBuilder response = new StringBuilder(); import com.twilio.Twilio; import java.awt.HeadlessException; StringBuilder response = new StringBuilder(); import com.twilio.Twilio; import java.awt.HeadlessException; StringBuilder response = new StringBuilder();

import com.twilio.rest.api.v2010.account.Message; import javax.swing.JFrame; while ((inputLine = in.readLine()) != null) { import com.twilio.rest.api.v2010.account.Message; import javax.swing.JFrame; while ((inputLine = in.readLine()) != null) { import com.twilio.rest.api.v2010.account.Message; import javax.swing.JFrame; while ((inputLine = in.readLine()) != null) {

import com.twilio.type.PhoneNumber; import javax.swing.JLabel; response.append(inputLine); import com.twilio.type.PhoneNumber; import javax.swing.JLabel; response.append(inputLine); import com.twilio.type.PhoneNumber; import javax.swing.JLabel; response.append(inputLine);

import java.io.BufferedReader; } import java.io.BufferedReader; } import java.io.BufferedReader; }

public class SendSms { import java.io.InputStreamReader; in.close(); public class SendSms { import java.io.InputStreamReader; in.close(); public class SendSms { import java.io.InputStreamReader; in.close();

// Replace these with your Twilio account details import java.net.HttpURLConnection; // Replace these with your Twilio account details import java.net.HttpURLConnection; // Replace these with your Twilio account details import java.net.HttpURLConnection;

public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID"; import java.net.URL; JSONObject json = new JSONObject(response.toString()); public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID"; import java.net.URL; JSONObject json = new JSONObject(response.toString()); public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID"; import java.net.URL; JSONObject json = new JSONObject(response.toString());

public static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN"; import org.json.JSONObject; if ("success".equals(json.getString("status"))) { public static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN"; import org.json.JSONObject; if ("success".equals(json.getString("status"))) { public static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN"; import org.json.JSONObject; if ("success".equals(json.getString("status"))) {

result = "City: " + json.getString("city") + ", Region: " + json.getString("regionName") + result = "City: " + json.getString("city") + ", Region: " + json.getString("regionName") + result = "City: " + json.getString("city") + ", Region: " + json.getString("regionName") +

public static void main(String[] args) { public class UserLocation extends JFrame { ", Country: " + json.getString("country") + "<br>Latitude: " + json.getDouble("lat") + public static void main(String[] args) { public class UserLocation extends JFrame { ", Country: " + json.getString("country") + "<br>Latitude: " + json.getDouble("lat") + public static void main(String[] args) { public class UserLocation extends JFrame { ", Country: " + json.getString("country") + "<br>Latitude: " + json.getDouble("lat") +

// Initialize the Twilio client public UserLocation() throws HeadlessException { ", Longitude: " + json.getDouble("lon"); // Initialize the Twilio client public UserLocation() throws HeadlessException { ", Longitude: " + json.getDouble("lon"); // Initialize the Twilio client public UserLocation() throws HeadlessException { ", Longitude: " + json.getDouble("lon");

Twilio.init(ACCOUNT_SID, AUTH_TOKEN); setTitle("User Current Location"); } Twilio.init(ACCOUNT_SID, AUTH_TOKEN); setTitle("User Current Location"); } Twilio.init(ACCOUNT_SID, AUTH_TOKEN); setTitle("User Current Location"); }

// Your Twilio phone number (or sender ID) setSize(400, 200); } catch (Exception e) { // Your Twilio phone number (or sender ID) setSize(400, 200); } catch (Exception e) { // Your Twilio phone number (or sender ID) setSize(400, 200); } catch (Exception e) {

String fromPhone = "+12345678901"; // Replace with your Twilio number setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); result = "Error retrieving location"; String fromPhone = "+12345678901"; // Replace with your Twilio number setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); result = "Error retrieving location"; String fromPhone = "+12345678901"; // Replace with your Twilio number setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); result = "Error retrieving location";

// Recipient phone number setLocationRelativeTo(null); } // Recipient phone number setLocationRelativeTo(null); } // Recipient phone number setLocationRelativeTo(null); }

String toPhone = "+10987654321"; // Replace with recipient's phone number return result; String toPhone = "+10987654321"; // Replace with recipient's phone number return result; String toPhone = "+10987654321"; // Replace with recipient's phone number return result;

String location = getUserLocation(); } String location = getUserLocation(); } String location = getUserLocation(); }

// Message to send JLabel label = new JLabel("<html>Your Approximate Location:<br>" + location + "</html>"); public static void main(String[] args) { // Message to send JLabel label = new JLabel("<html>Your Approximate Location:<br>" + location + "</html>"); public static void main(String[] args) { // Message to send JLabel label = new JLabel("<html>Your Approximate Location:<br>" + location + "</html>"); public static void main(String[] args) {

String messageBody = "Hello from Java via Twilio!"; add(label); javax.swing.SwingUtilities.invokeLater(() -> { String messageBody = "Hello from Java via Twilio!"; add(label); javax.swing.SwingUtilities.invokeLater(() -> { String messageBody = "Hello from Java via Twilio!"; add(label); javax.swing.SwingUtilities.invokeLater(() -> {

// Send the SMS message } UserLocation app = new UserLocation(); // Send the SMS message } UserLocation app = new UserLocation(); // Send the SMS message } UserLocation app = new UserLocation();

Message message = Message.creator( public String getUserLocation() { app.setVisible(true); Message message = Message.creator( public String getUserLocation() { app.setVisible(true); Message message = Message.creator( public String getUserLocation() { app.setVisible(true);

new PhoneNumber(toPhone), String result = "Location not available"; }); new PhoneNumber(toPhone), String result = "Location not available"; }); new PhoneNumber(toPhone), String result = "Location not available"; });

new PhoneNumber(fromPhone), try { } new PhoneNumber(fromPhone), try { } new PhoneNumber(fromPhone), try { }

messageBody) // Use ip-api.com to fetch user location based on IP } messageBody) // Use ip-api.com to fetch user location based on IP } messageBody) // Use ip-api.com to fetch user location based on IP }

.create(); String urlStr = "http://ip-api.com/json"; </content> .create(); String urlStr = "http://ip-api.com/json"; </content> .create(); String urlStr = "http://ip-api.com/json"; </content>

// Print the message SID (for reference) URL url = new URL(urlStr); </create_file> // Print the message SID (for reference) URL url = new URL(urlStr); </create_file> // Print the message SID (for reference) URL url = new URL(urlStr); </create_file>

System.out.println("SMS sent successfully. Message SID: " + message.getSid()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); System.out.println("SMS sent successfully. Message SID: " + message.getSid()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); System.out.println("SMS sent successfully. Message SID: " + message.getSid()); HttpURLConnection conn = (HttpURLConnection) url.openConnection();

} conn.setRequestMethod("GET"); } conn.setRequestMethod("GET"); } conn.setRequestMethod("GET");

} BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); } BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); } BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

</content> </create_file> </content> </create_file> </content> </create_file>

4 5 6 4 5 6 4 5 6

Camera code :- Camera code :- Camera code :-


import org.opencv.core.Core; import org.opencv.core.Core; import org.opencv.core.Core;

import org.opencv.core.Mat; import org.opencv.core.Mat; import org.opencv.core.Mat;

import org.opencv.highgui.HighGui; import org.opencv.highgui.HighGui; import org.opencv.highgui.HighGui;

import org.opencv.videoio.VideoCapture; import org.opencv.videoio.VideoCapture; import org.opencv.videoio.VideoCapture;

public class CameraCapture { public class CameraCapture { public class CameraCapture {

static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }

public static void main(String[] args) { public static void main(String[] args) { public static void main(String[] args) {

VideoCapture camera = new VideoCapture(0); // 0 is the default camera VideoCapture camera = new VideoCapture(0); // 0 is the default camera VideoCapture camera = new VideoCapture(0); // 0 is the default camera

Mat frame = new Mat(); Mat frame = new Mat(); Mat frame = new Mat();

if (!camera.isOpened()) { if (!camera.isOpened()) { if (!camera.isOpened()) {

System.out.println("Error: Camera is not available."); System.out.println("Error: Camera is not available."); System.out.println("Error: Camera is not available.");

return; return; return;

} } }

camera.read(frame); // Capture a frame camera.read(frame); // Capture a frame camera.read(frame); // Capture a frame

if (!frame.empty()) { if (!frame.empty()) { if (!frame.empty()) {

HighGui.imshow("Captured Image", frame); // Display the captured image HighGui.imshow("Captured Image", frame); // Display the captured image HighGui.imshow("Captured Image", frame); // Display the captured image

HighGui.waitKey(0); // Wait for a key press HighGui.waitKey(0); // Wait for a key press HighGui.waitKey(0); // Wait for a key press

} else { } else { } else {

System.out.println("Error: No frame captured."); System.out.println("Error: No frame captured."); System.out.println("Error: No frame captured.");

} } }

camera.release(); // Release the camera camera.release(); // Release the camera camera.release(); // Release the camera

} } }

} } }

7 8 7 8 7 8

Bluetooth code :- send email code :- System.err.println("Error sending email: " + e.getMessage()); Bluetooth code :- send email code :- System.err.println("Error sending email: " + e.getMessage()); Bluetooth code :- send email code :- System.err.println("Error sending email: " + e.getMessage());

import javax.bluetooth.*; import java.util.Properties; } import javax.bluetooth.*; import java.util.Properties; } import javax.bluetooth.*; import java.util.Properties; }

import javax.microedition.io.*; import javax.mail.*; } import javax.microedition.io.*; import javax.mail.*; } import javax.microedition.io.*; import javax.mail.*; }

import java.io.IOException; import javax.mail.internet.*; public static void main(String[] args) { import java.io.IOException; import javax.mail.internet.*; public static void main(String[] args) { import java.io.IOException; import javax.mail.internet.*; public static void main(String[] args) {

public class BluetoothExample { public class SendEmail { // Replace with recipient email, subject and message body public class BluetoothExample { public class SendEmail { // Replace with recipient email, subject and message body public class BluetoothExample { public class SendEmail { // Replace with recipient email, subject and message body

public static void main(String[] args) { private static final String SMTP_HOST = "smtp.gmail.com"; String toEmail = "[email protected]"; public static void main(String[] args) { private static final String SMTP_HOST = "smtp.gmail.com"; String toEmail = "[email protected]"; public static void main(String[] args) { private static final String SMTP_HOST = "smtp.gmail.com"; String toEmail = "[email protected]";

try { private static final String SMTP_PORT = "587"; String subject = "Test Email from Java"; try { private static final String SMTP_PORT = "587"; String subject = "Test Email from Java"; try { private static final String SMTP_PORT = "587"; String subject = "Test Email from Java";

final Object inquiryCompletedEvent = new Object(); private static final String USERNAME = "[email protected]"; String body = "Hello!\nThis is a simple email sent from Java."; final Object inquiryCompletedEvent = new Object(); private static final String USERNAME = "[email protected]"; String body = "Hello!\nThis is a simple email sent from Java."; final Object inquiryCompletedEvent = new Object(); private static final String USERNAME = "[email protected]"; String body = "Hello!\nThis is a simple email sent from Java.";

DiscoveryListener listener = new DiscoveryListener() { private static final String PASSWORD = "your_email_password_or_app_password"; sendEmail(toEmail, subject, body); DiscoveryListener listener = new DiscoveryListener() { private static final String PASSWORD = "your_email_password_or_app_password"; sendEmail(toEmail, subject, body); DiscoveryListener listener = new DiscoveryListener() { private static final String PASSWORD = "your_email_password_or_app_password"; sendEmail(toEmail, subject, body);

public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { public static void sendEmail(String toEmail, String subject, String body) { } public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { public static void sendEmail(String toEmail, String subject, String body) { } public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { public static void sendEmail(String toEmail, String subject, String body) { }

try { Properties props = new Properties(); } try { Properties props = new Properties(); } try { Properties props = new Properties(); }

System.out.println("Device found: " + btDevice.getFriendlyName(false)); props.put("mail.smtp.auth", "true"); </content> System.out.println("Device found: " + btDevice.getFriendlyName(false)); props.put("mail.smtp.auth", "true"); </content> System.out.println("Device found: " + btDevice.getFriendlyName(false)); props.put("mail.smtp.auth", "true"); </content>

} catch (IOException e) { props.put("mail.smtp.starttls.enable", "true"); </create_file> } catch (IOException e) { props.put("mail.smtp.starttls.enable", "true"); </create_file> } catch (IOException e) { props.put("mail.smtp.starttls.enable", "true"); </create_file>

System.out.println("Device found: " + btDevice.getBluetoothAddress()); props.put("mail.smtp.host", SMTP_HOST); System.out.println("Device found: " + btDevice.getBluetoothAddress()); props.put("mail.smtp.host", SMTP_HOST); System.out.println("Device found: " + btDevice.getBluetoothAddress()); props.put("mail.smtp.host", SMTP_HOST);

} props.put("mail.smtp.port", SMTP_PORT); } props.put("mail.smtp.port", SMTP_PORT); } props.put("mail.smtp.port", SMTP_PORT);

} Session session = Session.getInstance(props, new Authenticator() { } Session session = Session.getInstance(props, new Authenticator() { } Session session = Session.getInstance(props, new Authenticator() {

public void inquiryCompleted(int discType) { protected PasswordAuthentication getPasswordAuthentication() { public void inquiryCompleted(int discType) { protected PasswordAuthentication getPasswordAuthentication() { public void inquiryCompleted(int discType) { protected PasswordAuthentication getPasswordAuthentication() {

synchronized (inquiryCompletedEvent) { return new PasswordAuthentication(USERNAME, PASSWORD); synchronized (inquiryCompletedEvent) { return new PasswordAuthentication(USERNAME, PASSWORD); synchronized (inquiryCompletedEvent) { return new PasswordAuthentication(USERNAME, PASSWORD);

inquiryCompletedEvent.notifyAll(); } inquiryCompletedEvent.notifyAll(); } inquiryCompletedEvent.notifyAll(); }

} }); } }); } });

} try { } try { } try {

public void serviceSearchCompleted(int transID, int respCode) {} Message message = new MimeMessage(session); public void serviceSearchCompleted(int transID, int respCode) {} Message message = new MimeMessage(session); public void serviceSearchCompleted(int transID, int respCode) {} Message message = new MimeMessage(session);

public void servicesDiscovered(int transID, ServiceRecord[] records) {} message.setFrom(new InternetAddress(USERNAME)); public void servicesDiscovered(int transID, ServiceRecord[] records) {} message.setFrom(new InternetAddress(USERNAME)); public void servicesDiscovered(int transID, ServiceRecord[] records) {} message.setFrom(new InternetAddress(USERNAME));

}; message.setRecipients( }; message.setRecipients( }; message.setRecipients(

DiscoveryAgent agent = LocalDevice.getLocalDevice().getDiscoveryAgent(); Message.RecipientType.TO, InternetAddress.parse(toEmail)); DiscoveryAgent agent = LocalDevice.getLocalDevice().getDiscoveryAgent(); Message.RecipientType.TO, InternetAddress.parse(toEmail)); DiscoveryAgent agent = LocalDevice.getLocalDevice().getDiscoveryAgent(); Message.RecipientType.TO, InternetAddress.parse(toEmail));

agent.startInquiry(DiscoveryAgent.PREKNOWN, listener); message.setSubject(subject); agent.startInquiry(DiscoveryAgent.PREKNOWN, listener); message.setSubject(subject); agent.startInquiry(DiscoveryAgent.PREKNOWN, listener); message.setSubject(subject);

synchronized (inquiryCompletedEvent) { message.setText(body); synchronized (inquiryCompletedEvent) { message.setText(body); synchronized (inquiryCompletedEvent) { message.setText(body);

inquiryCompletedEvent.wait(); Transport.send(message); inquiryCompletedEvent.wait(); Transport.send(message); inquiryCompletedEvent.wait(); Transport.send(message);

} System.out.println("Email sent successfully to " + toEmail); } System.out.println("Email sent successfully to " + toEmail); } System.out.println("Email sent successfully to " + toEmail);

} catch (BluetoothStateException | InterruptedException e) { } catch (MessagingException e) { } catch (BluetoothStateException | InterruptedException e) { } catch (MessagingException e) { } catch (BluetoothStateException | InterruptedException e) { } catch (MessagingException e) {

e.printStackTrace(); }}} e.printStackTrace(); e.printStackTrace(); }}} e.printStackTrace(); e.printStackTrace(); }}} e.printStackTrace();

1 2 3 1 2 3 1 2 3

Sms code :- Current location code :- String inputLine; Sms code :- Current location code :- String inputLine; Sms code :- Current location code :- String inputLine;

import com.twilio.Twilio; import java.awt.HeadlessException; StringBuilder response = new StringBuilder(); import com.twilio.Twilio; import java.awt.HeadlessException; StringBuilder response = new StringBuilder(); import com.twilio.Twilio; import java.awt.HeadlessException; StringBuilder response = new StringBuilder();

import com.twilio.rest.api.v2010.account.Message; import javax.swing.JFrame; while ((inputLine = in.readLine()) != null) { import com.twilio.rest.api.v2010.account.Message; import javax.swing.JFrame; while ((inputLine = in.readLine()) != null) { import com.twilio.rest.api.v2010.account.Message; import javax.swing.JFrame; while ((inputLine = in.readLine()) != null) {

import com.twilio.type.PhoneNumber; import javax.swing.JLabel; response.append(inputLine); import com.twilio.type.PhoneNumber; import javax.swing.JLabel; response.append(inputLine); import com.twilio.type.PhoneNumber; import javax.swing.JLabel; response.append(inputLine);

import java.io.BufferedReader; } import java.io.BufferedReader; } import java.io.BufferedReader; }

public class SendSms { import java.io.InputStreamReader; in.close(); public class SendSms { import java.io.InputStreamReader; in.close(); public class SendSms { import java.io.InputStreamReader; in.close();

// Replace these with your Twilio account details import java.net.HttpURLConnection; // Replace these with your Twilio account details import java.net.HttpURLConnection; // Replace these with your Twilio account details import java.net.HttpURLConnection;

public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID"; import java.net.URL; JSONObject json = new JSONObject(response.toString()); public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID"; import java.net.URL; JSONObject json = new JSONObject(response.toString()); public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID"; import java.net.URL; JSONObject json = new JSONObject(response.toString());

public static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN"; import org.json.JSONObject; if ("success".equals(json.getString("status"))) { public static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN"; import org.json.JSONObject; if ("success".equals(json.getString("status"))) { public static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN"; import org.json.JSONObject; if ("success".equals(json.getString("status"))) {

result = "City: " + json.getString("city") + ", Region: " + json.getString("regionName") + result = "City: " + json.getString("city") + ", Region: " + json.getString("regionName") + result = "City: " + json.getString("city") + ", Region: " + json.getString("regionName") +

public static void main(String[] args) { public class UserLocation extends JFrame { ", Country: " + json.getString("country") + "<br>Latitude: " + json.getDouble("lat") + public static void main(String[] args) { public class UserLocation extends JFrame { ", Country: " + json.getString("country") + "<br>Latitude: " + json.getDouble("lat") + public static void main(String[] args) { public class UserLocation extends JFrame { ", Country: " + json.getString("country") + "<br>Latitude: " + json.getDouble("lat") +

// Initialize the Twilio client public UserLocation() throws HeadlessException { ", Longitude: " + json.getDouble("lon"); // Initialize the Twilio client public UserLocation() throws HeadlessException { ", Longitude: " + json.getDouble("lon"); // Initialize the Twilio client public UserLocation() throws HeadlessException { ", Longitude: " + json.getDouble("lon");

Twilio.init(ACCOUNT_SID, AUTH_TOKEN); setTitle("User Current Location"); } Twilio.init(ACCOUNT_SID, AUTH_TOKEN); setTitle("User Current Location"); } Twilio.init(ACCOUNT_SID, AUTH_TOKEN); setTitle("User Current Location"); }

// Your Twilio phone number (or sender ID) setSize(400, 200); } catch (Exception e) { // Your Twilio phone number (or sender ID) setSize(400, 200); } catch (Exception e) { // Your Twilio phone number (or sender ID) setSize(400, 200); } catch (Exception e) {

String fromPhone = "+12345678901"; // Replace with your Twilio number setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); result = "Error retrieving location"; String fromPhone = "+12345678901"; // Replace with your Twilio number setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); result = "Error retrieving location"; String fromPhone = "+12345678901"; // Replace with your Twilio number setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); result = "Error retrieving location";

// Recipient phone number setLocationRelativeTo(null); } // Recipient phone number setLocationRelativeTo(null); } // Recipient phone number setLocationRelativeTo(null); }

String toPhone = "+10987654321"; // Replace with recipient's phone number return result; String toPhone = "+10987654321"; // Replace with recipient's phone number return result; String toPhone = "+10987654321"; // Replace with recipient's phone number return result;

String location = getUserLocation(); } String location = getUserLocation(); } String location = getUserLocation(); }

// Message to send JLabel label = new JLabel("<html>Your Approximate Location:<br>" + location + "</html>"); public static void main(String[] args) { // Message to send JLabel label = new JLabel("<html>Your Approximate Location:<br>" + location + "</html>"); public static void main(String[] args) { // Message to send JLabel label = new JLabel("<html>Your Approximate Location:<br>" + location + "</html>"); public static void main(String[] args) {

String messageBody = "Hello from Java via Twilio!"; add(label); javax.swing.SwingUtilities.invokeLater(() -> { String messageBody = "Hello from Java via Twilio!"; add(label); javax.swing.SwingUtilities.invokeLater(() -> { String messageBody = "Hello from Java via Twilio!"; add(label); javax.swing.SwingUtilities.invokeLater(() -> {

// Send the SMS message } UserLocation app = new UserLocation(); // Send the SMS message } UserLocation app = new UserLocation(); // Send the SMS message } UserLocation app = new UserLocation();

Message message = Message.creator( public String getUserLocation() { app.setVisible(true); Message message = Message.creator( public String getUserLocation() { app.setVisible(true); Message message = Message.creator( public String getUserLocation() { app.setVisible(true);

new PhoneNumber(toPhone), String result = "Location not available"; }); new PhoneNumber(toPhone), String result = "Location not available"; }); new PhoneNumber(toPhone), String result = "Location not available"; });

new PhoneNumber(fromPhone), try { } new PhoneNumber(fromPhone), try { } new PhoneNumber(fromPhone), try { }

messageBody) // Use ip-api.com to fetch user location based on IP } messageBody) // Use ip-api.com to fetch user location based on IP } messageBody) // Use ip-api.com to fetch user location based on IP }

.create(); String urlStr = "http://ip-api.com/json"; </content> .create(); String urlStr = "http://ip-api.com/json"; </content> .create(); String urlStr = "http://ip-api.com/json"; </content>

// Print the message SID (for reference) URL url = new URL(urlStr); </create_file> // Print the message SID (for reference) URL url = new URL(urlStr); </create_file> // Print the message SID (for reference) URL url = new URL(urlStr); </create_file>

System.out.println("SMS sent successfully. Message SID: " + message.getSid()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); System.out.println("SMS sent successfully. Message SID: " + message.getSid()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); System.out.println("SMS sent successfully. Message SID: " + message.getSid()); HttpURLConnection conn = (HttpURLConnection) url.openConnection();

} conn.setRequestMethod("GET"); } conn.setRequestMethod("GET"); } conn.setRequestMethod("GET");

} BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); } BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); } BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

</content> </create_file> </content> </create_file> </content> </create_file>

4 5 6 4 5 6 4 5 6

Camera code :- Camera code :- Camera code :-


import org.opencv.core.Core; import org.opencv.core.Core; import org.opencv.core.Core;

import org.opencv.core.Mat; import org.opencv.core.Mat; import org.opencv.core.Mat;

import org.opencv.highgui.HighGui; import org.opencv.highgui.HighGui; import org.opencv.highgui.HighGui;

import org.opencv.videoio.VideoCapture; import org.opencv.videoio.VideoCapture; import org.opencv.videoio.VideoCapture;

public class CameraCapture { public class CameraCapture { public class CameraCapture {

static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }

public static void main(String[] args) { public static void main(String[] args) { public static void main(String[] args) {

VideoCapture camera = new VideoCapture(0); // 0 is the default camera VideoCapture camera = new VideoCapture(0); // 0 is the default camera VideoCapture camera = new VideoCapture(0); // 0 is the default camera

Mat frame = new Mat(); Mat frame = new Mat(); Mat frame = new Mat();

if (!camera.isOpened()) { if (!camera.isOpened()) { if (!camera.isOpened()) {

System.out.println("Error: Camera is not available."); System.out.println("Error: Camera is not available."); System.out.println("Error: Camera is not available.");

return; return; return;

} } }

camera.read(frame); // Capture a frame camera.read(frame); // Capture a frame camera.read(frame); // Capture a frame

if (!frame.empty()) { if (!frame.empty()) { if (!frame.empty()) {

HighGui.imshow("Captured Image", frame); // Display the captured image HighGui.imshow("Captured Image", frame); // Display the captured image HighGui.imshow("Captured Image", frame); // Display the captured image

HighGui.waitKey(0); // Wait for a key press HighGui.waitKey(0); // Wait for a key press HighGui.waitKey(0); // Wait for a key press

} else { } else { } else {

System.out.println("Error: No frame captured."); System.out.println("Error: No frame captured."); System.out.println("Error: No frame captured.");

} } }

camera.release(); // Release the camera camera.release(); // Release the camera camera.release(); // Release the camera

} } }

} } }

7 8 7 8 7 8

Bluetooth code :- send email code :- System.err.println("Error sending email: " + e.getMessage());

import javax.bluetooth.*; import java.util.Properties; }

import javax.microedition.io.*; import javax.mail.*; }

import java.io.IOException; import javax.mail.internet.*; public static void main(String[] args) {

public class BluetoothExample { public class SendEmail { // Replace with recipient email, subject and message body

public static void main(String[] args) { private static final String SMTP_HOST = "smtp.gmail.com"; String toEmail = "[email protected]";

try { private static final String SMTP_PORT = "587"; String subject = "Test Email from Java";

final Object inquiryCompletedEvent = new Object(); private static final String USERNAME = "[email protected]"; String body = "Hello!\nThis is a simple email sent from Java.";

DiscoveryListener listener = new DiscoveryListener() { private static final String PASSWORD = "your_email_password_or_app_password"; sendEmail(toEmail, subject, body);

public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { public static void sendEmail(String toEmail, String subject, String body) { }

try { Properties props = new Properties(); }

System.out.println("Device found: " + btDevice.getFriendlyName(false)); props.put("mail.smtp.auth", "true"); </content>

} catch (IOException e) { props.put("mail.smtp.starttls.enable", "true"); </create_file>

System.out.println("Device found: " + btDevice.getBluetoothAddress()); props.put("mail.smtp.host", SMTP_HOST);

} props.put("mail.smtp.port", SMTP_PORT);

} Session session = Session.getInstance(props, new Authenticator() {

public void inquiryCompleted(int discType) { protected PasswordAuthentication getPasswordAuthentication() {

synchronized (inquiryCompletedEvent) { return new PasswordAuthentication(USERNAME, PASSWORD);

inquiryCompletedEvent.notifyAll(); }

} });

} try {

public void serviceSearchCompleted(int transID, int respCode) {} Message message = new MimeMessage(session);

public void servicesDiscovered(int transID, ServiceRecord[] records) {} message.setFrom(new InternetAddress(USERNAME));

}; message.setRecipients(

DiscoveryAgent agent = LocalDevice.getLocalDevice().getDiscoveryAgent(); Message.RecipientType.TO, InternetAddress.parse(toEmail));

agent.startInquiry(DiscoveryAgent.PREKNOWN, listener); message.setSubject(subject);

synchronized (inquiryCompletedEvent) { message.setText(body);

inquiryCompletedEvent.wait(); Transport.send(message);

} System.out.println("Email sent successfully to " + toEmail);

} catch (BluetoothStateException | InterruptedException e) { } catch (MessagingException e) {

e.printStackTrace(); }}} e.printStackTrace();

1 2 3

Sms code :-
import com.twilio.Twilio;

import com.twilio.rest.api.v2010.account.Message;

import com.twilio.type.PhoneNumber;

public class SendSms {

// Replace these with your Twilio account details

public static final String ACCOUNT_SID = "YOUR_ACCOUNT_SID";

public static final String AUTH_TOKEN = "YOUR_AUTH_TOKEN";

public static void main(String[] args) {

// Initialize the Twilio client

Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

// Your Twilio phone number (or sender ID)

String fromPhone = "+12345678901"; //

You might also like