mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-21 13:18:52 +01:00
Clean up some lint issues in android-smsmms module
This commit is contained in:
@@ -1,380 +0,0 @@
|
|||||||
package com.klinker.android.send_message;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.res.XmlResourceParser;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.telephony.ServiceState;
|
|
||||||
import android.telephony.TelephonyManager;
|
|
||||||
import android.telephony.cdma.CdmaCellLocation;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.klinker.android.logger.Log;
|
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class ApnUtils {
|
|
||||||
|
|
||||||
private static final String TAG = "ApnUtils";
|
|
||||||
|
|
||||||
public static void initDefaultApns(final Context context, final OnApnFinishedListener listener) {
|
|
||||||
loadMmsSettings(context);
|
|
||||||
final ArrayList<APN> apns = loadApns(context);
|
|
||||||
|
|
||||||
if (apns == null || apns.size() == 0) {
|
|
||||||
Log.v(TAG, "Found no APNs :( Damn CDMA network probably.");
|
|
||||||
Toast.makeText(context, context.getString(R.string.auto_select_failed), Toast.LENGTH_SHORT).show();
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onFinished();
|
|
||||||
}
|
|
||||||
} else if (apns.size() == 1) {
|
|
||||||
setApns(context, apns.get(0));
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onFinished();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!PreferenceManager.getDefaultSharedPreferences(context).getBoolean("has_seen_select_apns_warning", false)) {
|
|
||||||
new AlertDialog.Builder(context)
|
|
||||||
.setTitle(R.string.auto_select_apn)
|
|
||||||
.setMessage(R.string.auto_select_multiple_apns)
|
|
||||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int num) {
|
|
||||||
showApnChooser(context, apns, listener);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.show();
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("has_seen_select_apns_warning", true).commit();
|
|
||||||
} else {
|
|
||||||
showApnChooser(context, apns, listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void showApnChooser(final Context context, final ArrayList<APN> apns, final OnApnFinishedListener listener) {
|
|
||||||
CharSequence[] items = new CharSequence[apns.size()];
|
|
||||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
String curMmsc = sharedPrefs.getString("mmsc_url", "");
|
|
||||||
String curProxy = sharedPrefs.getString("mms_proxy", "");
|
|
||||||
String curPort = sharedPrefs.getString("mms_port", "");
|
|
||||||
|
|
||||||
int defaultApn = -1;
|
|
||||||
for (int i = 0; i < items.length; i++) {
|
|
||||||
APN apn = apns.get(i);
|
|
||||||
items[i] = (i+1) + ". " + apn.name;
|
|
||||||
|
|
||||||
if (apn.mmsc.equals(curMmsc) && apn.proxy.equals(curProxy) && apn.port.equals(curPort)) {
|
|
||||||
defaultApn = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new AlertDialog.Builder(context)
|
|
||||||
.setSingleChoiceItems(items, defaultApn, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
setApns(context, apns.get(i));
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onFinished();
|
|
||||||
}
|
|
||||||
dialogInterface.dismiss();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
|
||||||
@Override
|
|
||||||
public void onCancel(DialogInterface dialogInterface) {
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onFinished();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface OnApnFinishedListener {
|
|
||||||
public abstract void onFinished();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void loadMmsSettings(Context context) {
|
|
||||||
XmlResourceParser parser = context.getResources().getXml(R.xml.mms_config);
|
|
||||||
String maxMessageSize = 1000000 + "";
|
|
||||||
int maxImageHeight = 800;
|
|
||||||
int maxImageWidth = 800;
|
|
||||||
String userAgent = "Android Messaging";
|
|
||||||
String uaProfUrl = "http://www.gstatic.com/android/hangouts/hangouts_mms_ua_profile.xml";
|
|
||||||
|
|
||||||
try {
|
|
||||||
beginDocument(parser, "mms_config");
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
nextElement(parser);
|
|
||||||
String tag = parser.getName();
|
|
||||||
if (tag == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
String name = parser.getAttributeName(0);
|
|
||||||
String value = parser.getAttributeValue(0);
|
|
||||||
String text = null;
|
|
||||||
if (parser.next() == XmlPullParser.TEXT) {
|
|
||||||
text = parser.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.v(TAG, "tag: " + tag + " value: " + value + " - " +
|
|
||||||
text);
|
|
||||||
if ("name".equalsIgnoreCase(name)) {
|
|
||||||
if ("int".equals(tag)) {
|
|
||||||
// int config tags go here
|
|
||||||
if ("maxMessageSize".equalsIgnoreCase(value)) {
|
|
||||||
maxMessageSize = text;
|
|
||||||
} else if ("maxImageHeight".equalsIgnoreCase(value)) {
|
|
||||||
maxImageHeight = Integer.parseInt(text);
|
|
||||||
} else if ("maxImageWidth".equalsIgnoreCase(value)) {
|
|
||||||
maxImageWidth = Integer.parseInt(text);
|
|
||||||
}
|
|
||||||
} else if ("string".equals(tag)) {
|
|
||||||
// string config tags go here
|
|
||||||
if ("userAgent".equalsIgnoreCase(value)) {
|
|
||||||
userAgent = text;
|
|
||||||
} else if ("uaProfUrl".equalsIgnoreCase(value)) {
|
|
||||||
uaProfUrl = text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
Log.e(TAG, "loadMmsSettings caught ", e);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
Log.e(TAG, "loadMmsSettings caught ", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "loadMmsSettings caught ", e);
|
|
||||||
} finally {
|
|
||||||
parser.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
String errorStr = null;
|
|
||||||
|
|
||||||
if (errorStr != null) {
|
|
||||||
String err =
|
|
||||||
String.format("MmsConfig.loadMmsSettings mms_config.xml missing %s setting",
|
|
||||||
errorStr);
|
|
||||||
Log.e(TAG, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
||||||
final TelephonyManager telephonyManager =
|
|
||||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
||||||
userAgent = telephonyManager.getMmsUserAgent();
|
|
||||||
uaProfUrl = telephonyManager.getMmsUAProfUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
.edit()
|
|
||||||
.putInt("mms_max_width", maxImageWidth)
|
|
||||||
.putInt("mms_max_height", maxImageHeight)
|
|
||||||
.putString("mms_max_size", maxMessageSize)
|
|
||||||
.putString("mms_agent", userAgent)
|
|
||||||
.putString("mms_user_agent_profile_url", uaProfUrl)
|
|
||||||
.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ArrayList<APN> loadApns(Context context) {
|
|
||||||
XmlResourceParser parser = context.getResources().getXml(R.xml.apns);
|
|
||||||
ArrayList<APN> apns = new ArrayList<APN>();
|
|
||||||
String mmsc = "", proxy = "", port = "", carrier = "";
|
|
||||||
|
|
||||||
int mcc = -1, mnc = -1;
|
|
||||||
|
|
||||||
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
|
||||||
String networkOperator = manager.getNetworkOperator();
|
|
||||||
|
|
||||||
if (isValidNetworkOperator(networkOperator)) {
|
|
||||||
mcc = Integer.parseInt(networkOperator.substring(0, 3));
|
|
||||||
String s = networkOperator.substring(3);
|
|
||||||
try {
|
|
||||||
mnc = Integer.parseInt(s.replaceFirst("^0{1,2}", ""));
|
|
||||||
} catch (Exception e) {
|
|
||||||
mnc = -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mcc = context.getResources().getConfiguration().mcc;
|
|
||||||
mnc = context.getResources().getConfiguration().mnc;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (mcc == -1) {
|
|
||||||
mcc = Integer.parseInt(new ServiceState().getOperatorNumeric().substring(0, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mnc == -1) {
|
|
||||||
TelephonyManager tm = (TelephonyManager) context.getSystemService
|
|
||||||
(Context.TELEPHONY_SERVICE);
|
|
||||||
mnc = ((CdmaCellLocation) tm.getCellLocation()).getSystemId();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mcc == -1 || mnc == -1) {
|
|
||||||
Log.v(TAG, "couldn't find both mcc and mnc. mcc = " + mcc + ", mnc = " + mnc);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.v(TAG, "mcc: " + mcc + " mnc: " + mnc);
|
|
||||||
|
|
||||||
try {
|
|
||||||
beginDocument(parser, "apns");
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
nextElement(parser);
|
|
||||||
String tag = parser.getName();
|
|
||||||
if (tag == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean mccCorrect = false, mncCorrect = false;
|
|
||||||
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
|
||||||
try {
|
|
||||||
String name = parser.getAttributeName(i);
|
|
||||||
int value = Integer.parseInt(parser.getAttributeValue(i));
|
|
||||||
if ("mcc".equals(name) && mcc == value) {
|
|
||||||
mccCorrect = true;
|
|
||||||
} else if ("mnc".equals(name) && mnc == value) {
|
|
||||||
mncCorrect = true;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// cast exception probably
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mccCorrect && mncCorrect) {
|
|
||||||
// parse the rest of the apn
|
|
||||||
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
|
||||||
String name = parser.getAttributeName(i);
|
|
||||||
String value = parser.getAttributeValue(i);
|
|
||||||
if ("type".equals(name)) {
|
|
||||||
if (!value.contains("mms")) {
|
|
||||||
mmsc = "";
|
|
||||||
proxy = "";
|
|
||||||
port = "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if ("mmsc".equals(name)) {
|
|
||||||
mmsc = value;
|
|
||||||
} else if ("mmsproxy".equals(name)) {
|
|
||||||
proxy = value;
|
|
||||||
} else if ("mmsport".equals(name)) {
|
|
||||||
port = value;
|
|
||||||
} else if ("carrier".equals(name)) {
|
|
||||||
carrier = value;
|
|
||||||
} else if ("port".equals(name) && port.equals("")) {
|
|
||||||
port = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mmsc.equals("")) {
|
|
||||||
APN apn = new APN();
|
|
||||||
apn.name = carrier;
|
|
||||||
apn.mmsc = mmsc;
|
|
||||||
apn.proxy = proxy;
|
|
||||||
apn.port = port;
|
|
||||||
|
|
||||||
boolean contains = false;
|
|
||||||
for (int i = 0; i < apns.size(); i++) {
|
|
||||||
APN current = apns.get(i);
|
|
||||||
|
|
||||||
if (current.mmsc.equals(apn.mmsc) && current.port.equals(apn.port) && current.proxy.equals(apn.proxy)) {
|
|
||||||
contains = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!contains) {
|
|
||||||
apns.add(apn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
Log.e(TAG, "loadApns caught ", e);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
Log.e(TAG, "loadApns caught ", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "loadApns caught ", e);
|
|
||||||
} finally {
|
|
||||||
parser.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.v(TAG, "MMSC: " + mmsc + ", MMS Proxy: " + proxy + ", MMS Port: " + port);
|
|
||||||
|
|
||||||
String errorStr = null;
|
|
||||||
|
|
||||||
if (errorStr != null) {
|
|
||||||
String err =
|
|
||||||
String.format("MmsConfig.loadMmsSettings mms_config.xml missing %s setting",
|
|
||||||
errorStr);
|
|
||||||
Log.e(TAG, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
return apns;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the given network operator is valid, i.e. it's not null, empty or contains "null"
|
|
||||||
*
|
|
||||||
* @param networkOperator
|
|
||||||
* The network operator to be checked
|
|
||||||
*
|
|
||||||
* @return True if is a valid operator
|
|
||||||
*/
|
|
||||||
private static boolean isValidNetworkOperator(String networkOperator) {
|
|
||||||
return networkOperator != null && !networkOperator.isEmpty() &&
|
|
||||||
!networkOperator.contains("null");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setApns(Context context, APN apn) {
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(context)
|
|
||||||
.edit()
|
|
||||||
.putString("mmsc_url", apn.mmsc)
|
|
||||||
.putString("mms_proxy", apn.proxy)
|
|
||||||
.putString("mms_port", apn.port)
|
|
||||||
.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException {
|
|
||||||
int type;
|
|
||||||
while ((type=parser.next()) != parser.START_TAG
|
|
||||||
&& type != parser.END_DOCUMENT) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type != parser.START_TAG) {
|
|
||||||
throw new XmlPullParserException("No start tag found");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parser.getName().equals(firstElementName)) {
|
|
||||||
throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() +
|
|
||||||
", expected " + firstElementName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void nextElement(XmlPullParser parser) throws XmlPullParserException, IOException {
|
|
||||||
int type;
|
|
||||||
while ((type=parser.next()) != parser.START_TAG
|
|
||||||
&& type != parser.END_DOCUMENT) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class APN {
|
|
||||||
public String name;
|
|
||||||
public String mmsc;
|
|
||||||
public String proxy;
|
|
||||||
public String port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -58,7 +58,7 @@ public class Message {
|
|||||||
private String[] addresses;
|
private String[] addresses;
|
||||||
private Bitmap[] images;
|
private Bitmap[] images;
|
||||||
private String[] imageNames;
|
private String[] imageNames;
|
||||||
private List<Part> parts = new ArrayList<Part>();
|
private List<Part> parts = new ArrayList<>();
|
||||||
private boolean save;
|
private boolean save;
|
||||||
private int delay;
|
private int delay;
|
||||||
|
|
||||||
@@ -411,9 +411,7 @@ public class Message {
|
|||||||
|
|
||||||
this.addresses = new String[temp.length + 1];
|
this.addresses = new String[temp.length + 1];
|
||||||
|
|
||||||
for (int i = 0; i < temp.length; i++) {
|
System.arraycopy(temp, 0, this.addresses, 0, temp.length);
|
||||||
this.addresses[i] = temp[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
this.addresses[temp.length] = address;
|
this.addresses[temp.length] = address;
|
||||||
}
|
}
|
||||||
@@ -432,9 +430,7 @@ public class Message {
|
|||||||
|
|
||||||
this.images = new Bitmap[temp.length + 1];
|
this.images = new Bitmap[temp.length + 1];
|
||||||
|
|
||||||
for (int i = 0; i < temp.length; i++) {
|
System.arraycopy(temp, 0, this.images, 0, temp.length);
|
||||||
this.images[i] = temp[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
this.images[temp.length] = image;
|
this.images[temp.length] = image;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-12
@@ -24,14 +24,12 @@ import android.os.AsyncTask;
|
|||||||
import android.provider.Telephony;
|
import android.provider.Telephony;
|
||||||
import android.telephony.SmsManager;
|
import android.telephony.SmsManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.mms.service_alt.DownloadRequest;
|
import com.android.mms.service_alt.DownloadRequest;
|
||||||
import com.android.mms.service_alt.MmsConfig;
|
import com.android.mms.service_alt.MmsConfig;
|
||||||
import com.android.mms.transaction.DownloadManager;
|
import com.android.mms.transaction.DownloadManager;
|
||||||
import com.android.mms.transaction.HttpUtils;
|
import com.android.mms.transaction.HttpUtils;
|
||||||
import com.android.mms.transaction.TransactionSettings;
|
import com.android.mms.transaction.TransactionSettings;
|
||||||
import com.android.mms.util.SendingProgressTokenManager;
|
import com.android.mms.util.SendingProgressTokenManager;
|
||||||
import com.google.android.mms.InvalidHeaderValueException;
|
|
||||||
import com.google.android.mms.MmsException;
|
import com.google.android.mms.MmsException;
|
||||||
import com.google.android.mms.pdu_alt.EncodedStringValue;
|
import com.google.android.mms.pdu_alt.EncodedStringValue;
|
||||||
import com.google.android.mms.pdu_alt.GenericPdu;
|
import com.google.android.mms.pdu_alt.GenericPdu;
|
||||||
@@ -263,7 +261,7 @@ public class MmsReceivedReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
// Create the M-NotifyResp.ind
|
// Create the M-NotifyResp.ind
|
||||||
NotifyRespInd notifyRespInd = null;
|
NotifyRespInd notifyRespInd;
|
||||||
try {
|
try {
|
||||||
notifyRespInd = new NotifyRespInd(
|
notifyRespInd = new NotifyRespInd(
|
||||||
PduHeaders.CURRENT_MMS_VERSION,
|
PduHeaders.CURRENT_MMS_VERSION,
|
||||||
@@ -276,9 +274,7 @@ public class MmsReceivedReceiver extends BroadcastReceiver {
|
|||||||
} else {
|
} else {
|
||||||
sendPdu(new PduComposer(mContext, notifyRespInd).make());
|
sendPdu(new PduComposer(mContext, notifyRespInd).make());
|
||||||
}
|
}
|
||||||
} catch (MmsException e) {
|
} catch (MmsException | IOException e) {
|
||||||
Log.e(TAG, "error", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "error", e);
|
Log.e(TAG, "error", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -302,7 +298,7 @@ public class MmsReceivedReceiver extends BroadcastReceiver {
|
|||||||
if (tranId != null) {
|
if (tranId != null) {
|
||||||
Log.v(TAG, "sending ACK to MMSC: " + mTransactionSettings.getMmscUrl());
|
Log.v(TAG, "sending ACK to MMSC: " + mTransactionSettings.getMmscUrl());
|
||||||
// Create M-Acknowledge.ind
|
// Create M-Acknowledge.ind
|
||||||
com.google.android.mms.pdu_alt.AcknowledgeInd acknowledgeInd = null;
|
com.google.android.mms.pdu_alt.AcknowledgeInd acknowledgeInd;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
acknowledgeInd = new com.google.android.mms.pdu_alt.AcknowledgeInd(
|
acknowledgeInd = new com.google.android.mms.pdu_alt.AcknowledgeInd(
|
||||||
@@ -318,11 +314,7 @@ public class MmsReceivedReceiver extends BroadcastReceiver {
|
|||||||
} else {
|
} else {
|
||||||
sendPdu(new PduComposer(mContext, acknowledgeInd).make());
|
sendPdu(new PduComposer(mContext, acknowledgeInd).make());
|
||||||
}
|
}
|
||||||
} catch (InvalidHeaderValueException e) {
|
} catch (IOException | MmsException e) {
|
||||||
Log.e(TAG, "error", e);
|
|
||||||
} catch (MmsException e) {
|
|
||||||
Log.e(TAG, "error", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.e(TAG, "error", e);
|
Log.e(TAG, "error", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-8
@@ -5,10 +5,8 @@ import android.app.IntentService;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
|
||||||
import android.provider.Telephony;
|
import android.provider.Telephony;
|
||||||
import android.telephony.SmsManager;
|
import android.telephony.SmsManager;
|
||||||
|
|
||||||
import com.android.mms.service_alt.DownloadRequest;
|
import com.android.mms.service_alt.DownloadRequest;
|
||||||
import com.android.mms.service_alt.MmsConfig;
|
import com.android.mms.service_alt.MmsConfig;
|
||||||
import com.android.mms.transaction.DownloadManager;
|
import com.android.mms.transaction.DownloadManager;
|
||||||
@@ -99,10 +97,6 @@ public class MmsReceivedService extends IntentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void handleHttpError(Context context, Intent intent) {
|
private static void handleHttpError(Context context, Intent intent) {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int httpError = intent.getIntExtra(SmsManager.EXTRA_MMS_HTTP_STATUS, 0);
|
final int httpError = intent.getIntExtra(SmsManager.EXTRA_MMS_HTTP_STATUS, 0);
|
||||||
if (httpError == 404 ||
|
if (httpError == 404 ||
|
||||||
httpError == 400) {
|
httpError == 400) {
|
||||||
@@ -220,7 +214,7 @@ public class MmsReceivedService extends IntentService {
|
|||||||
@Override
|
@Override
|
||||||
public void run() throws IOException {
|
public void run() throws IOException {
|
||||||
// Create the M-NotifyResp.ind
|
// Create the M-NotifyResp.ind
|
||||||
NotifyRespInd notifyRespInd = null;
|
NotifyRespInd notifyRespInd;
|
||||||
try {
|
try {
|
||||||
notifyRespInd = new NotifyRespInd(
|
notifyRespInd = new NotifyRespInd(
|
||||||
PduHeaders.CURRENT_MMS_VERSION,
|
PduHeaders.CURRENT_MMS_VERSION,
|
||||||
@@ -255,7 +249,7 @@ public class MmsReceivedService extends IntentService {
|
|||||||
byte[] tranId = mRetrieveConf.getTransactionId();
|
byte[] tranId = mRetrieveConf.getTransactionId();
|
||||||
if (tranId != null) {
|
if (tranId != null) {
|
||||||
// Create M-Acknowledge.ind
|
// Create M-Acknowledge.ind
|
||||||
com.google.android.mms.pdu_alt.AcknowledgeInd acknowledgeInd = null;
|
com.google.android.mms.pdu_alt.AcknowledgeInd acknowledgeInd;
|
||||||
try {
|
try {
|
||||||
acknowledgeInd = new com.google.android.mms.pdu_alt.AcknowledgeInd(
|
acknowledgeInd = new com.google.android.mms.pdu_alt.AcknowledgeInd(
|
||||||
PduHeaders.CURRENT_MMS_VERSION, tranId);
|
PduHeaders.CURRENT_MMS_VERSION, tranId);
|
||||||
|
|||||||
@@ -16,9 +16,7 @@
|
|||||||
|
|
||||||
package com.klinker.android.send_message;
|
package com.klinker.android.send_message;
|
||||||
|
|
||||||
import android.net.wifi.WifiInfo;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import com.klinker.android.logger.Log;
|
import com.klinker.android.logger.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,31 +18,40 @@ package com.klinker.android.send_message;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.*;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.telephony.SmsManager;
|
import android.telephony.SmsManager;
|
||||||
import android.telephony.SmsMessage;
|
import android.telephony.SmsMessage;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.widget.Toast;
|
||||||
import com.android.mms.MmsConfig;
|
import com.android.mms.MmsConfig;
|
||||||
|
import com.android.mms.dom.smil.parser.SmilXmlSerializer;
|
||||||
import com.android.mms.service_alt.MmsNetworkManager;
|
import com.android.mms.service_alt.MmsNetworkManager;
|
||||||
import com.android.mms.service_alt.MmsRequestManager;
|
import com.android.mms.service_alt.MmsRequestManager;
|
||||||
import com.android.mms.service_alt.SendRequest;
|
import com.android.mms.service_alt.SendRequest;
|
||||||
import com.klinker.android.logger.Log;
|
|
||||||
import android.widget.Toast;
|
|
||||||
import com.android.mms.dom.smil.parser.SmilXmlSerializer;
|
|
||||||
import com.android.mms.transaction.MmsMessageSender;
|
|
||||||
import com.android.mms.transaction.ProgressCallbackEntity;
|
|
||||||
import com.android.mms.util.DownloadManager;
|
import com.android.mms.util.DownloadManager;
|
||||||
import com.android.mms.util.RateController;
|
import com.android.mms.util.RateController;
|
||||||
import com.google.android.mms.*;
|
import com.google.android.mms.ContentType;
|
||||||
import com.google.android.mms.pdu_alt.*;
|
import com.google.android.mms.InvalidHeaderValueException;
|
||||||
|
import com.google.android.mms.MMSPart;
|
||||||
|
import com.google.android.mms.MmsException;
|
||||||
|
import com.google.android.mms.pdu_alt.CharacterSets;
|
||||||
|
import com.google.android.mms.pdu_alt.EncodedStringValue;
|
||||||
|
import com.google.android.mms.pdu_alt.PduBody;
|
||||||
|
import com.google.android.mms.pdu_alt.PduComposer;
|
||||||
|
import com.google.android.mms.pdu_alt.PduHeaders;
|
||||||
|
import com.google.android.mms.pdu_alt.PduPart;
|
||||||
|
import com.google.android.mms.pdu_alt.PduPersister;
|
||||||
|
import com.google.android.mms.pdu_alt.SendReq;
|
||||||
import com.google.android.mms.smil.SmilHelper;
|
import com.google.android.mms.smil.SmilHelper;
|
||||||
|
import com.klinker.android.logger.Log;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@@ -50,7 +59,13 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to process transaction requests for sending
|
* Class to process transaction requests for sending
|
||||||
@@ -97,7 +112,7 @@ public class Transaction {
|
|||||||
* @param settings is the settings object to process send requests through
|
* @param settings is the settings object to process send requests through
|
||||||
*/
|
*/
|
||||||
public Transaction(Context context, Settings settings) {
|
public Transaction(Context context, Settings settings) {
|
||||||
this.settings = settings;
|
Transaction.settings = settings;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
SMS_SENT = context.getPackageName() + SMS_SENT;
|
SMS_SENT = context.getPackageName() + SMS_SENT;
|
||||||
@@ -140,48 +155,9 @@ public class Transaction {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Optional: define a {@link BroadcastReceiver} that will get started when Android notifies us that the SMS has
|
|
||||||
* been marked as "sent". If you do not define a receiver here, it will look for the .SMS_SENT receiver
|
|
||||||
* that was defined in the AndroidManifest, as discussed in the README.md.
|
|
||||||
*
|
|
||||||
* @param intent the receiver that you want to start when the message gets marked as sent.
|
|
||||||
*/
|
|
||||||
public Transaction setExplicitBroadcastForSentSms(Intent intent) {
|
|
||||||
explicitSentSmsReceiver = intent;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Optional: define a {@link BroadcastReceiver} that will get started when Android notifies us that the MMS has
|
|
||||||
* been marked as "sent". If you do not define a receiver here, it will look for the .MMS_SENT receiver
|
|
||||||
* that was defined in the AndroidManifest, as discussed in the README.md.
|
|
||||||
*
|
|
||||||
* @param intent the receiver that you want to start when the message gets marked as sent.
|
|
||||||
*/
|
|
||||||
public Transaction setExplicitBroadcastForSentMms(Intent intent) {
|
|
||||||
explicitSentMmsReceiver = intent;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Optional: define a {@link BroadcastReceiver} that will get started when Android notifies us that the SMS has
|
|
||||||
* been marked as "delivered". If you do not define a receiver here, it will look for the .SMS_DELIVERED
|
|
||||||
* receiver that was defined in the AndroidManifest, as discussed in the README.md.
|
|
||||||
* <p/>
|
|
||||||
* Providing a receiver here does not guarantee that it will ever get started. If the {@link Settings}
|
|
||||||
* object does not have delivery reports turned on, this receiver will never get called.
|
|
||||||
*
|
|
||||||
* @param intent the receiver that you want to start when the message gets marked as sent.
|
|
||||||
*/
|
|
||||||
public Transaction setExplicitBroadcastForDeliveredSms(Intent intent) {
|
|
||||||
explicitDeliveredSmsReceiver = intent;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendSmsMessage(String text, String[] addresses, long threadId, int delay) {
|
private void sendSmsMessage(String text, String[] addresses, long threadId, int delay) {
|
||||||
Log.v("send_transaction", "message text: " + text);
|
Log.v("send_transaction", "message text: " + text);
|
||||||
Uri messageUri = null;
|
Uri messageUri;
|
||||||
int messageId = 0;
|
int messageId = 0;
|
||||||
if (saveMessage) {
|
if (saveMessage) {
|
||||||
Log.v("send_transaction", "saving message");
|
Log.v("send_transaction", "saving message");
|
||||||
@@ -191,10 +167,10 @@ public class Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save the message for each of the addresses
|
// save the message for each of the addresses
|
||||||
for (int i = 0; i < addresses.length; i++) {
|
for (String address : addresses) {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put("address", addresses[i]);
|
values.put("address", address);
|
||||||
values.put("body", settings.getStripUnicode() ? StripAccents.stripAccents(text) : text);
|
values.put("body", settings.getStripUnicode() ? StripAccents.stripAccents(text) : text);
|
||||||
values.put("date", cal.getTimeInMillis() + "");
|
values.put("date", cal.getTimeInMillis() + "");
|
||||||
values.put("read", 1);
|
values.put("read", 1);
|
||||||
@@ -202,7 +178,7 @@ public class Transaction {
|
|||||||
|
|
||||||
// attempt to create correct thread id if one is not supplied
|
// attempt to create correct thread id if one is not supplied
|
||||||
if (threadId == NO_THREAD_ID || addresses.length > 1) {
|
if (threadId == NO_THREAD_ID || addresses.length > 1) {
|
||||||
threadId = Utils.getOrCreateThreadId(context, addresses[i]);
|
threadId = Utils.getOrCreateThreadId(context, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.v("send_transaction", "saving message with thread id: " + threadId);
|
Log.v("send_transaction", "saving message with thread id: " + threadId);
|
||||||
@@ -212,7 +188,7 @@ public class Transaction {
|
|||||||
|
|
||||||
Log.v("send_transaction", "inserted to uri: " + messageUri);
|
Log.v("send_transaction", "inserted to uri: " + messageUri);
|
||||||
|
|
||||||
Cursor query = context.getContentResolver().query(messageUri, new String[] {"_id"}, null, null, null);
|
Cursor query = context.getContentResolver().query(messageUri, new String[]{"_id"}, null, null, null);
|
||||||
if (query != null && query.moveToFirst()) {
|
if (query != null && query.moveToFirst()) {
|
||||||
messageId = query.getInt(0);
|
messageId = query.getInt(0);
|
||||||
query.close();
|
query.close();
|
||||||
@@ -245,8 +221,8 @@ public class Transaction {
|
|||||||
PendingIntent deliveredPI = PendingIntent.getBroadcast(
|
PendingIntent deliveredPI = PendingIntent.getBroadcast(
|
||||||
context, messageId, deliveredIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
context, messageId, deliveredIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
ArrayList<PendingIntent> sPI = new ArrayList<PendingIntent>();
|
ArrayList<PendingIntent> sPI = new ArrayList<>();
|
||||||
ArrayList<PendingIntent> dPI = new ArrayList<PendingIntent>();
|
ArrayList<PendingIntent> dPI = new ArrayList<>();
|
||||||
|
|
||||||
String body = text;
|
String body = text;
|
||||||
|
|
||||||
@@ -283,8 +259,8 @@ public class Transaction {
|
|||||||
String[] textToSend = splitByLength(body, length, counter);
|
String[] textToSend = splitByLength(body, length, counter);
|
||||||
|
|
||||||
// send each message part to each recipient attached to message
|
// send each message part to each recipient attached to message
|
||||||
for (int j = 0; j < textToSend.length; j++) {
|
for (String aTextToSend : textToSend) {
|
||||||
ArrayList<String> parts = smsManager.divideMessage(textToSend[j]);
|
ArrayList<String> parts = smsManager.divideMessage(aTextToSend);
|
||||||
|
|
||||||
for (int k = 0; k < parts.size(); k++) {
|
for (int k = 0; k < parts.size(); k++) {
|
||||||
sPI.add(saveMessage ? sentPI : null);
|
sPI.add(saveMessage ? sentPI : null);
|
||||||
@@ -292,7 +268,7 @@ public class Transaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log.v("send_transaction", "sending split message");
|
Log.v("send_transaction", "sending split message");
|
||||||
sendDelayedSms(smsManager, addresses[i], parts, sPI, dPI, delay, messageUri);
|
sendDelayedSms(smsManager, address, parts, sPI, dPI, delay, messageUri);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.v("send_transaction", "sending without splitting");
|
Log.v("send_transaction", "sending without splitting");
|
||||||
@@ -307,7 +283,7 @@ public class Transaction {
|
|||||||
if (Utils.isDefaultSmsApp(context)) {
|
if (Utils.isDefaultSmsApp(context)) {
|
||||||
try {
|
try {
|
||||||
Log.v("send_transaction", "sent message");
|
Log.v("send_transaction", "sent message");
|
||||||
sendDelayedSms(smsManager, addresses[i], parts, sPI, dPI, delay, messageUri);
|
sendDelayedSms(smsManager, address, parts, sPI, dPI, delay, messageUri);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// whoops...
|
// whoops...
|
||||||
Log.v("send_transaction", "error sending message");
|
Log.v("send_transaction", "error sending message");
|
||||||
@@ -321,11 +297,12 @@ public class Transaction {
|
|||||||
Toast.makeText(context, "Message could not be sent", Toast.LENGTH_LONG).show();
|
Toast.makeText(context, "Message could not be sent", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception f) { }
|
} catch (Exception f) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// not default app, so just fire it off right away for the hell of it
|
// not default app, so just fire it off right away for the hell of it
|
||||||
smsManager.sendMultipartTextMessage(addresses[i], null, parts, sPI, dPI);
|
smsManager.sendMultipartTextMessage(address, null, parts, sPI, dPI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,16 +345,16 @@ public class Transaction {
|
|||||||
|
|
||||||
private void sendMmsMessage(String text, String[] addresses, Bitmap[] image, String[] imageNames, List<Message.Part> parts, String subject) {
|
private void sendMmsMessage(String text, String[] addresses, Bitmap[] image, String[] imageNames, List<Message.Part> parts, String subject) {
|
||||||
// merge the string[] of addresses into a single string so they can be inserted into the database easier
|
// merge the string[] of addresses into a single string so they can be inserted into the database easier
|
||||||
String address = "";
|
StringBuilder address = new StringBuilder();
|
||||||
|
|
||||||
for (int i = 0; i < addresses.length; i++) {
|
for (String address1 : addresses) {
|
||||||
address += addresses[i] + " ";
|
address.append(address1).append(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
address = address.trim();
|
address = new StringBuilder(address.toString().trim());
|
||||||
|
|
||||||
// create the parts to send
|
// create the parts to send
|
||||||
ArrayList<MMSPart> data = new ArrayList<MMSPart>();
|
ArrayList<MMSPart> data = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < image.length; i++) {
|
for (int i = 0; i < image.length; i++) {
|
||||||
// turn bitmap into byte array to be stored
|
// turn bitmap into byte array to be stored
|
||||||
@@ -415,70 +392,22 @@ public class Transaction {
|
|||||||
data.add(part);
|
data.add(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
Log.v(TAG, "using lollipop method for sending sms");
|
||||||
MessageInfo info = null;
|
|
||||||
|
|
||||||
try {
|
if (settings.getUseSystemSending()) {
|
||||||
info = getBytes(context, saveMessage, address.split(" "),
|
Log.v(TAG, "using system method for sending");
|
||||||
data.toArray(new MMSPart[data.size()]), subject);
|
sendMmsThroughSystem(context, subject, data, addresses, explicitSentMmsReceiver);
|
||||||
MmsMessageSender sender = new MmsMessageSender(context, info.location, info.bytes.length);
|
|
||||||
sender.sendMessage(info.token);
|
|
||||||
|
|
||||||
IntentFilter filter = new IntentFilter();
|
|
||||||
filter.addAction(ProgressCallbackEntity.PROGRESS_STATUS_ACTION);
|
|
||||||
BroadcastReceiver receiver = new BroadcastReceiver() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
int progress = intent.getIntExtra("progress", -3);
|
|
||||||
Log.v("sending_mms_library", "progress: " + progress);
|
|
||||||
|
|
||||||
// send progress broadcast to update ui if desired...
|
|
||||||
Intent progressIntent = new Intent(MMS_PROGRESS);
|
|
||||||
progressIntent.putExtra("progress", progress);
|
|
||||||
BroadcastUtils.sendExplicitBroadcast(context, progressIntent, MMS_PROGRESS);
|
|
||||||
|
|
||||||
if (progress == ProgressCallbackEntity.PROGRESS_COMPLETE) {
|
|
||||||
BroadcastUtils.sendExplicitBroadcast(context, new Intent(), REFRESH);
|
|
||||||
|
|
||||||
try {
|
|
||||||
context.unregisterReceiver(this);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// TODO fix me
|
|
||||||
// receiver is not registered force close error... hmm.
|
|
||||||
}
|
|
||||||
} else if (progress == ProgressCallbackEntity.PROGRESS_ABORT) {
|
|
||||||
// This seems to get called only after the progress has reached 100 and
|
|
||||||
// then something else goes wrong, so here we will try and send again
|
|
||||||
// and see if it works
|
|
||||||
Log.v("sending_mms_library", "sending aborted for some reason...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
context.registerReceiver(receiver, filter);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Log.e(TAG, "exception thrown", e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Log.v(TAG, "using lollipop method for sending sms");
|
try {
|
||||||
|
MessageInfo info = getBytes(context, saveMessage, address.toString().split(" "),
|
||||||
if (settings.getUseSystemSending()) {
|
data.toArray(new MMSPart[data.size()]), subject);
|
||||||
Log.v(TAG, "using system method for sending");
|
MmsRequestManager requestManager = new MmsRequestManager(context, info.bytes);
|
||||||
sendMmsThroughSystem(context, subject, data, addresses, explicitSentMmsReceiver);
|
SendRequest request = new SendRequest(requestManager, Utils.getDefaultSubscriptionId(),
|
||||||
} else {
|
info.location, null, null, null, null);
|
||||||
try {
|
MmsNetworkManager manager = new MmsNetworkManager(context, Utils.getDefaultSubscriptionId());
|
||||||
MessageInfo info = getBytes(context, saveMessage, address.split(" "),
|
request.execute(context, manager);
|
||||||
data.toArray(new MMSPart[data.size()]), subject);
|
} catch (Exception e) {
|
||||||
MmsRequestManager requestManager = new MmsRequestManager(context, info.bytes);
|
Log.e(TAG, "error sending mms", e);
|
||||||
SendRequest request = new SendRequest(requestManager, Utils.getDefaultSubscriptionId(),
|
|
||||||
info.location, null, null, null, null);
|
|
||||||
MmsNetworkManager manager = new MmsNetworkManager(context, Utils.getDefaultSubscriptionId());
|
|
||||||
request.execute(context, manager);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "error sending mms", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,8 +418,8 @@ public class Transaction {
|
|||||||
final SendReq sendRequest = new SendReq();
|
final SendReq sendRequest = new SendReq();
|
||||||
|
|
||||||
// create send request addresses
|
// create send request addresses
|
||||||
for (int i = 0; i < recipients.length; i++) {
|
for (String recipient : recipients) {
|
||||||
final EncodedStringValue[] phoneNumbers = EncodedStringValue.extract(recipients[i]);
|
final EncodedStringValue[] phoneNumbers = EncodedStringValue.extract(recipient);
|
||||||
|
|
||||||
if (phoneNumbers != null && phoneNumbers.length > 0) {
|
if (phoneNumbers != null && phoneNumbers.length > 0) {
|
||||||
sendRequest.addTo(phoneNumbers[0]);
|
sendRequest.addTo(phoneNumbers[0]);
|
||||||
@@ -514,8 +443,7 @@ public class Transaction {
|
|||||||
// assign parts to the pdu body which contains sending data
|
// assign parts to the pdu body which contains sending data
|
||||||
long size = 0;
|
long size = 0;
|
||||||
if (parts != null) {
|
if (parts != null) {
|
||||||
for (int i = 0; i < parts.length; i++) {
|
for (MMSPart part : parts) {
|
||||||
MMSPart part = parts[i];
|
|
||||||
if (part != null) {
|
if (part != null) {
|
||||||
try {
|
try {
|
||||||
PduPart partPdu = new PduPart();
|
PduPart partPdu = new PduPart();
|
||||||
@@ -790,7 +718,7 @@ public class Transaction {
|
|||||||
try {
|
try {
|
||||||
Uri destUri = Uri.parse("content://mms");
|
Uri destUri = Uri.parse("content://mms");
|
||||||
|
|
||||||
Set<String> recipients = new HashSet<String>();
|
Set<String> recipients = new HashSet<>();
|
||||||
recipients.addAll(Arrays.asList(to));
|
recipients.addAll(Arrays.asList(to));
|
||||||
long thread_id = Utils.getOrCreateThreadId(context, recipients);
|
long thread_id = Utils.getOrCreateThreadId(context, recipients);
|
||||||
|
|
||||||
@@ -873,11 +801,15 @@ public class Transaction {
|
|||||||
ByteArrayInputStream is = new ByteArrayInputStream(imageBytes);
|
ByteArrayInputStream is = new ByteArrayInputStream(imageBytes);
|
||||||
byte[] buffer = new byte[256];
|
byte[] buffer = new byte[256];
|
||||||
|
|
||||||
for (int len = 0; (len = is.read(buffer)) != -1; ) {
|
for (int len; (len = is.read(buffer)) != -1; ) {
|
||||||
os.write(buffer, 0, len);
|
if (os != null) {
|
||||||
|
os.write(buffer, 0, len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
os.close();
|
if (os != null) {
|
||||||
|
os.close();
|
||||||
|
}
|
||||||
is.close();
|
is.close();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@@ -891,9 +823,7 @@ public class Transaction {
|
|||||||
mmsPartValue.put("cid", "<" + System.currentTimeMillis() + ">");
|
mmsPartValue.put("cid", "<" + System.currentTimeMillis() + ">");
|
||||||
mmsPartValue.put("text", text);
|
mmsPartValue.put("text", text);
|
||||||
Uri partUri = Uri.parse("content://mms/" + id + "/part");
|
Uri partUri = Uri.parse("content://mms/" + id + "/part");
|
||||||
Uri res = context.getContentResolver().insert(partUri, mmsPartValue);
|
return context.getContentResolver().insert(partUri, mmsPartValue);
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add address to the request
|
// add address to the request
|
||||||
@@ -903,9 +833,7 @@ public class Transaction {
|
|||||||
addrValues.put("charset", "106");
|
addrValues.put("charset", "106");
|
||||||
addrValues.put("type", 151); // TO
|
addrValues.put("type", 151); // TO
|
||||||
Uri addrUri = Uri.parse("content://mms/" + id + "/addr");
|
Uri addrUri = Uri.parse("content://mms/" + id + "/addr");
|
||||||
Uri res = context.getContentResolver().insert(addrUri, addrValues);
|
return context.getContentResolver().insert(addrUri, addrValues);
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -215,40 +215,22 @@ public class Utils {
|
|||||||
* @param enabled is whether to enable or disable data
|
* @param enabled is whether to enable or disable data
|
||||||
*/
|
*/
|
||||||
public static void setMobileDataEnabled(Context context, boolean enabled) {
|
public static void setMobileDataEnabled(Context context, boolean enabled) {
|
||||||
String methodName;
|
// TODO find a better way to do this on lollipop!
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
// This will actually not work due to no permission for android.permission.MODIFY_PHONE_STATE, which
|
||||||
try {
|
// is a system level permission and cannot be accessed for third party apps.
|
||||||
ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
try {
|
||||||
Class conmanClass = Class.forName(conman.getClass().getName());
|
TelephonyManager tm = (TelephonyManager) context
|
||||||
Field iConnectivityManagerField = conmanClass.getDeclaredField("mService");
|
.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
iConnectivityManagerField.setAccessible(true);
|
Class c = Class.forName(tm.getClass().getName());
|
||||||
Object iConnectivityManager = iConnectivityManagerField.get(conman);
|
Method m = c.getDeclaredMethod("getITelephony");
|
||||||
Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName());
|
m.setAccessible(true);
|
||||||
Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
|
Object telephonyService = m.invoke(tm);
|
||||||
setMobileDataEnabledMethod.setAccessible(true);
|
c = Class.forName(telephonyService.getClass().getName());
|
||||||
|
m = c.getDeclaredMethod("setDataEnabled", Boolean.TYPE);
|
||||||
setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled);
|
m.setAccessible(true);
|
||||||
} catch (Exception e) {
|
m.invoke(telephonyService, enabled);
|
||||||
Log.e(TAG, "exception thrown", e);
|
} catch (Exception e) {
|
||||||
}
|
Log.e(TAG, "error enabling data on lollipop", e);
|
||||||
} else {
|
|
||||||
// TODO find a better way to do this on lollipop!
|
|
||||||
// This will actually not work due to no permission for android.permission.MODIFY_PHONE_STATE, which
|
|
||||||
// is a system level permission and cannot be accessed for third party apps.
|
|
||||||
try {
|
|
||||||
TelephonyManager tm = (TelephonyManager) context
|
|
||||||
.getSystemService(Context.TELEPHONY_SERVICE);
|
|
||||||
Class c = Class.forName(tm.getClass().getName());
|
|
||||||
Method m = c.getDeclaredMethod("getITelephony");
|
|
||||||
m.setAccessible(true);
|
|
||||||
Object telephonyService = m.invoke(tm);
|
|
||||||
c = Class.forName(telephonyService.getClass().getName());
|
|
||||||
m = c.getDeclaredMethod("setDataEnabled", Boolean.TYPE);
|
|
||||||
m.setAccessible(true);
|
|
||||||
m.invoke(telephonyService, enabled);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(TAG, "error enabling data on lollipop", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -309,8 +291,6 @@ public class Utils {
|
|||||||
long id = cursor.getLong(0);
|
long id = cursor.getLong(0);
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return id;
|
return id;
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
@@ -394,25 +374,14 @@ public class Utils {
|
|||||||
return sendSettings;
|
return sendSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether or not the user has Android 4.4 KitKat
|
|
||||||
* @return true if version code on device is >= kitkat
|
|
||||||
*/
|
|
||||||
public static boolean hasKitKat() {
|
|
||||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether or not the app is the default SMS app on a device
|
* Determines whether or not the app is the default SMS app on a device
|
||||||
* @param context
|
* @param context
|
||||||
* @return true if app is default
|
* @return true if app is default
|
||||||
*/
|
*/
|
||||||
public static boolean isDefaultSmsApp(Context context) {
|
public static boolean isDefaultSmsApp(Context context) {
|
||||||
if (hasKitKat()) {
|
return context.getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(context));
|
||||||
return context.getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user