Android Open Source - Lessaging Message Manager






From Project

Back to project page Lessaging.

License

The source code is released under:

GNU General Public License

If you think the Android project Lessaging 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 fr.lessaging.message;
/*  w  w w  .jav a2  s. com*/
import android.app.PendingIntent;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.Telephony;
import android.telephony.PhoneNumberUtils;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

import java.util.ArrayList;

import fr.lessaging.utils.AppConfig;

/**
 * Created by lheido on 27/12/14.
 */
public class MessageManager {

    public static final String ACTION_DELIVERED_SMS = "fr.lessaging.delivered";
    public static final String ACTION_SENT_SMS = "fr.lessaging.sent_sms";
    public static final String ARG_SMS_DELIVERED = "delivered_message_id";
    private static final String ARG_SMS_SENT = "sent_message_id";


    public static void send(Context context, Message message, String address){
        SmsManager manager = SmsManager.getDefault();

        Intent iDelivered = new Intent(ACTION_DELIVERED_SMS);
        iDelivered.putExtra(ARG_SMS_DELIVERED, message.getId());
        Intent iSent = new Intent(ACTION_SENT_SMS);
        iSent.putExtra(ARG_SMS_SENT, message.getId());
        ArrayList<PendingIntent> piSent = new ArrayList<PendingIntent>();
        ArrayList<PendingIntent> piDelivered = new ArrayList<PendingIntent>();
        piSent.add(PendingIntent.getBroadcast(context, 0, iSent, PendingIntent.FLAG_UPDATE_CURRENT));
        piDelivered.add(PendingIntent.getBroadcast(context, 0, iDelivered, PendingIntent.FLAG_UPDATE_CURRENT));

        ArrayList<String> bodyPart = manager.divideMessage(message.getBody());
        if(AppConfig.DEBUG){
            Log.w("MessageManager.send", "bodyPart size = "+bodyPart.size());
            int[] len = SmsMessage.calculateLength(message.getBody(), false);
            Log.w("MessageManager.send", "number of sms required : "+ len[0]);
            Log.w("MessageManager.send", "number of code units used : "+ len[1]);
            Log.w("MessageManager.send", "number of code units remaining until the next message : "+ len[2]);
        }

        manager.sendMultipartTextMessage(address, null, bodyPart, piSent, piDelivered);
    }

    public static void send(Context context, String messageBody, Bitmap image, String addressToSend){}

    public static void store(Context context, String phoneContact, Message sms, long thread_id){
        try {
            ContentValues values = new ContentValues();
            values.put("address", sms.getSender());
            values.put("body", sms.getBody());
            values.put("read", false);
            values.put("type", sms.getType());
            values.put("status", 32);
            if(thread_id != -1)
                values.put("thread_id", thread_id);
            values.put("date", sms.getDateNormalize());
            Uri uri_id = context.getContentResolver().insert(Uri.parse("content://sms"), values);
            long id = -1L;
            if(uri_id != null) {
                id = Long.parseLong(uri_id.getLastPathSegment());
            }
            sms.setId(id);
        } catch (Exception ex) {
            Toast.makeText(context, "store_sms\n" + ex.toString(), Toast.LENGTH_LONG).show();
        }
    }

    public static String getUserPhone(Context context){
        TelephonyManager telemamanger = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        return telemamanger.getLine1Number();
    }

}




Java Source Code List

fr.lessaging.ApplicationTest.java
fr.lessaging.MainActivity.java
fr.lessaging.adapters.ConversationsListAdapter.java
fr.lessaging.adapters.MmsAdapter.java
fr.lessaging.adapters.SmsAdapter.java
fr.lessaging.adapters.SmsBaseAdapter.java
fr.lessaging.adapters.ViewPagerAdapter.java
fr.lessaging.conversation.Conversation.java
fr.lessaging.conversation.ConversationsList.java
fr.lessaging.fragments.CurrentConversationFragment.java
fr.lessaging.fragments.MmsFragment.java
fr.lessaging.fragments.NavigationDrawerFragment.java
fr.lessaging.fragments.SmsBaseFragment.java
fr.lessaging.fragments.SmsFragment.java
fr.lessaging.message.MessageManager.java
fr.lessaging.message.MessageTaskCallback.java
fr.lessaging.message.Message.java
fr.lessaging.message.MmsTask.java
fr.lessaging.message.SmsTask.java
fr.lessaging.preferences.LessagingPreference.java
fr.lessaging.preferences.PrefConversationFragment.java
fr.lessaging.preferences.PrefGeneralFragment.java
fr.lessaging.preferences.PrefListConversationsFragment.java
fr.lessaging.preferences.PrefReceiveFragment.java
fr.lessaging.receiver.MessageReceiver.java
fr.lessaging.utils.AppConfig.java
fr.lessaging.utils.BuildFragment.java
fr.lessaging.utils.LessagingNotification.java
fr.lessaging.utils.LessagingVibrator.java
fr.lessaging.utils.UserPref.java