mirror of
https://github.com/markusfisch/BinaryEye.git
synced 2024-09-19 19:42:18 +02:00
Allow file input from share menu
Updates the handleSendText method to support both types of intents. Also extends the accepted file types to text/* to also accept VCards and other text-based files.
This commit is contained in:
parent
be6539d41f
commit
24730dfde3
@ -62,7 +62,7 @@
|
|||||||
<intent-filter android:label="@string/compose_barcode">
|
<intent-filter android:label="@string/compose_barcode">
|
||||||
<action android:name="android.intent.action.SEND"/>
|
<action android:name="android.intent.action.SEND"/>
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
<data android:mimeType="text/plain"/>
|
<data android:mimeType="text/*"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.google.zxing.client.android.SCAN"/>
|
<action android:name="com.google.zxing.client.android.SCAN"/>
|
||||||
|
@ -52,6 +52,8 @@ import de.markusfisch.android.zxingcpp.ZxingCpp.BarcodeFormat
|
|||||||
import de.markusfisch.android.zxingcpp.ZxingCpp.Binarizer
|
import de.markusfisch.android.zxingcpp.ZxingCpp.Binarizer
|
||||||
import de.markusfisch.android.zxingcpp.ZxingCpp.ReaderOptions
|
import de.markusfisch.android.zxingcpp.ZxingCpp.ReaderOptions
|
||||||
import de.markusfisch.android.zxingcpp.ZxingCpp.Result
|
import de.markusfisch.android.zxingcpp.ZxingCpp.Result
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.util.Scanner
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
@ -135,7 +137,7 @@ class CameraActivity : AppCompatActivity() {
|
|||||||
initDetectorView()
|
initDetectorView()
|
||||||
|
|
||||||
if (intent?.action == Intent.ACTION_SEND &&
|
if (intent?.action == Intent.ACTION_SEND &&
|
||||||
intent.type == "text/plain"
|
intent.type?.startsWith("text/") == true
|
||||||
) {
|
) {
|
||||||
handleSendText(intent)
|
handleSendText(intent)
|
||||||
}
|
}
|
||||||
@ -347,9 +349,27 @@ class CameraActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private fun handleSendText(intent: Intent) {
|
private fun handleSendText(intent: Intent) {
|
||||||
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
|
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
|
||||||
|
|
||||||
if (text?.isEmpty() == false) {
|
if (text?.isEmpty() == false) {
|
||||||
startActivity(MainActivity.getEncodeIntent(this, text, true))
|
startActivity(MainActivity.getEncodeIntent(this, text, true))
|
||||||
finish()
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read text from file
|
||||||
|
val textUri = intent.getParcelableExtra(Intent.EXTRA_STREAM) as Uri?
|
||||||
|
if (textUri != null) {
|
||||||
|
val file = contentResolver.openFileDescriptor(textUri, "r")
|
||||||
|
if (file != null) {
|
||||||
|
val fs = FileInputStream(file.fileDescriptor)
|
||||||
|
val scn = Scanner(fs).useDelimiter("\\A")
|
||||||
|
if (scn.hasNext()) {
|
||||||
|
val fText = scn.next()
|
||||||
|
startActivity(MainActivity.getEncodeIntent(this, fText, true))
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
file.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user