0
A
回答
1
在這裏,我分享我的工作短信插件。請試試這個。我希望這能幫到您。如果有任何問題讓我知道。
SmsPlugin.java
package org.apache.cordova.plugin;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
public class SmsPlugin extends CordovaPlugin {
public final String ACTION_SEND_SMS = "SendSMS";
@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (action.equals(ACTION_SEND_SMS)) {
try {
String phoneNumber = args.getString(0);
String message = args.getString(1);
String method = args.getString(2);
if(method.equalsIgnoreCase("INTENT")){
invokeSMSIntent(phoneNumber, message);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.NO_RESULT));
} else{
sendSMS(phoneNumber, message);
}
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
return true;
}
catch (JSONException ex) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
}
}
return false;
}
private void invokeSMSIntent(String phoneNumber, String message) {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", message);
sendIntent.setType("vnd.android-dir/mms-sms");
this.cordova.getActivity().startActivity(sendIntent);
}
private void sendSMS(String phoneNumber, String message) {
SmsManager manager = SmsManager.getDefault();
PendingIntent sentIntent = PendingIntent.getActivity(this.cordova.getActivity(), 0, new Intent(), 0);
manager.sendTextMessage(phoneNumber, null, message, sentIntent, null);
}
}
的index.html
$(document).ready(function() {
$("#btnDefaultSMS").click(function(){
var number = $("#numberTxt").val();
var message = $("#messageTxt").val();
SmsPlugin.prototype.send(number, message, 'INTENT',
function() {
alert('Message sent successfully');
},
function (e) {
alert('Message Failed:' + e);
}
);
});
});
HTML部分
<div data-role="fieldcontain">
<input name="" id="numberTxt" placeholder="Enter mobile number" value="" type="tel" data-mini="true"><br>
<textarea name="" id="messageTxt" placeholder="Enter message" data-mini="false"></textarea>
<br>
<input id="btnDefaultSMS" type="submit" data-theme="e" value="Send SMS" data-mini="false">
<input id="btnShare" type="submit" data-theme="e" value="Share" data-mini="false">
</div>
smsplugin.js
var SmsPlugin = function() {};
SmsPlugin.prototype.send = function (phone, message, method, successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'SmsPlugin', "SendSMS", [phone, message, method]);
};
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin("sms", new SmsPlugin());
});
config.xml中
<feature name="SmsPlugin">
<param name="android-package" value="org.apache.cordova.plugin.SmsPlugin"/>
</feature>
1
我從PhoneGap的發送SMS,通過創建與使用SMS協議的鏈路,類似的按鈕使用本地SMS發送方bradorego's suggestion另一個問題:
<a href="sms:/* phone number here */?body=/* body text here */">Link</a>
相關問題
- 1. Android發送短信
- 2. Android發送短信
- 3. 發送使用短信管理短信羣發android系統
- 4. &符號在短信 - 短信發送android
- 5. Android:使用互聯網發送短信
- 6. 使用Android發送全長短信
- 7. 使用Twilio發送短信android
- 8. 如何使用短信管理器將短信發送到android
- 9. Android:更新發送短信的方法發送短信
- 10. 使用.net發送短信
- 11. 使用VB.NET發送短信
- 12. 使用Sikuli發送短信
- 13. 使用API發送短信
- 14. 使用Java發送短信
- 15. 使用Ruby發送短信
- 16. 發送短信使用Python
- 17. 使用BulkSMS.com發送短信
- 18. 使用C#發送短信
- 19. 使用GPRS發送短信
- 20. 延遲短信發送ANDROID
- 21. Android發送大量短信
- 22. 在Android中發送短信,
- 23. 攔截髮送短信android
- 24. Android發送短信JS
- 25. 發送短信錯誤Android
- 26. Catch發送短信(Android 2.2)
- 27. Android刪除發送短信
- 28. 短信發送時間android
- 29. Android:發送即時短信
- 30. 權限發送短信android
你可能會給我一個樣本嗎?一個工作項目會很好。謝謝 –
如果我的回答是正確的,那麼接受它,以便它對其他人有用。只要嘗試使用上面的代碼並正確配置即可。如果有問題,請讓我知道 –
它不起作用 –