Android Open Source - CallNotifier Sms Wrapper






From Project

Back to project page CallNotifier.

License

The source code is released under:

Apache License

If you think the Android project CallNotifier listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.hevsoft.callnotiffier;
//from  ww w . j a va 2 s. c o m
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by elvis.iulian on 11/7/2014.
 */
public class SmsWrapper  {

    private static final String TAG = "SmsWrapper";

    public static void sendSms(Context context,String smsPattern,Contact c,Subject s){
        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);
        SmsManager sms = SmsManager.getDefault();
        if(sms!=null) {
            String smsBody = createSmsBody(smsPattern, s.name + " " + s.phone, formatDate(s.callDate));
            Log.d(TAG,"Sending SMS:("+c.name+")"+smsBody);
            sms.sendTextMessage(c.phone, null, smsBody, sentPI, deliveredPI);
        }
    }

    private static String createSmsBody(String pattern,String nameNr,String date){
        return String.format(pattern,nameNr,date);
    }


    public static String getCurrentPhoneNumber(Context context){
        TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        if(manager!=null){
            return manager.getLine1Number();
        }
        return null;
    }

    public static String formatDate(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm dd MMM");
        return sdf.format(date);
    }

}




Java Source Code List

com.hevsoft.callnotiffier.ApplicationTest.java
com.hevsoft.callnotiffier.CallsReceiver.java
com.hevsoft.callnotiffier.Configuration.java
com.hevsoft.callnotiffier.Contact.java
com.hevsoft.callnotiffier.IObsController.java
com.hevsoft.callnotiffier.MainActivity.java
com.hevsoft.callnotiffier.ObsController.java
com.hevsoft.callnotiffier.SmsWrapper.java
com.hevsoft.callnotiffier.Subject.java