用于twilio集成的MY代码如下
try {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message.creator(new com.twilio.type.PhoneNumber("whatsapp:+918002XXXXX"),
new com.twilio.type.PhoneNumber("whatsapp:+1415XXXXXXx"),
"Your appointment is coming up on {{July 21}} at {{3PM}}")
.create();
System.out.println(message.getSid());
}
catch (Exception e){
Toast.makeText(getApplicationContext(), "the error message is"+e, Toast.LENGTH_LONG).show();
}
我使用的依赖项如下
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-firestore:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile group: "com.twilio.sdk", name: "twilio", version: "7.24.2"
implementation 'com.android.support:multidex:1.0.3'
}
我得到的错误是这个
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gsr.schoolreport, PID: 18267
java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar!classes2.dex)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.getSocketFactory(SSLConnectionSocketFactory.java:172)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.getDefaultRegistry(PoolingHttpClientConnectionManager.java:109)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:116)
at com.twilio.http.NetworkHttpClient.<init>(NetworkHttpClient.java:58)
at com.twilio.http.TwilioRestClient$Builder.build(TwilioRestClient.java:102)
at com.twilio.Twilio.getRestClient(Twilio.java:129)
at com.twilio.base.Creator.create(Creator.java:45)
at com.gsr.schoolreport.EditData$3$1.onComplete(EditData.java:236)
at com.google.android.gms.tasks.zzf.run(Unknown Source:23)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
应用程序终止。 请帮助我,过去一个月都面对这个问题
答案 0 :(得分:0)
这里是Twilio开发人员的传播者。
似乎您要尝试的是Twilio Java Helper Library,因为它使用Apache Commons,因此Android不支持。尽管我们只有一个用于语音,聊天(不是WhatsApp)和视频的软件,但您想与Android一起使用的是Android SDK之一。
因此,如果您想将WhatsApp集成到您的android应用程序中,建议您使用任何您喜欢的后端编程语言创建一个后端,并让您的应用程序对此进行HTTP请求。
您最终将获得相同的功能,但是您的代码中将没有嵌入任何凭据。
看看我过去写的this article,它解释了如何使用SMS进行操作,因此您只需对其进行更改即可使用WhatsApp。