Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无需打开意图,以渐进方式向whatsapp号发送文本_Android_Kotlin - Fatal编程技术网

Android 无需打开意图,以渐进方式向whatsapp号发送文本

Android 无需打开意图,以渐进方式向whatsapp号发送文本,android,kotlin,Android,Kotlin,我有一个向Whatsapp号码发送短信的代码。然而,每当我发送消息时,它就会打开Whatsapp。如何在不打开Whatsapp应用程序的情况下发送短信 String smsNumber = "9230......."; Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my te

我有一个向Whatsapp号码发送短信的代码。然而,每当我发送消息时,它就会打开Whatsapp。如何在不打开Whatsapp应用程序的情况下发送短信

String smsNumber = "9230......."; 
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");  
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);

你不能这样做,因为WhatsApp不提供。 因此,在安卓系统中做事情的合法方式是使用意图


但是,如果您真的想向WhatsApp发送消息并使其自动化,我想您可以创建一个关注WhatsApp包事件的应用程序,打开应用程序发送消息,然后自动关闭它。请记住,这不是一个解决方案这是一个黑客的解决方法,不应该在生产中使用,只是出于兴趣,我认为这样做是可行的。

只有使用安卓系统才能做到这一点

这个想法很简单,你可以让Android执行Whatsapp的发送按钮

因此,流程将是:

发送一条带有您当前使用意图的常规消息,并在消息内容末尾添加后缀,如“我的_”应用程序发送的消息

一旦文本出现,您的可访问性服务将被通知WhatsApp的EditText已填充

如果WhatsApp的编辑文本中有后缀,您的辅助功能服务将单击发送按钮。这是为了避免在用户键入常规消息时执行操作

有关更多信息,请查看代码链接