I am writing an Android application (with a service) where I need to send a message when I receive a GCM notification.
The main problem: when I send 3 SMS at the same time, any other operation stops for a long time (10-20 seconds), and the phone is also blocked. I tried to send an SMS to the stream, but there are no differences.
SmsSender.java
public class SmsSender implements Runnable{ private Context context; private String phoneNumber; private String message; private int id; public SmsSender(Context paramContext, String phoneNumber, String message, int id) { super(); this.context = paramContext; this.phoneNumber = phoneNumber; this.message = message; this.id = id; } public void run() { try { Intent sentIntent = new Intent("sent"); Intent deliveredIntent = new Intent("delivered"); sentIntent.putExtra("id", id); deliveredIntent.putExtra("id", id); PendingIntent sentPI = PendingIntent.getBroadcast(this.context, id,sentIntent, 0); PendingIntent deliveredPI = PendingIntent.getBroadcast(this.context, id, deliveredIntent, 0); SmsManager smsManager = SmsManager.getDefault(); ArrayList<String> parts = smsManager.divideMessage(message); ArrayList<PendingIntent> sentList = new ArrayList<PendingIntent>(); sentList.add(sentPI); ArrayList<PendingIntent> deliveredList = new ArrayList<PendingIntent>(); deliveredList.add(deliveredPI); smsManager.sendMultipartTextMessage(phoneNumber, null, parts, sentList, deliveredList); } catch (Exception e) { e.printStackTrace(); } } }
Start thread
new topic (new SmsSender (getApplicationContext (), phone number, message, id)). start ();
Where is the problem? Why is SMS sent in the main stream and not in my stream?
source share