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

๐Ÿ”€ :: getDefaultAdapter returns null ์—๋Ÿฌ ํ•ด๊ฒฐํ•˜๊ธฐ #206 #207

Merged
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
76 changes: 74 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (flutterRoot == null) {

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '18'
flutterVersionCode = '20'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
Expand Down Expand Up @@ -56,7 +56,7 @@ android {
applicationId "com.osj.lotura"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 21
minSdkVersion 23
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down Expand Up @@ -88,3 +88,75 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

//3.16 ์ด์ƒ๋ถ€ํ„ฐ ๋ฐ”๋€Œ๋Š”๊ฑธ ^๊ถŒ์žฅ^ ํ•˜๋Š” ์˜ต์…˜
//plugins {
// id("com.android.application")
// id("kotlin-android")
// id("dev.flutter.flutter-gradle-plugin")
// id("com.google.gms.google-services")
//}
//
//def localProperties = new Properties()
//def localPropertiesFile = rootProject.file('local.properties')
//if (localPropertiesFile.exists()) {
// localPropertiesFile.withReader('UTF-8') { reader ->
// localProperties.load(reader)
// }
//}
//
//def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
//if (flutterVersionCode == null) {
// flutterVersionCode = '19'
//}
//
//def flutterVersionName = localProperties.getProperty('flutter.versionName')
//if (flutterVersionName == null) {
// flutterVersionName = '3.3.6'
//}
//
//android {
// namespace "com.osj.lotura"
// compileSdk flutter.compileSdkVersion
// ndkVersion flutter.ndkVersion
//
// compileOptions {
// sourceCompatibility JavaVersion.VERSION_1_8
// targetCompatibility JavaVersion.VERSION_1_8
// }
//
// kotlinOptions {
// jvmTarget = '1.8'
// }
//
// sourceSets {
// main.java.srcDirs += 'src/main/kotlin'
// }
//
// defaultConfig {
// // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
// applicationId "com.osj.lotura"
// // You can update the following values to match your application needs.
// // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
// minSdkVersion 23
// targetSdkVersion flutter.targetSdkVersion
// versionCode flutterVersionCode.toInteger()
// versionName flutterVersionName
// }
//
// buildTypes {
// release {
// // TODO: Add your own signing config for the release build.
// // Signing with the debug keys for now, so `flutter run --release` works.
// signingConfig signingConfigs.debug
// }
// }
//}
//
//flutter {
// source '../..'
//}
//
//dependencies {
// implementation platform('com.google.firebase:firebase-bom:32.7.4')
//}
23 changes: 12 additions & 11 deletions android/app/src/main/kotlin/com/osj/lotura/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity : FlutterActivity() {
private lateinit var nfcAdapter: NfcAdapter
private var nfcAdapter: NfcAdapter? = null
private var returnData = -1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
nfcAdapter = NfcAdapter.getDefaultAdapter(this)
if (nfcAdapter != null) {
if (intent.action == NfcAdapter.ACTION_NDEF_DISCOVERED) {
val data = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)
val message = data?.get(0) as NdefMessage
val record = message.records[0] as NdefRecord
val byteArr = record.payload

if (intent.action == NfcAdapter.ACTION_NDEF_DISCOVERED) {
val data = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)
val message = data?.get(0) as NdefMessage
val record = message.records[0] as NdefRecord
val byteArr = record.payload

returnData = String(byteArr).toInt()
returnData = String(byteArr).toInt()
}
}
}

Expand All @@ -41,7 +42,7 @@ class MainActivity : FlutterActivity() {
}

"nfcIsAvailable" -> {
result.success(nfcAdapter.isEnabled)
result.success(nfcAdapter?.isEnabled)
}
}
}
Expand Down Expand Up @@ -77,10 +78,10 @@ class MainActivity : FlutterActivity() {
val intentFilters = arrayOf(
IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED),
)
nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFilters, null)
nfcAdapter?.enableForegroundDispatch(this, pendingIntent, intentFilters, null)
}

private fun disableNfcForegroundDispatch() {
nfcAdapter.disableForegroundDispatch(this)
nfcAdapter?.disableForegroundDispatch(this)
}
}
20 changes: 20 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,23 @@ subprojects {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}

//3.16 ์ด์ƒ๋ถ€ํ„ฐ ๋ฐ”๋€Œ๋Š”๊ฑธ ^๊ถŒ์žฅ^ ํ•˜๋Š” ์˜ต์…˜
//allprojects {
// repositories {
// google()
// mavenCentral()
// }
//}
//
//rootProject.buildDir = '../build'
//subprojects {
// project.buildDir = "${rootProject.buildDir}/${project.name}"
//}
//subprojects {
// project.evaluationDependsOn(':app')
//}
//
//tasks.register("clean", Delete) {
// delete rootProject.buildDir
//}
28 changes: 28 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,31 @@ localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
//3.16 ์ด์ƒ๋ถ€ํ„ฐ ๋ฐ”๋€Œ๋Š”๊ฑธ ^๊ถŒ์žฅ^ ํ•˜๋Š” ์˜ต์…˜
//pluginManagement {
// def flutterSdkPath = {
// def properties = new Properties()
// file("local.properties").withInputStream { properties.load(it) }
// def flutterSdkPath = properties.getProperty("flutter.sdk")
// assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
// return flutterSdkPath
// }
// settings.ext.flutterSdkPath = flutterSdkPath()
//
// includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
//
// repositories {
// google()
// mavenCentral()
// gradlePluginPortal()
// }
//}
//
//plugins {
// id "dev.flutter.flutter-plugin-loader" version "1.0.0"
// id "com.android.application" version "7.3.0" apply false
// id "org.jetbrains.kotlin.android" version "1.7.10" apply false
// id "com.google.gms.google-services" version "4.3.14" apply false
//}
//
//include ":app"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 3.3.6+18
version: 3.3.6+20

environment:
sdk: '>=3.1.3 <4.0.0'
Expand Down