Codes
Main code examples:
Downloading information from the register of connections:
Cursor managedCursor;
switch ((String) ZmienneGlobalne.getInstance().global_var[5]) {
case "Incoming":
managedCursor = getContentResolver().query(
CallLog.Calls.CONTENT_URI, null, CallLog.Calls.TYPE + "=" + CallLog.Calls.INCOMING_TYPE, null, CallLog.Calls.DATE + " DESC");
break;
case "Outgoing":
managedCursor = getContentResolver().query(
CallLog.Calls.CONTENT_URI, null, CallLog.Calls.TYPE + "=" + CallLog.Calls.OUTGOING_TYPE, null, CallLog.Calls.DATE + " DESC");
break;
case "All":
managedCursor = getContentResolver().query(
CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DATE + " DESC");
break;
default:
managedCursor = getContentResolver().query(
CallLog.Calls.CONTENT_URI, null, CallLog.Calls.TYPE + "=" + CallLog.Calls.INCOMING_TYPE, null, CallLog.Calls.DATE + " DESC");
}
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int licznik = 0;
if (managedCursor.getCount() >= 1) {
while (managedCursor.moveToNext()) {
if (licznik == iloscWLiscie) {
break;
}
String phNumber = managedCursor.getString(number);
String callDate = managedCursor.getString(date);
String callType = managedCursor.getString(type);
String txtType = "";
android.text.format.DateFormat df = new android.text.format.DateFormat();
Date callDayTime = new Date(Long.valueOf(callDate));
switch (callType){
case "1":
txtType = "Incoming";
image = R.drawable.incoming;
break;
case "2":
txtType = "Outgoing";
image = R.drawable.outcoming;
break;
case "3":
txtType = "Missed";
image = R.drawable.missed;
break;
case "4":
txtType = "VoiceMail";
image = R.drawable.voicemail;
break;
case "5":
txtType = "Rejected";
image = R.drawable.reject;
break;
case "6":
txtType = "Blocked";
image = R.drawable.block;
break;
case "7":
txtType = "Answered Externally";
image = R.drawable.ans_ext;
break;
default:
txtType = "Other: " + callType;
}
licznik = licznik + 1;
HashMap<string, string=""> map = new HashMap<string, string="">();
map.put("id", phNumber);
map.put("tel", phNumber);
map.put("list_image",image.toString());
map.put(TAG_LINIA1, df.format("dd-MM-yyyy HH:mm:ss", callDayTime).toString());
map.put(TAG_LINIA2, txtType);
productsList.add(map);
}
}
managedCursor.close();
Sending an SMS message:
ArrayList sentPendingIntents = new ArrayList();
ArrayList deliveredPendingIntents = new ArrayList();
PendingIntent sentPI = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(getApplicationContext(), SmsSentReceiver.class), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(getApplicationContext(), SmsDeliveredReceiver.class), 0);
try {
SmsManager sms = SmsManager.getDefault();
ArrayList parts = sms.divideMessage(message);
for (int i = 0; i < parts.size(); i++) {
sentPendingIntents.add(i, sentPI);
deliveredPendingIntents.add(i, deliveredPI);
}
sms.sendMultipartTextMessage(phoneNumber,null,parts,sentPendingIntents,deliveredPendingIntents);
} catch (Exception e){
e.printStackTrace();
Toast.makeText(getBaseContext(), "SMS sending failed...", Toast.LENGTH_SHORT).show();
}
Supports SMS delivery:
public void onReceive(Context context, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
if (ZmienneGlobalne.getInstance().global_var[3] == "1") {
Toast.makeText(context, "SMS delivered", Toast.LENGTH_SHORT).show();
}
break;
case Activity.RESULT_CANCELED:
if (ZmienneGlobalne.getInstance().global_var[3] == "1") {
Toast.makeText(context, "SMS not delivered", Toast.LENGTH_SHORT).show();
}
break;
}
}