public static WhatsappApi getInstance() { if (instance == null) instance = new WhatsappApi(); return instance; }
public synchronized void sendMessage(final List<WContact> contacts, final WMessage message, final Context context, final SendMessageListener listener) throws IOException, WhatsappNotInstalledException { if (isWhatsappInstalled()) { new AsyncTask<Void, Void, Boolean>() { @Override }.execute(); } else throw new WhatsappNotInstalledException();
public synchronized void getContacts(Context context, final GetContactsListener listener) throws WhatsappNotInstalledException { if (isWhatsappInstalled()) { new AsyncTask<Void, Void, List<WContact>>() { @Override protected List<WContact> doInBackground(Void... params) { Shell.SU.run("am force-stop com.whatsapp"); db = SQLiteDatabase.openOrCreateDatabase(new File("/data/data/com.whatsapp/databases/wa.db"), null); List<WContact> contactList = new LinkedList<>(); String selectQuery = "SELECT jid, display_name FROM wa_contacts where phone_type is not null and is_whatsapp_user = 1"; Cursor cursor = db.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { WContact contact = new WContact(cursor.getString(1), cursor.getString(0)); contactList.add(contact); } while (cursor.moveToNext()); } db.close(); return contactList; } @Override protected void onPostExecute(List<WContact> contacts) { super.onPostExecute(contacts); if (listener != null) { listener.receiveWhatsappContacts(contacts); } } }.execute(); } else throw new WhatsappNotInstalledException(); }
mReceivers = new LinkedList<>(); if (!WhatsappApi.getInstance().isWhatsappInstalled()) { Toast.makeText(this, "Whatsapp not installed", Toast.LENGTH_SHORT).show(); return; if (!WhatsappApi.getInstance().isRootAvailable()) { Toast.makeText(this, "Root is not available", Toast.LENGTH_SHORT).show(); return; WhatsappApi.getInstance().getContacts(this, new GetContactsListener() { @Override public void receiveWhatsappContacts(List<WContact> contacts) { e.printStackTrace();
switch (message.getType()) { case TEXT: break; case VIDEO: name = message.getFile().getPath(); c = Calendar.getInstance(); df = new SimpleDateFormat("yyyyMMMdd"); source = new File(name); rand = new Random(); destination = new File(vidFolder, "VID-" + formattedDate + "-WA" + (rand.nextInt(100) + rand.nextInt(75) + rand.nextInt(50)) + "." + FilenameUtils.getExtension(message.getFile().getName())); if (source.exists()) { FileChannel src = new FileInputStream(source).getChannel(); break; case IMAGE: name = message.getFile().getPath(); c = Calendar.getInstance(); df = new SimpleDateFormat("yyyyMMdd"); source = new File(name); rand = new Random(); destination = new File(imgFolder, "IMG-" + formattedDate + "-WA" + (rand.nextInt(100) + rand.nextInt(75) + rand.nextInt(50)) + "." + FilenameUtils.getExtension(message.getFile().getName())); if (source.exists()) { FileChannel src = new FileInputStream(source).getChannel(); break; case AUDIO: name = message.getFile().getPath();
WMessage message = new WMessage(text, attachmentFile, this); WhatsappApi.getInstance().sendMessage(mReceivers, message, this, new SendMessageListener() { @Override public void finishSendWMessage(List<WContact> contact, WMessage message) { e.printStackTrace();
public void sendMessage(WContact contact, WMessage message, Context context, SendMessageListener listener) throws IOException, WhatsappNotInstalledException { List<WContact> contacts = new LinkedList<>(); contacts.add(contact); sendMessage(contacts, message, context, listener); }
public WMessage(String text, File file, Context context) { this.text = text; this.file = file; if (file != null) { mime = Utils.getMimeType(context, file); if (mime == null) type = MessageType.TEXT; else if (mime.contains("video")) type = MessageType.VIDEO; else if (mime.contains("audio")) type = MessageType.AUDIO; else if (mime.contains("image")) type = MessageType.IMAGE; } else type = MessageType.TEXT; }