forked from jens/Automation
mms
This commit is contained in:
parent
93cb72ac2f
commit
98df050f42
@ -1220,21 +1220,37 @@ public class Actions
|
|||||||
|
|
||||||
public static void sendTextMessage(Context context, String[] parametersArray)
|
public static void sendTextMessage(Context context, String[] parametersArray)
|
||||||
{
|
{
|
||||||
String phoneNumber, message;
|
String phoneNumber, message, messageType = "sms", filePath = null;
|
||||||
|
|
||||||
phoneNumber = parametersArray[0];
|
phoneNumber = parametersArray[0];
|
||||||
message = parametersArray[1];
|
message = parametersArray[1];
|
||||||
|
|
||||||
|
if(parametersArray.length > 2)
|
||||||
|
{
|
||||||
|
messageType = parametersArray[2];
|
||||||
|
|
||||||
|
if(parametersArray.length > 3)
|
||||||
|
filePath = parametersArray[3];
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String textToSend = Miscellaneous.replaceVariablesInText(message, context);
|
String textToSend = Miscellaneous.replaceVariablesInText(message, context);
|
||||||
|
if(messageType.equals("sms"))
|
||||||
|
sendSmsMessage(phoneNumber, textToSend);
|
||||||
|
else
|
||||||
|
sendMmsMessage(phoneNumber, textToSend, filePath);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("e", Miscellaneous.getAnyContext().getString(R.string.sendTextMessage), "Error in sendTextMessage: " + Log.getStackTraceString(e), 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
private static void sendSmsMessage(String phoneNumber, String textToSend)
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
|
{
|
||||||
intent.putExtra("sms_body", message);
|
try
|
||||||
AutomationService.getInstance().startActivity(intent);
|
{
|
||||||
*/
|
|
||||||
|
|
||||||
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, Actions.class), 0);
|
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, Actions.class), 0);
|
||||||
SmsManager sms = SmsManager.getDefault();
|
SmsManager sms = SmsManager.getDefault();
|
||||||
sms.sendTextMessage(phoneNumber, null, textToSend, pi, null);
|
sms.sendTextMessage(phoneNumber, null, textToSend, pi, null);
|
||||||
@ -1245,6 +1261,29 @@ public class Actions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void sendMmsMessage(String phoneNumber, String textToSend, String fileToBeAttached)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, Actions.class), 0);
|
||||||
|
SmsManager sms = SmsManager.getDefault();
|
||||||
|
sms.sendMultimediaMessage(phoneNumber, null, textToSend, pi, null);
|
||||||
|
|
||||||
|
if(!StringUtils.isEmpty(fileToBeAttached))
|
||||||
|
{
|
||||||
|
Uri uri = Uri.parse("file://" + fileToBeAttached);
|
||||||
|
i.putExtra(Intent.EXTRA_STREAM, "file:/" + uri);
|
||||||
|
i.setType("image/png");
|
||||||
|
}
|
||||||
|
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Miscellaneous.logEvent("e", Miscellaneous.getAnyContext().getString(R.string.sendTextMessage), "Error in sendTextMessage: " + Log.getStackTraceString(e), 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class WakeUpDeviceClass implements Runnable
|
private static class WakeUpDeviceClass implements Runnable
|
||||||
{
|
{
|
||||||
private long awakeTime;
|
private long awakeTime;
|
||||||
|
@ -17,6 +17,7 @@ import android.widget.CompoundButton;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@ -29,9 +30,11 @@ public class ActivityManageActionSendTextMessage extends Activity
|
|||||||
Button bSaveSendTextMessage, bImportNumberFromContacts, bMmsAttachment;
|
Button bSaveSendTextMessage, bImportNumberFromContacts, bMmsAttachment;
|
||||||
EditText etPhoneNumber, etSendTextMessage;
|
EditText etPhoneNumber, etSendTextMessage;
|
||||||
RadioButton rbMessageTypeSms, rbMessageTypeMms;
|
RadioButton rbMessageTypeSms, rbMessageTypeMms;
|
||||||
|
TextView tvSendMmsFileAttachment;
|
||||||
|
|
||||||
protected final static int requestCodeForContactsPermissions = 9876;
|
protected final static int requestCodeForContactsPermissions = 9876;
|
||||||
protected final static int requestCodeGetContact = 3235;
|
protected final static int requestCodeGetContact = 3235;
|
||||||
|
protected final static int requestCodeGetMMSattachment = 3236;
|
||||||
|
|
||||||
public static boolean edit = false;
|
public static boolean edit = false;
|
||||||
public static Action resultingAction = null;
|
public static Action resultingAction = null;
|
||||||
@ -49,6 +52,7 @@ public class ActivityManageActionSendTextMessage extends Activity
|
|||||||
rbMessageTypeSms = (RadioButton)findViewById(R.id.rbMessageTypeSms);
|
rbMessageTypeSms = (RadioButton)findViewById(R.id.rbMessageTypeSms);
|
||||||
rbMessageTypeMms = (RadioButton) findViewById(R.id.rbMessageTypeMms);
|
rbMessageTypeMms = (RadioButton) findViewById(R.id.rbMessageTypeMms);
|
||||||
bMmsAttachment = (Button)findViewById(R.id.bMmsAttachment);
|
bMmsAttachment = (Button)findViewById(R.id.bMmsAttachment);
|
||||||
|
tvSendMmsFileAttachment = (TextView)findViewById(R.id.tvSendMmsFileAttachment);
|
||||||
|
|
||||||
bSaveSendTextMessage.setOnClickListener(new OnClickListener()
|
bSaveSendTextMessage.setOnClickListener(new OnClickListener()
|
||||||
{
|
{
|
||||||
@ -94,6 +98,18 @@ public class ActivityManageActionSendTextMessage extends Activity
|
|||||||
rbMessageTypeSms.setOnCheckedChangeListener(checkedChangedListener);
|
rbMessageTypeSms.setOnCheckedChangeListener(checkedChangedListener);
|
||||||
rbMessageTypeMms.setOnCheckedChangeListener(checkedChangedListener);
|
rbMessageTypeMms.setOnCheckedChangeListener(checkedChangedListener);
|
||||||
|
|
||||||
|
bMmsAttachment.setOnClickListener(new OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View view)
|
||||||
|
{
|
||||||
|
Intent chooseFileIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
|
chooseFileIntent.setType("*/*");
|
||||||
|
chooseFileIntent = Intent.createChooser(chooseFileIntent, getResources().getString(R.string.chooseFile));
|
||||||
|
startActivityForResult(chooseFileIntent, requestCodeGetMMSattachment);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ActivityManageActionSendTextMessage.edit = getIntent().getBooleanExtra("edit", false);
|
ActivityManageActionSendTextMessage.edit = getIntent().getBooleanExtra("edit", false);
|
||||||
if(edit)
|
if(edit)
|
||||||
{
|
{
|
||||||
@ -159,10 +175,10 @@ public class ActivityManageActionSendTextMessage extends Activity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||||
{
|
|
||||||
if(requestCode == requestCodeGetContact)
|
|
||||||
{
|
{
|
||||||
if(resultCode == Activity.RESULT_OK)
|
if(resultCode == Activity.RESULT_OK)
|
||||||
|
{
|
||||||
|
if(requestCode == requestCodeGetContact)
|
||||||
{
|
{
|
||||||
String phoneNo = null;
|
String phoneNo = null;
|
||||||
String name = null;
|
String name = null;
|
||||||
@ -181,6 +197,12 @@ public class ActivityManageActionSendTextMessage extends Activity
|
|||||||
etPhoneNumber.setText(phoneNo);
|
etPhoneNumber.setText(phoneNo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (requestCode == requestCodeGetMMSattachment)
|
||||||
|
{
|
||||||
|
Uri fileUri = data.getData();
|
||||||
|
String filePath = fileUri.getPath();
|
||||||
|
tvSendMmsFileAttachment.setText(filePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//super.onActivityResult(requestCode, resultCode, data);
|
//super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@
|
|||||||
android:text="@string/attachment" />
|
android:text="@string/attachment" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/sendMmsFileAttachment"
|
android:id="@+id/tvSendMmsFileAttachment"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user