Add read storage permisison, button emojis, reload button

This commit is contained in:
octospacc 2023-12-17 00:57:21 +01:00
parent e6316b0d3d
commit e5ed0931f7
4 changed files with 41 additions and 7 deletions

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="58571dd8" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-12-16T23:46:19.954246007Z" />
</component>
</project>

View File

@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"

View File

@ -22,6 +22,8 @@ import android.widget.Toast
import org.json.JSONObject
class MainActivity : AppCompatActivity() {
private val EVENT_SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"
private var buttonReload: MenuItem? = null
private var buttonConfigurationOpen: MenuItem? = null
private var buttonConfigurationSave: MenuItem? = null
private var buttonConfigurationCancel: MenuItem? = null
@ -55,7 +57,7 @@ class MainActivity : AppCompatActivity() {
val messageReceiver = object: BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val sharedPrefs: SharedPreferences = context.getSharedPreferences("Prefs", 0)
if (intent.action == "android.provider.Telephony.SMS_RECEIVED") {
if (intent.action == EVENT_SMS_RECEIVED) {
val bundle = intent.extras
if (bundle != null) {
// get sms objects
@ -72,7 +74,7 @@ class MainActivity : AppCompatActivity() {
}
val sender: String? = messages[0]!!.getOriginatingAddress()
val message = sb.toString()
execJavascript(" Android.onEvent('android.provider.Telephony.SMS_RECEIVED'); Android.onSmsReceived('${message}', '${sender}'); ")
execJavascript(" Android.onEvent('${EVENT_SMS_RECEIVED}'); Android.onSmsReceived('${argumentifyString(message)}', '${argumentifyString(sender.toString())}'); ")
//execJavascript("Android.SmsQueue.push({ sender: '${sender}', message: '${message}' }); Android.Callback('android.provider.Telephony.SMS_RECEIVED');")
//execJavascript("Android.SmsQueue.push({ sender: 1, message: 2 ); Android.Callback('android.provider.Telephony.SMS_RECEIVED')")
//smsListener!!.messageReceived(message)
@ -82,11 +84,12 @@ class MainActivity : AppCompatActivity() {
}
}
}
this.registerReceiver(messageReceiver, IntentFilter("android.provider.Telephony.SMS_RECEIVED"))
this.registerReceiver(messageReceiver, IntentFilter(EVENT_SMS_RECEIVED))
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_main, menu!!)
buttonReload = menu.findItem(R.id.button_reload)
buttonConfigurationOpen = menu.findItem(R.id.button_configuration_open)
buttonConfigurationSave = menu.findItem(R.id.button_configuration_save)
buttonConfigurationCancel = menu.findItem(R.id.button_configuration_cancel)
@ -97,6 +100,10 @@ class MainActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.button_reload -> {
webview!!.clearCache(true)
reloadWebview()
}
R.id.button_configuration_open -> {
reloadConfiguration()
setConfigurationView(true)
@ -132,6 +139,10 @@ class MainActivity : AppCompatActivity() {
return super.onOptionsItemSelected(item)
}
private fun argumentifyString(text: String): String {
return text.replace("\"", "\\\"").replace("'", "\\'").replace("\n", "\\n")
}
private fun showHideView(view: View) {
view.visibility = (if (view.visibility == View.VISIBLE) View.INVISIBLE else View.VISIBLE)
}
@ -145,6 +156,7 @@ class MainActivity : AppCompatActivity() {
}
private fun setConfigurationView(status: Boolean) {
buttonReload!!.isVisible = !status
buttonConfigurationOpen!!.isVisible = !status
buttonConfigurationSave!!.isVisible = status
buttonConfigurationCancel!!.isVisible = status
@ -152,7 +164,7 @@ class MainActivity : AppCompatActivity() {
setViewVisibility(webview!!, !status)
//setViewVisibility(labelLog!!, !status)
setViewVisibility(layoutConfiguration!!, status)
setTitle(if (status) "Configuration" else "WebView")
setTitle(if (status) "⚙️ Configuration" else "\uD83C\uDF10 WebView")
}
private fun reloadWebview() {

View File

@ -2,17 +2,21 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/button_reload"
android:title="🔃️ Force Reload"
app:showAsAction="never" />
<item
android:id="@+id/button_configuration_open"
android:title="Configuration"
android:title="⚙️ Configuration"
app:showAsAction="never" />
<item
android:id="@+id/button_configuration_save"
android:title="Save"
android:title="📝️ Save"
app:showAsAction="never" />
<item
android:id="@+id/button_configuration_cancel"
android:title="Cancel"
android:title="📔️ Cancel"
app:showAsAction="never" />
<!-- <item
android:id="@+id/button_clearlog"