Android开发中调用系统短信功能,发送短信后如何判断短信已发送成功?调用打电话功能,如何监听通话状态?

时间:2021-09-22 08:54:10
我是这样做的但没有效果,请各位同道的兄弟们赐教:
我已配置了 <uses-permission android:name="android.permission.CALL_PHONE" />
           <uses-permission android:name="android.permission.SEND_SMS"/>
           <uses-permission android:name="android.permission.RECEIVE_SMS"/>  所需的权限。

定义了方法:private void sendMsg(String number, String message){
     String SENT = "sms_sent";
     String DELIVERED = "sms_delivered";
     
     PendingIntent sentPI = PendingIntent.getActivity(this, 0, new Intent(SENT), 0);
     PendingIntent deliveredPI = PendingIntent.getActivity(this, 0, new Intent(DELIVERED), 0);
     
     registerReceiver(new BroadcastReceiver(){

             @Override
             public void onReceive(Context context, Intent intent) {
                 switch(getResultCode())
                 {
                     case Activity.RESULT_OK:
                     {
                         Log.i("====>", "Activity.RESULT_OK");
                     }
                         break;
                     case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                         Log.i("====>", "RESULT_ERROR_GENERIC_FAILURE");
                         break;
                     case SmsManager.RESULT_ERROR_NO_SERVICE:
                         Log.i("====>", "RESULT_ERROR_NO_SERVICE");
                         break;
                     case SmsManager.RESULT_ERROR_NULL_PDU:
                         Log.i("====>", "RESULT_ERROR_NULL_PDU");
                         break;
                     case SmsManager.RESULT_ERROR_RADIO_OFF:
                         Log.i("====>", "RESULT_ERROR_RADIO_OFF");
                         break;
                 }
             }
     }, new IntentFilter(SENT));
     
     registerReceiver(new BroadcastReceiver(){
         @Override
         public void onReceive(Context context, Intent intent){
             switch(getResultCode())
             {
                 case Activity.RESULT_OK:
                     Log.i("====>", "RESULT_OK");
                     break;
                 case Activity.RESULT_CANCELED:
                     Log.i("=====>", "RESULT_CANCELED");
                     break;
             }

1 个解决方案

#1


您的发送的方法呢?

#1


您的发送的方法呢?