send broadcasts action
This commit is contained in:
@ -49,6 +49,7 @@ public class Action
|
||||
vibrate,
|
||||
createNotification,
|
||||
closeNotification,
|
||||
sendBroadcast,
|
||||
sendTextMessage;
|
||||
|
||||
public String getFullName(Context context)
|
||||
@ -119,6 +120,8 @@ public class Action
|
||||
return context.getResources().getString(R.string.createNotification);
|
||||
case closeNotification:
|
||||
return context.getResources().getString(R.string.closeNotifications);
|
||||
case sendBroadcast:
|
||||
return context.getResources().getString(R.string.sendBroadcast);
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
@ -259,6 +262,9 @@ public class Action
|
||||
case closeNotification:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.closeNotifications));
|
||||
break;
|
||||
case sendBroadcast:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.sendBroadcast));
|
||||
break;
|
||||
default:
|
||||
returnString.append(action.toString());
|
||||
}
|
||||
@ -534,6 +540,9 @@ public class Action
|
||||
else
|
||||
Miscellaneous.logEvent("w", "Close notification", "Close notification was requested, but OS version is too low: " + String.valueOf(Build.VERSION.SDK_INT), 2);
|
||||
break;
|
||||
case sendBroadcast:
|
||||
Actions.sendBroadcast(context, this.getParameter2());
|
||||
break;
|
||||
default:
|
||||
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);
|
||||
break;
|
||||
@ -637,7 +646,7 @@ public class Action
|
||||
//Do something with result
|
||||
//Toast.makeText(context, text, duration) result;
|
||||
Miscellaneous.logEvent("i", "HTTP RESULT", result, 3);
|
||||
Actions myAction=new Actions();
|
||||
Actions myAction = new Actions();
|
||||
myAction.useDownloadedWebpage(result);
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +185,15 @@ public class Actions
|
||||
}
|
||||
}
|
||||
|
||||
public static class WifiStuff
|
||||
public static void sendBroadcast(Context context, String action)
|
||||
{
|
||||
Miscellaneous.logEvent("i", "sendBroadcast", "Sending broadcast with action " + action, 5);
|
||||
Intent broadcastIntent = new Intent();
|
||||
broadcastIntent.setAction(action);
|
||||
context.sendBroadcast(broadcastIntent);
|
||||
}
|
||||
|
||||
public static class WifiStuff
|
||||
{
|
||||
public static Boolean setWifi(Context context, Boolean desiredState, boolean toggleActionIfPossible)
|
||||
{
|
||||
|
@ -0,0 +1,83 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ActivityManageActionSendBroadcast extends Activity
|
||||
{
|
||||
EditText etBroadcastToSend;
|
||||
Button bBroadcastSendShowSuggestions, bSaveSendBroadcast;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_manage_action_send_broadcast);
|
||||
|
||||
etBroadcastToSend = (EditText)findViewById(R.id.etBroadcastToSend);
|
||||
bBroadcastSendShowSuggestions = (Button)findViewById(R.id.bBroadcastSendShowSuggestions);
|
||||
bSaveSendBroadcast = (Button)findViewById(R.id.bSaveSendBroadcast);
|
||||
|
||||
bSaveSendBroadcast.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
if(checkInput())
|
||||
{
|
||||
Intent answer = new Intent();
|
||||
answer.putExtra(ActivityManageRule.intentNameActionParameter2, etBroadcastToSend.getText().toString());
|
||||
setResult(RESULT_OK, answer);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bBroadcastSendShowSuggestions.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityManageActionSendBroadcast.this);
|
||||
builder.setTitle(getResources().getString(R.string.selectBroadcast));
|
||||
builder.setItems(ActivityManageTriggerBroadcast.broadcastSuggestions, new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int which)
|
||||
{
|
||||
etBroadcastToSend.setText(ActivityManageTriggerBroadcast.broadcastSuggestions[which]);
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
}
|
||||
});
|
||||
|
||||
Intent input = getIntent();
|
||||
|
||||
if(input.hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
etBroadcastToSend.setText(input.getStringExtra(ActivityManageRule.intentNameActionParameter2));
|
||||
}
|
||||
|
||||
boolean checkInput()
|
||||
{
|
||||
String broadcastToSend = etBroadcastToSend.getText().toString();
|
||||
if(StringUtils.isEmpty(broadcastToSend))
|
||||
{
|
||||
Toast.makeText(ActivityManageActionSendBroadcast.this, getResources().getString(R.string.enterBroadcast), Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -121,6 +121,8 @@ public class ActivityManageRule extends Activity
|
||||
final static int requestCodeActionControlMediaEdit = 808;
|
||||
final static int requestCodeTriggerBroadcastReceivedAdd = 809;
|
||||
final static int requestCodeTriggerBroadcastReceivedEdit = 810;
|
||||
final static int requestCodeActionSendBroadcastAdd = 811;
|
||||
final static int requestCodeActionSendBroadcastEdit = 812;
|
||||
|
||||
public static ActivityManageRule getInstance()
|
||||
{
|
||||
@ -375,6 +377,11 @@ public class ActivityManageRule extends Activity
|
||||
activityEditVibrateIntent.putExtra("vibratePattern", a.getParameter2());
|
||||
startActivityForResult(activityEditVibrateIntent, requestCodeActionVibrateEdit);
|
||||
break;
|
||||
case sendBroadcast:
|
||||
Intent activityEditSendBroadcastIntent = new Intent(ActivityManageRule.this, ActivityManageActionSendBroadcast.class);
|
||||
activityEditSendBroadcastIntent.putExtra(intentNameActionParameter2, a.getParameter2());
|
||||
startActivityForResult(activityEditSendBroadcastIntent, requestCodeActionSendBroadcastEdit);
|
||||
break;
|
||||
case controlMediaPlayback:
|
||||
Intent activityEditControlMediaIntent = new Intent(ActivityManageRule.this, ActivityManageActionControlMedia.class);
|
||||
activityEditControlMediaIntent.putExtra(ActivityManageRule.intentNameActionParameter2, a.getParameter2());
|
||||
@ -1472,6 +1479,16 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionSendBroadcastAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionControlMediaAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
@ -1518,6 +1535,18 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionSendBroadcastEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter2))
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionControlMediaEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
@ -1728,6 +1757,8 @@ public class ActivityManageRule extends Activity
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.notification));
|
||||
else if(types[i].toString().equals(Action_Enum.closeNotification.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.notification));
|
||||
else if(types[i].toString().equals(Action_Enum.sendBroadcast.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.satellite));
|
||||
else if(types[i].toString().equals(Action_Enum.sendTextMessage.toString()))
|
||||
{
|
||||
// if(ActivityPermissions.isPermissionDeclaratedInManifest(ActivityManageSpecificRule.this, "android.permission.SEND_SMS") && !Miscellaneous.isGooglePlayInstalled(ActivityManageSpecificRule.this))
|
||||
@ -1890,6 +1921,12 @@ public class ActivityManageRule extends Activity
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionVibrate.class);
|
||||
startActivityForResult(intent, requestCodeActionVibrateAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.sendBroadcast.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.sendBroadcast);
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionSendBroadcast.class);
|
||||
startActivityForResult(intent, requestCodeActionSendBroadcastAdd);
|
||||
}
|
||||
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.controlMediaPlayback.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.controlMediaPlayback);
|
||||
|
@ -96,7 +96,7 @@ public class ActivityManageTriggerBroadcast extends Activity
|
||||
});
|
||||
}
|
||||
|
||||
String[] broadcastSuggestions = {
|
||||
public static String[] broadcastSuggestions = {
|
||||
"android.accounts.LOGIN_ACCOUNTS_CHANGED",
|
||||
"android.accounts.action.ACCOUNT_REMOVED",
|
||||
"android.app.action.ACTION_PASSWORD_CHANGED",
|
||||
|
@ -12,6 +12,7 @@ import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import com.jens.automation2.Actions;
|
||||
import com.jens.automation2.ActivityPermissions;
|
||||
import com.jens.automation2.AutomationService;
|
||||
import com.jens.automation2.Miscellaneous;
|
||||
@ -134,11 +135,11 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
|
||||
if(keyguardManager.isKeyguardLocked() && !keyguardManager.isDeviceLocked())
|
||||
{
|
||||
sendLockBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithoutSecurity);
|
||||
Actions.sendBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithoutSecurity);
|
||||
}
|
||||
else if(keyguardManager.isDeviceLocked())
|
||||
{
|
||||
sendLockBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithSecurity);
|
||||
Actions.sendBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithSecurity);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -232,13 +233,13 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
|
||||
if(keyguardManager.isKeyguardLocked() && !keyguardManager.isDeviceLocked())
|
||||
{
|
||||
sendLockBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithoutSecurity);
|
||||
Actions.sendBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithoutSecurity);
|
||||
timer.purge();
|
||||
timer.cancel();
|
||||
}
|
||||
else if(keyguardManager.isDeviceLocked())
|
||||
{
|
||||
sendLockBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithSecurity);
|
||||
Actions.sendBroadcast(Miscellaneous.getAnyContext(), broadcastScreenLockedWithSecurity);
|
||||
timer.purge();
|
||||
timer.cancel();
|
||||
}
|
||||
@ -270,11 +271,4 @@ public class ScreenStateReceiver extends BroadcastReceiver implements Automation
|
||||
timer.scheduleAtFixedRate(task, 0, interval);
|
||||
}
|
||||
}
|
||||
|
||||
static void sendLockBroadcast(Context context, String lockType)
|
||||
{
|
||||
Intent lockedBroadcastIntent = new Intent();
|
||||
lockedBroadcastIntent.setAction(lockType);
|
||||
context.sendBroadcast(lockedBroadcastIntent);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/default_margin" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_span="2"
|
||||
android:textSize="25dp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="@dimen/default_margin"
|
||||
android:text="@string/sendBroadcast" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/broadcastExplanation" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etBroadcastToSend"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="@dimen/default_margin"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/bBroadcastSendShowSuggestions"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="@dimen/default_margin"
|
||||
android:text="@string/broadcastsShowSuggestions" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bSaveSendBroadcast"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/save" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
@ -716,7 +716,5 @@
|
||||
<string name="lockedWithoutSecurity">gesperrt (nur wischen, keine PIN, etc.)</string>
|
||||
<string name="lockedWithSecurity">gesperrt (mit PIN, etc.)</string>
|
||||
<string name="lockedCommentScreenMustBeOff">Jeglicher Sperrzustand wird nur erkannt werden, wenn gleichzeitig der Bildschirm aus ist.</string>
|
||||
<string name="lockedCommentScreenMustBeOff">J</string>
|
||||
<string name="emailPretext">Wenn Sie ein Problem, einen Vorschlag oder eine Frage haben, schreiben Sie bitte auch etwas in die Email. Senden Sie mir nicht einfach die Dateien mit dem Standard-Mailtext. Ich werde solche Nachrichten ignorieren, sollten wir nicht bereits in einer Konversation sein.</string>
|
||||
<string name="emailPretext">W</string>
|
||||
</resources>
|
||||
</resources>
|
@ -816,4 +816,7 @@
|
||||
<string name="lockedWithSecurity">locked (with PIN, etc.)</string>
|
||||
<string name="lockedCommentScreenMustBeOff">Any state of locked will only be detected if the screen is off.</string>
|
||||
<string name="emailPretext">If you have a problem, suggestions or question, please write something in the email. Do not just send me the files with the default mail body. I will ignore everything those unless we\'re already in a conversation.</string>
|
||||
<string name="sendBroadcast">Send broadcast</string>
|
||||
<string name="enterBroadcast">Enter a broadcast action.</string>
|
||||
<string name="broadcastExplanation">This action allows to send a broadcast across the Android OS messaging system. This is not user-visible, but apps who listen for that specific broadcast can respond to it being sent.</string>
|
||||
</resources>
|
Reference in New Issue
Block a user