[help Android] các bác cho em hỏi em có 1 cái hàm gửi - TopicsExpress



          

[help Android] các bác cho em hỏi em có 1 cái hàm gửi tin nhắn với lắng nghe sự kiện gửi đi như thế này. nhưng không hiểu sao. em gửi lần đầu thì chỉ có 1 poup bật lên thông báo thành công, nhưng nếu gửi tiếp lần nữa thì lại có 2 popup được bật ra là gửi thành công nếu lần 3 thì có 3 poup tương tự như thế ạ. Các bác giúp em vơi đây là code của em ạ. private void startSMSCharging(final Context context ,final String message, final String phoneNumber, final String category) { try { String SENT = SMS_SENT; String DELIVERED = SMS_DELIVERED; PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent(SENT), 0); PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0,new Intent(DELIVERED), 0); //---when the SMS has been sent--- context.getApplicationContext().registerReceiver(new BroadcastReceiver(){ @Override public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: String title = null; String content; if (category.equalsIgnoreCase(sms)) { if (titleSmsCharging != null) { title = titleSmsCharging; }else{ title = context.getResources().getString(R.string.sms_charging); } } if(category.equalsIgnoreCase(smsplus)){ if (titleSmsPlusCharging != null) { title = titleSmsPlusCharging; }else{ title = context.getResources().getString(R.string.smsplus_charging); } } content = context.getResources().getString(R.string.sms_sent); if (title != null && content != null) { final MDialogNotify dialognt = new MDialogNotify(context); dialognt.setTitle(title, textStyle); dialognt.setContent(content, textStyle); if (backgroundColorTitle != null && colorTextTitleShowPayment != null && typefaceStyleTitleShowPayment != null) { dialognt.setBackGroundTitleMDialog(backgroundColorTitle, colorTextTitleShowPayment, typefaceStyleTitleShowPayment); } dialognt.setCancelable(true); dialognt.setButtonClose(new OnClickListener() { @Override public void onClick(View v) { dialognt.dismiss(); } }); dialognt.show(); } break; case SmsManager.RESULT_ERROR_NO_SERVICE: String titlenoservice = null; String contentnoservice; if (category.equalsIgnoreCase(sms)) { if (titleSmsCharging != null) { titlenoservice = titleSmsCharging; }else{ titlenoservice = context.getResources().getString(R.string.sms_charging); } } if(category.equalsIgnoreCase(smsplus)){ if (titleSmsPlusCharging != null) { titlenoservice = titleSmsPlusCharging; }else{ titlenoservice = context.getResources().getString(R.string.smsplus_charging); } } contentnoservice = context.getResources().getString(R.string.sms_noservice); if (titlenoservice != null && titlenoservice != null) { final MDialogNotify dialogntsmplus = new MDialogNotify(context); dialogntsmplus.setTitle(titlenoservice, textStyle); dialogntsmplus.setContent(contentnoservice, textStyle); if (backgroundColorTitle != null && colorTextTitleShowPayment != null && typefaceStyleTitleShowPayment != null) { dialogntsmplus.setBackGroundTitleMDialog(backgroundColorTitle, colorTextTitleShowPayment, typefaceStyleTitleShowPayment); } dialogntsmplus.setCancelable(true); dialogntsmplus.setButtonClose(new OnClickListener() { @Override public void onClick(View v) { dialogntsmplus.dismiss(); } }); dialogntsmplus.show(); } break; } } }, new IntentFilter(SENT)); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); } catch (Exception e) { Log.e(erro, e.toString()); } }
Posted on: Wed, 05 Nov 2014 15:04:39 +0000

Trending Topics



Recently Viewed Topics




© 2015