我在接收来自 twilio number 的消息通知方面做了很多研发。
场景是从一个 twilio 应用程序,一个发送消息到另一个 twilio 号码,然后应用程序中的另一个 twilio 号码,必须接收该特定应用程序的通知。
我曾尝试发送通知,但没有找到任何东西来解决这个问题。
建议我做什么,当有人将消息发送到特定的 twilio 号码时,在应用程序中接收消息作为通知。
Log.i("sendNotificationMethod","sendNotificationMethod");
/* Instantiate a new Twilio Rest Client */
TwilioRestClient client = new TwilioRestClient(sub_sid, sub_auth_token);
// Get the account and call factory class
Account acct = client.getAccount();
SmsFactory smsFactory = acct.getSmsFactory();
//build map of server admins
Map<String,String> admins = new HashMap<String,String>();
admins.put("12056108304", "Johnny");
admins.put("12053405623", "Helen");
admins.put("4158675311", "Virgil");
String fromNumber = sms_fromm;
Log.i("fromNumber", fromNumber);
// Iterate over all our server admins
for (String toNumber : admins.keySet()) {
//build map of post parameters
Map<String,String> params = new HashMap<String,String>();
params.put("From", fromNumber);
params.put("To", toNumber);
params.put("Body", "Bad news1111 " + admins.get(toNumber) + ", the server is down and it needs your help");
try {
// send an sms a call
// ( This makes a POST request to the SMS/Messages resource)
Sms sms = smsFactory.create(params);
Log.i("sms.getStatus()", sms.getStatus().toString());
Log.i("Success sending SMS: ","" + sms.getSid());
}
catch (TwilioRestException e) {
e.printStackTrace();
}
}
我使用上面的代码发送通知并使用 lib 文件 twilio-java. 我收到没有此类方法错误的错误。意味着它没有找到 TwilioRestClient 方法
03-21 13:19:11.223: E/AndroidRuntime(296): FATAL EXCEPTION: main
03-21 13:19:11.223: E/AndroidRuntime(296): java.lang.NoSuchMethodError: org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.<init>
03-21 13:19:11.223: E/AndroidRuntime(296): at com.twilio.sdk.TwilioRestClient.<init>(TwilioRestClient.java:137)
03-21 13:19:11.223: E/AndroidRuntime(296): at com.twilio.sdk.TwilioRestClient.<init>(TwilioRestClient.java:108)
03-21 13:19:11.223: E/AndroidRuntime(296): at com.zoemultiline.sms.SMS_In_Out.initializeView(SMS_In_Out.java:200)
03-21 13:19:11.223: E/AndroidRuntime(296): at com.zoemultiline.sms.SMS_In_Out.onCreate(SMS_In_Out.java:185)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.view.View.performClick(View.java:2408)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.view.View$PerformClick.run(View.java:8816)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.os.Handler.handleCallback(Handler.java:587)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.os.Handler.dispatchMessage(Handler.java:92)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.os.Looper.loop(Looper.java:123)
03-21 13:19:11.223: E/AndroidRuntime(296): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-21 13:19:11.223: E/AndroidRuntime(296): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 13:19:11.223: E/AndroidRuntime(296): at java.lang.reflect.Method.invoke(Method.java:521)
03-21 13:19:11.223: E/AndroidRuntime(296): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-21 13:19:11.223: E/AndroidRuntime(296): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-21 13:19:11.223: E/AndroidRuntime(296): at dalvik.system.NativeStart.main(Native Method)