gpt4 book ai didi

android - 向特定联系人发送 Whatsapp 消息

转载 作者:IT老高 更新时间:2023-10-28 23:23:32 25 4
gpt4 key购买 nike

我关注了 link这是我的代码

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/" + "MYNUMBER@s.whatsapp.net"));
i.setPackage("com.whatsapp");
startActivity(i);

这是我的日志

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://com.android.contacts/data/MYNUMBER@s.whatsapp.net pkg=com.whatsapp }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.app.Activity.startActivityForResult(Activity.java:3312)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:824)
at android.app.Activity.startActivity(Activity.java:3522)
at android.app.Activity.startActivity(Activity.java:3490)
at com.sieryuu.maidchan.MainActivity.onClick(MainActivity.java:61)
at android.view.View.performClick(View.java:4147)
at android.view.View$PerformClick.run(View.java:17161)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)

我的问题:如何在后台向whatsapp联系人发送文本(不选择联系人号码,我已经知道ID)? (如果需要)

最佳答案

我找到了执行此操作的正确方法,并且在您阅读本文后很简单:http://howdygeeks.com/send-whatsapp-message-unsaved-number-android/

电话和消息都是字符串。

源代码:

try {
PackageManager packageManager = context.getPackageManager();
Intent i = new Intent(Intent.ACTION_VIEW);
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();
}

享受吧!

关于android - 向特定联系人发送 Whatsapp 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18892396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com