por para mensajes masivos macro from envio enviar desde como automaticos android android-intent contact whatsapp

android - para - mensajes automaticos whatsapp iphone



Enviar texto a contacto específico mediante programación(whatsapp) (14)

Quería saber cómo puedo enviar mensajes de texto a un contacto específico de WhatsApp. Encontré un código para ver un contacto específico, pero no para enviar datos.

Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Contacts.Data._ID }, ContactsContract.Data.DATA1 + "=?", new String[] { id }, null); c.moveToFirst(); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/" + c.getString(0))); startActivity(i); c.close();

Esto funciona bien para ver un contacto de whatsapp, pero ¿cómo puedo agregar algo de texto ahora? ¿O el desarrollador de Whatsapp no ​​implementó ese tipo de API?


¡Lo he hecho!

private void openWhatsApp() { String smsNumber = "7****"; // E164 format without ''+'' sign Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); sendIntent.putExtra("jid", smsNumber + "@s.whatsapp.net"); //phone number without "+" prefix sendIntent.setPackage("com.whatsapp"); if (intent.resolveActivity(getActivity().getPackageManager()) == null) { Toast.makeText(this, "Error/n" + e.toString(), Toast.LENGTH_SHORT).show(); return; } startActivity(sendIntent); }


¡prueba esto, funcionó para mí! . Solo use la intención

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(whatsappUrl())); startActivity(intent);

Crea url de whatsapp. agregue el código de país en el número de teléfono de whatsapp https://countrycode.org/

public static String whatsappUrl(){ final String BASE_URL = "https://api.whatsapp.com/"; final String WHATSAPP_PHONE_NUMBER = "628123232323"; //''62'' is country code for Indonesia final String PARAM_PHONE_NUMBER = "phone"; final String PARAM_TEXT = "text"; final String TEXT_VALUE = "Hello, How are you ?"; String newUrl = BASE_URL + "send"; Uri builtUri = Uri.parse(newUrl).buildUpon() .appendQueryParameter(PARAM_PHONE_NUMBER, WHATSAPP_PHONE_NUMBER) .appendQueryParameter(PARAM_TEXT, TEXT_VALUE) .build(); return buildUrl(builtUri).toString(); } public static URL buildUrl(Uri myUri){ URL finalUrl = null; try { finalUrl = new URL(myUri.toString()); } catch (MalformedURLException e) { e.printStackTrace(); } return finalUrl; }


Creo que la respuesta es una mezcla de su pregunta y esta respuesta aquí: https://.com/a/15931345/734687 Así que probaría el siguiente código:

  1. cambiar ACTION_VIEW a ACTION_SENDTO
  2. establece el Uri como lo hiciste
  3. configura el paquete para whatsapp

Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse("content://com.android.contacts/data/" + c.getString(0))); i.setType("text/plain"); i.setPackage("com.whatsapp"); // so that only Whatsapp reacts and not the chooser i.putExtra(Intent.EXTRA_SUBJECT, "Subject"); i.putExtra(Intent.EXTRA_TEXT, "I''m the body."); startActivity(i);

Busqué en el manifiesto de Whatsapp y vi que ACTION_SEND está registrado en la actividad ContactPicker , por lo que no te servirá de nada. Sin embargo, ACTION_SENDTO está registrado en la actividad com.whatsapp.Conversation que suena más adecuada para su problema.

Whatsapp puede funcionar como un reemplazo para enviar SMS, por lo que debería funcionar como un SMS. Cuando no especifica la aplicación deseada (a través de setPackage ), Android muestra el selector de aplicaciones. Por lo tanto, solo debe mirar el código para enviar SMS a través del intento y luego proporcionar la información adicional del paquete.

Uri uri = Uri.parse("smsto:" + smsNumber); Intent i = new Intent(Intent.ACTION_SENDTO, uri); i.putExtra("sms_body", smsText); i.setPackage("com.whatsapp"); startActivity(i);

Primero intente reemplazar el intento ACTION_SEND por ACTION_SENDTO . Si esto no funciona, proporcione el sms_body extra sms_body . Si esto no funciona, intente cambiar el uri.

Actualización Intenté resolver esto yo mismo y no pude encontrar una solución. Whatsapp está abriendo el historial de chat, pero no toma el texto y lo envía. Parece que esta funcionalidad simplemente no está implementada.


Encontré la manera correcta de hacer esto y es simple después de leer este artículo: http://howdygeeks.com/send-whatsapp-message-unsaved-number-android/

el teléfono y el mensaje son ambos String.

Código fuente:

PackageManager packageManager = context.getPackageManager(); Intent i = new Intent(Intent.ACTION_VIEW); try { String url = "https://api.whatsapp.com/send?phone="+ phone +"&text=" + URLEncoder.encode(message, "UTF-8"); i.setPackage("com.whatsapp"); i.setData(Uri.parse(url)); if (i.resolveActivity(packageManager) != null) { context.startActivity(i); } } catch (Exception e){ e.printStackTrace(); }

¡Disfrutar!


Esto primero buscará el contacto especificado y luego abrirá una ventana de chat. Y si WhatsApp no ​​está instalado, entonces try-catch block maneja esto.

String digits = "//d+"; Sring mob_num = 987654321; if (mob_num.matches(digits)) { try { /linking for whatsapp Uri uri = Uri.parse("whatsapp://send?phone=+91" + mob_num); Intent i = new Intent(Intent.ACTION_VIEW, uri); startActivity(i); } catch (ActivityNotFoundException e){ e.printStackTrace(); Toast.makeText(this, "WhatsApp not installed.", Toast.LENGTH_SHORT).show(); } }


Esto primero buscará el contacto especificado y luego abrirá una ventana de chat.

Nota: phone_number y str son variables.

Uri mUri = Uri.parse("https://api.whatsapp.com/send? phone=" + phone_no + "&text=" + str); Intent mIntent = new Intent("android.intent.action.VIEW", mUri); mIntent.setPackage("com.whatsapp"); startActivity(mIntent);


La nueva característica de Whatsapp ha llegado, prueba estos

Intent sendIntent = new Intent("android.intent.action.MAIN"); sendIntent.setAction(Intent.ACTION_VIEW); sendIntent.setPackage("com.whatsapp"); String url = "https://api.whatsapp.com/send?phone=" + "Phone with international format" + "&text=" + "your message"; sendIntent.setData(Uri.parse(url)); startActivity(sendIntent);

Credits

Ver esta documentación


Mira mi respuesta: https://.com/a/40285262/5879376

Intent sendIntent = new Intent("android.intent.action.MAIN"); sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.Conversation")); sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("YOUR_PHONE_NUMBER")+"@s.whatsapp.net");//phone number without "+" prefix startActivity(sendIntent);


Te permite abrir la pantalla de conversación de WhatsApp para ese usuario específico con el que intentas comunicarte:

private void openWhatsApp() { String smsNumber = "91XXXXXXXX20"; boolean isWhatsappInstalled = whatsappInstalledOrNot("com.whatsapp"); if (isWhatsappInstalled) { Intent sendIntent = new Intent("android.intent.action.MAIN"); sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation")); sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(smsNumber) + "@s.whatsapp.net");//phone number without "+" prefix startActivity(sendIntent); } else { Uri uri = Uri.parse("market://details?id=com.whatsapp"); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show(); startActivity(goToMarket); } } private boolean whatsappInstalledOrNot(String uri) { PackageManager pm = getPackageManager(); boolean app_installed = false; try { pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); app_installed = true; } catch (PackageManager.NameNotFoundException e) { app_installed = false; } return app_installed; }


Verifica esta respuesta. Aquí su número comienza con "91 **********".

Intent sendIntent = new Intent("android.intent.action.MAIN"); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); sendIntent.putExtra("jid",PhoneNumberUtils.stripSeparators("91**********") + "@s.whatsapp.net"); sendIntent.setPackage("com.whatsapp"); startActivity(sendIntent);


¡Este enfoque también funciona con la aplicación de WhatsApp Business!

Cambie el nombre del paquete como sendIntent.setPackage ("com.whatsapp.w4b"); para WhatsApp Business.

Gran truco Rishabh, muchas gracias, estaba buscando esta solución desde los últimos 3 años.

De acuerdo con la respuesta anterior de Rishabh Maurya, he implementado este código que está funcionando bien para compartir texto e imágenes en WhatsApp.

Tenga en cuenta que en ambos casos abre una conversación de whatsapp (si toNume existe en la lista de contactos de WhatsApp de los usuarios), pero el usuario debe hacer clic en el botón enviar para completar la acción. Eso significa que ayuda a omitir el paso de selección de contacto.

Para mensajes de texto

String toNumber = "+91 98765 43210"; // contains spaces. toNumber = toNumber.replace("+", "").replace(" ", ""); Intent sendIntent = new Intent("android.intent.action.MAIN"); sendIntent.putExtra("jid", toNumber + "@s.whatsapp.net"); sendIntent.putExtra(Intent.EXTRA_TEXT, message); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setPackage("com.whatsapp"); sendIntent.setType("text/plain"); startActivity(sendIntent);

Para compartir imágenes

String toNumber = "+91 98765 43210"; // contains spaces. toNumber = toNumber.replace("+", "").replace(" ", ""); Intent sendIntent = new Intent("android.intent.action.MAIN"); sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile)); sendIntent.putExtra("jid", toNumber + "@s.whatsapp.net"); sendIntent.putExtra(Intent.EXTRA_TEXT, message); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setPackage("com.whatsapp"); sendIntent.setType("image/png"); context.startActivity(sendIntent);

¡Disfruta WhatsApping!


String toNumber = "+92307 8401217"; // contains spaces. toNumber = toNumber.replace("+", "").replace(" ", ""); Intent sendIntent = new Intent("android.intent.action.MAIN"); sendIntent.putExtra("jid", toNumber + "@s.whatsapp.net"); sendIntent.putExtra(Intent.EXTRA_TEXT, "message"); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setPackage("com.whatsapp"); sendIntent.setType("text/plain"); startActivity(sendIntent);


private void openWhatsApp() { //without ''+'' try { Intent sendIntent = new Intent("android.intent.action.MAIN"); //sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation")); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra("jid",whatsappId); sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); sendIntent.setPackage("com.whatsapp"); startActivity(sendIntent); } catch(Exception e) { Toast.makeText(this, "Error/n" + e.toString(), Toast.LENGTH_SHORT).show(); Log.e("Error",e+"") ; } }


Bitmap bmp = null; bmp = ((BitmapDrawable) tmpimg.getDrawable()).getBitmap(); Uri bmpUri = null; try { File file = new File(getBaseContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".jpg"); FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 90, out); out.close(); bmpUri = Uri.fromFile(file); } catch (IOException e) { e.printStackTrace(); } String toNumber = "+919999999999"; toNumber = toNumber.replace("+", "").replace(" ", ""); Intent shareIntent =new Intent("android.intent.action.MAIN"); shareIntent.setAction(Intent.ACTION_SEND); String ExtraText; ExtraText = "Share Text"; shareIntent.putExtra(Intent.EXTRA_TEXT, ExtraText); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); shareIntent.setType("image/jpg"); shareIntent.setPackage("com.whatsapp"); shareIntent.putExtra("jid", toNumber + "@s.whatsapp.net"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { startActivity(shareIntent); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(getBaseContext(), "Sharing tools have not been installed.", Toast.LENGTH_SHORT).show(); } }