我从twilio号码收到消息通知后做了很多研发。
场景来自一个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)