This commit is contained in:
Jens 2022-11-10 23:06:07 +01:00
parent 93cb72ac2f
commit 98df050f42
3 changed files with 73 additions and 12 deletions

View File

@ -1220,21 +1220,37 @@ public class Actions
public static void sendTextMessage(Context context, String[] parametersArray)
{
String phoneNumber, message;
String phoneNumber, message, messageType = "sms", filePath = null;
phoneNumber = parametersArray[0];
message = parametersArray[1];
if(parametersArray.length > 2)
{
messageType = parametersArray[2];
if(parametersArray.length > 3)
filePath = parametersArray[3];
}
try
{
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);
}
}
/*
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
intent.putExtra("sms_body", message);
AutomationService.getInstance().startActivity(intent);
*/
private static void sendSmsMessage(String phoneNumber, String textToSend)
{
try
{
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, Actions.class), 0);
SmsManager sms = SmsManager.getDefault();
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 long awakeTime;

View File

@ -17,6 +17,7 @@ import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@ -29,9 +30,11 @@ public class ActivityManageActionSendTextMessage extends Activity
Button bSaveSendTextMessage, bImportNumberFromContacts, bMmsAttachment;
EditText etPhoneNumber, etSendTextMessage;
RadioButton rbMessageTypeSms, rbMessageTypeMms;
TextView tvSendMmsFileAttachment;
protected final static int requestCodeForContactsPermissions = 9876;
protected final static int requestCodeGetContact = 3235;
protected final static int requestCodeGetMMSattachment = 3236;
public static boolean edit = false;
public static Action resultingAction = null;
@ -49,6 +52,7 @@ public class ActivityManageActionSendTextMessage extends Activity
rbMessageTypeSms = (RadioButton)findViewById(R.id.rbMessageTypeSms);
rbMessageTypeMms = (RadioButton) findViewById(R.id.rbMessageTypeMms);
bMmsAttachment = (Button)findViewById(R.id.bMmsAttachment);
tvSendMmsFileAttachment = (TextView)findViewById(R.id.tvSendMmsFileAttachment);
bSaveSendTextMessage.setOnClickListener(new OnClickListener()
{
@ -94,6 +98,18 @@ public class ActivityManageActionSendTextMessage extends Activity
rbMessageTypeSms.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);
if(edit)
{
@ -159,10 +175,10 @@ public class ActivityManageActionSendTextMessage extends Activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == requestCodeGetContact)
{
if(resultCode == Activity.RESULT_OK)
{
if(requestCode == requestCodeGetContact)
{
String phoneNo = null;
String name = null;
@ -181,6 +197,12 @@ public class ActivityManageActionSendTextMessage extends Activity
etPhoneNumber.setText(phoneNo);
}
}
else if (requestCode == requestCodeGetMMSattachment)
{
Uri fileUri = data.getData();
String filePath = fileUri.getPath();
tvSendMmsFileAttachment.setText(filePath);
}
}
//super.onActivityResult(requestCode, resultCode, data);
}

View File

@ -97,7 +97,7 @@
android:text="@string/attachment" />
<TextView
android:id="@+id/sendMmsFileAttachment"
android:id="@+id/tvSendMmsFileAttachment"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />