Send message to specific number whatsapp android? -
how can send message specific number in whatsapp.
i searched , found code
uri uri = uri.parse("smsto:" + number); intent = new intent(intent.action_sendto, uri); i.putextra("sms_body", "as sdj ajs"); i.setpackage("com.whatsapp"); startactivity(i);
it opens number's chat window no message displayed in edit text.
also tried
cursor c = getcontentresolver().query(contactscontract.data.content_uri, new string[] { contactscontract.contacts.data._id }, contactscontract.data.data1 + "=?", new string[] { "number@s.whatsapp.net" }, null); c.movetofirst(); intent = new intent(intent.action_view, uri.parse("content://com.android.contacts/data/" + c.getstring(0))); startactivity(i); c.close();
but force closes app
android.database.cursorindexoutofboundsexception: index 0 requested, size of 0 @ android.database.abstractcursor.checkposition(abstractcursor.java:426) @ android.database.abstractwindowedcursor.checkposition(abstractwindowedcursor.java:136) @ android.database.abstractwindowedcursor.getstring(abstractwindowedcursor.java:50) @ android.database.cursorwrapper.getstring(cursorwrapper.java:114) @ com.appprix.app.applauncher.whatsappshare(applauncher.java:113) @ appprix.refer.referfragment.onclick(referfragment.java:74) @ android.view.view.performclick(view.java:4575) @ android.view.view$performclick.run(view.java:18578) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5127) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:825) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:641) @ dalvik.system.nativestart.main(native method)
do way
public void onclickwhatsapp(view view) { packagemanager pm=getpackagemanager(); try { intent waintent = new intent(intent.action_send); waintent.settype("text/plain"); string text = "your text here"; packageinfo info=pm.getpackageinfo("com.whatsapp", packagemanager.get_meta_data); //check if package exists or not. if not code //in catch block called waintent.setpackage("com.whatsapp"); waintent.putextra(intent.extra_text, text); startactivity(intent.createchooser(waintent, "share with")); } catch (namenotfoundexception e) { toast.maketext(this, "whatsapp not installed", toast.length_short) .show(); } }
Comments
Post a Comment