1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import android.os.Bundle;
import android.app.Activity;
import android.telephony.SmsManager;
import java.util.ArrayList;
import android.content.BroadcastReceiver;
import android.app.PendingIntent;
import android.widget.Toast;
import android.content.Context;
public static boolean sendLongSms(String recipient,String message)
{
//Set pending intent
String SENT = "SMS_SENT";
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> msgArray = smsManager.divideMessage(message);
Toast.makeText(getContexteApplication(),msgArray.size(),Toast.LENGTH_LONG).show();
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
for (int i=0; i<msgArray.size(); i++)
{
sentIntents.add(PendingIntent.getBroadcast(getApplicationContext(),0,new Intent(SENT),PendingIntent.FLAG_UPDATE_CURRENT));
}
//Register for sent
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent)
{
String result = "";
switch (getResultCode()) {
case Activity.RESULT_OK:
result = "Ok";
break;
default :
result = "Error";
break;
}
Toast.makeText(getContexteApplication(),result,Toast.LENGTH_LONG).show();
}
}, new IntentFilter(SENT));
//Send SMS
smsManager.sendMultipartTextMessage(recipient,null,msgArray,sentIntents,null);
return true;
} |
Partager