Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #49 to help enable NFC #53

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions app/src/main/java/com/tananaev/passportreader/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import android.util.Log
import android.view.View
import android.view.WindowManager
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
import com.tananaev.passportreader.ImageUtil.decodeImage
Expand Down Expand Up @@ -164,11 +165,22 @@ abstract class MainActivity : AppCompatActivity() {
super.onResume()
val adapter = NfcAdapter.getDefaultAdapter(this)
if (adapter != null) {
val intent = Intent(applicationContext, this.javaClass)
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_MUTABLE)
val filter = arrayOf(arrayOf("android.nfc.tech.IsoDep"))
adapter.enableForegroundDispatch(this, pendingIntent, null, filter)
if (adapter.isEnabled) {
val intent = Intent(applicationContext, this.javaClass)
intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
val pendingIntent =
PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_MUTABLE)
val filter = arrayOf(arrayOf("android.nfc.tech.IsoDep"))
adapter.enableForegroundDispatch(this, pendingIntent, null, filter)
} else {
Toast.makeText(
applicationContext,
getString(R.string.enable_nfc_toast),
Toast.LENGTH_LONG
).show();
Thread.sleep(5_000)
nickoe marked this conversation as resolved.
Show resolved Hide resolved
startActivity(Intent(android.provider.Settings.ACTION_NFC_SETTINGS));
}
}
if (passportNumberFromIntent) {
// When the passport number field is populated from the caller, we hide the
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
<string name="pass">Pass</string>
<string name="failed">Failed</string>

<string name="enable_nfc_toast">Please activate NFC and press Back to return to the application!</string>
</resources>