-1
我正在使用短信管理器發送帶有發送的待處理意向和遞送掛起意向的短信。我的應用程序只使用短信發送功能,我也放在這個權限短信管理器不能正常工作
<uses-permission android:name="android.permission.SEND_SMS"/>
這是我在一個片段的OnAcitivityCreated
方法代碼:
try {
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(getActivity().getApplicationContext(), 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(getActivity().getApplicationContext(), 0,
new Intent(DELIVERED), 0);
//PendingIntent sentPI;
//String SENT = "SMS_SENT";
// sentPI = PendingIntent.getBroadcast(getActivity().getApplicationContext(), 0,new Intent(getActivity().getApplicationContext(),MainActivity.class), 0);
getActivity().registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getActivity().getApplicationContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getActivity().getApplicationContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getActivity().getApplicationContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getActivity().getApplicationContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getActivity().getApplicationContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
},new IntentFilter(SENT));
SmsManager smsmanager = SmsManager.getDefault();
smsmanager.sendTextMessage("+923349521400", null, message, sentPI, deliveredPI);
Toast.makeText(getActivity(), "Sms sent!", Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Toast.makeText(getActivity(), "failure", Toast.LENGTH_LONG).show();
}
代碼沒有響應任何內容,或者您收到任何崩潰或任何您想要的內容。哪部分不工作? – Smit
代碼沒有做任何事情。 –