我在我的应用程序中使用内置消息应用程序来发送消息,但是在发送消息之后它只会卡在那里,而在发送消息时它应该意图回到我的应用程序我该怎么做。
public void sendSmsIntent(String phoneNumber) {
Intent intent2 = new Intent(Intent.ACTION_SENDTO);
intent2.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber)));
startActivity(intent2);
}
答案 0 :(得分:-1)
在您要发送短信的任何地方调用sendSMS()方法;
private void sendSMS()
{
PendingIntent sent = this.createPendingResult(SENT, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendDataMessage(strcontactnumber, null, SMS_PORT, messageText.getBytes(), sent, null);
}
onActivityResult();
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
String toast = null;
switch (requestCode)
{
case SENT :
switch (resultCode)
{
case RESULT_OK :
toast = "OK";
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE :
toast = "Generic Failure";
break;
case SmsManager.RESULT_ERROR_RADIO_OFF :
toast = "Radio Off";
break;
case SmsManager.RESULT_ERROR_NULL_PDU :
toast = "Null Pdu";
break;
}
break;
}
if (toast != null)
{
Toast.makeText(this, toast, Toast.LENGTH_LONG).show();
}
}
它将直接从您的应用发送短信,而无需调用原生应用
And if you want to return back to your app by your code then
It is possible. Just need to add the following extra to your intent:
sendIntent.putExtra("exit_on_sent", true);