@@ -6,6 +6,7 @@ import android.content.ClipboardManager
6
6
import android.content.DialogInterface
7
7
import android.content.Intent
8
8
import android.net.Uri
9
+ import android.os.Build
9
10
import android.os.Bundle
10
11
import android.provider.OpenableColumns
11
12
import android.util.Log
@@ -53,15 +54,15 @@ class MainActivity : AppCompatActivity() {
53
54
binding = ActivityMainBinding .inflate(layoutInflater)
54
55
setContentView(binding.root)
55
56
56
- webView = findViewById( R .id. webview)
57
+ webView = binding. webview
57
58
webView.settings.domStorageEnabled = true
58
59
webView.settings.javaScriptEnabled = true
59
60
webView.settings.userAgentString = " DjangoFiles Android"
60
61
webView.addJavascriptInterface(WebAppInterface (this ), " Android" )
61
62
webView.setWebViewClient(MyWebViewClient ())
62
63
63
64
ViewCompat .setOnApplyWindowInsetsListener(
64
- findViewById( R .id. main)
65
+ binding. main
65
66
) { v: View , insets: WindowInsetsCompat ->
66
67
val systemBars = insets.getInsets(WindowInsetsCompat .Type .systemBars())
67
68
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
@@ -90,7 +91,6 @@ class MainActivity : AppCompatActivity() {
90
91
}
91
92
92
93
private fun handleIntent (intent : Intent ) {
93
- // TODO: Need to do some serious debugging on intent handling...
94
94
val uri = intent.data
95
95
Log .d(" handleIntent" , " uri: $uri " )
96
96
@@ -158,29 +158,61 @@ class MainActivity : AppCompatActivity() {
158
158
} else if (Intent .ACTION_SEND == action && mimeType != null ) {
159
159
Log .d(" handleIntent" , " ACTION_SEND" )
160
160
if (" text/plain" == mimeType) {
161
+ val sharedText: String? = intent.getStringExtra(Intent .EXTRA_TEXT )
162
+ if (sharedText != null ) {
163
+ Log .d(" handleIntent" , " Received text/plain: $sharedText " )
164
+ if (sharedText.startsWith(" content://" )) {
165
+ val fileUri = Uri .parse(sharedText)
166
+ Log .d(" handleIntent" , " Received URI: $fileUri " )
167
+ } else {
168
+ Log .d(" handleIntent" , " Received text/plain: $sharedText " )
169
+ }
170
+ }
171
+ val preferences = getSharedPreferences(PREFS_NAME , MODE_PRIVATE )
172
+ val savedUrl = preferences.getString(URL_KEY , null )
173
+ Log .d(" handleIntent" , " savedUrl: ${savedUrl} /paste/" )
174
+ webView.loadUrl(" ${savedUrl} /paste/" )
161
175
Toast .makeText(
162
176
this ,
163
177
this .getString(R .string.tst_not_implemented),
164
178
Toast .LENGTH_SHORT
165
179
).show()
166
180
} else {
167
- val fileUri = intent.getParcelableExtra<Uri >(Intent .EXTRA_STREAM )
181
+ // val fileUri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
182
+ val fileUri = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
183
+ intent.getParcelableExtra(Intent .EXTRA_STREAM , Uri ::class .java)
184
+ } else {
185
+ @Suppress(" DEPRECATION" )
186
+ intent.getParcelableExtra(Intent .EXTRA_STREAM )
187
+ }
168
188
if (fileUri != null ) {
169
189
processSharedFile(fileUri)
190
+ } else {
191
+ Log .w(" handleIntent" , " URI is NULL" )
170
192
}
171
193
}
172
194
} else if (Intent .ACTION_SEND_MULTIPLE == action) {
173
195
Log .d(" handleIntent" , " ACTION_SEND_MULTIPLE" )
174
- val fileUris = intent.getParcelableArrayListExtra<Uri >(Intent .EXTRA_STREAM )
196
+ // val fileUris = intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)
197
+ val fileUris = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
198
+ intent.getParcelableArrayListExtra(Intent .EXTRA_STREAM , Uri ::class .java)
199
+ } else {
200
+ @Suppress(" DEPRECATION" )
201
+ intent.getParcelableArrayListExtra(Intent .EXTRA_STREAM )
202
+ }
175
203
if (fileUris != null ) {
176
204
for (fileUri in fileUris) {
177
205
processSharedFile(fileUri)
178
206
}
207
+ } else {
208
+ Log .w(" handleIntent" , " URI is NULL" )
179
209
}
210
+ } else {
211
+ Toast .makeText(this , " Unknown Intent!" , Toast .LENGTH_SHORT ).show()
212
+ Log .w(" handleIntent" , " All Intent Types Processed. No Match!" )
180
213
}
181
214
}
182
215
183
-
184
216
private fun showSettingsDialog () {
185
217
val preferences = getSharedPreferences(PREFS_NAME , MODE_PRIVATE )
186
218
val savedUrl = preferences.getString(URL_KEY , null )
0 commit comments