android判断短信是否发送成功[动态注册广播]
16lz
2022-04-22
// 创建广播private BroadcastReceiver sendMessage = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(context, "短信发送成功!", Toast.LENGTH_SHORT).show(); break; } }}; // 动态注册广播 registerReceiver(sendMessage, new IntentFilter("SENT_SMS_ACTION")); Intent sentIntent = new Intent("SENT_SMS_ACTION"); PendingIntent sentPI = PendingIntent.getBroadcast(MainActivity.this, 0, sentIntent, 0); // 发送短信,并判断是否发送成功 SmsManager manager = SmsManager.getDefault(); manager.sendTextMessage(号码, null, 短信内容, sentPI, null);
更多相关文章
- Android(安卓)installed app, never used, cannot receiver Broa
- Android广播机制
- Android(安卓)HTTP 压缩 gzip
- Intent在android中的几种用法
- Android初级教程调用手机拍照与摄像功能
- Android(安卓)关闭所有的Activity
- Android(安卓)调用快递鸟api 实现物流跟踪(在途监控)
- ANDROID 使用 Service 在手机锁屏休眠状态下后台执行发送短信息
- IPPH-发送广播