Browse Source

don't crash on devices without nfc

pull/31/head
Jannik 3 years ago
parent
commit
6cc1671a52
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 30
      app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt
  2. 4
      fastlane/metadata/android/en-US/chnagelogs/14.txt

30
app/src/main/java/org/mosad/seil0/projectlaogai/MainActivity.kt

@ -23,10 +23,12 @@
package org.mosad.seil0.projectlaogai
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Color
import android.nfc.NfcAdapter
import android.nfc.NfcManager
import android.nfc.tech.NfcA
import android.os.Bundle
import android.view.Menu
@ -58,6 +60,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
private lateinit var pendingIntent: PendingIntent
private lateinit var intentFiltersArray: Array<IntentFilter>
private lateinit var techListsArray: Array<Array<String>>
private var useNFC = false
override fun onCreate(savedInstanceState: Bundle?) {
Aesthetic.attach(this)
@ -99,14 +102,16 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
override fun onResume() {
super.onResume()
Aesthetic.resume(this)
adapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techListsArray)
if(useNFC)
adapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techListsArray)
}
override fun onPause() {
super.onPause()
Aesthetic.pause(this)
adapter.disableForegroundDispatch(this)
if(useNFC)
adapter.disableForegroundDispatch(this)
}
override fun onBackPressed() {
@ -189,14 +194,19 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}
private fun initForegroundDispatch() {
intentFiltersArray = arrayOf(IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED).apply { addDataType("*/*") })
techListsArray = arrayOf(arrayOf(NfcA::class.java.name))
adapter = NfcAdapter.getDefaultAdapter(this)
pendingIntent = PendingIntent.getActivity(
this, 0,
Intent(this, javaClass).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0
)
val nfcManager = this.getSystemService(Context.NFC_SERVICE) as NfcManager
val nfcAdapter = nfcManager.defaultAdapter
if (nfcAdapter != null) {
useNFC = true
intentFiltersArray = arrayOf(IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED).apply { addDataType("*/*") })
techListsArray = arrayOf(arrayOf(NfcA::class.java.name))
adapter = NfcAdapter.getDefaultAdapter(this)
pendingIntent = PendingIntent.getActivity(
this, 0,
Intent(this, javaClass).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0
)
}
}
}

4
fastlane/metadata/android/en-US/chnagelogs/14.txt

@ -1,5 +1,7 @@
This release 0.5.0 is called "artistical Apollon".
* new: it's now possible to choos a theme (light, dark or balck)
* change: updated some libs, updated kotlin to 1.3.40
* new: you can now check your current mensa card balance
* change: updated some libs, updated kotlin to 1.3.41
* fix: the mensa should now show the correct meals on sunday/monday
* fix: the timetable should now show the correct on the sunday/monday change

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close