├── .gitignore ├── LICENSE.txt ├── Readme.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── implementationApp ├── .gitignore ├── build.gradle ├── gradle.properties ├── proguard-rules.txt └── src │ ├── androidTest │ └── java │ │ └── be │ │ └── appfoundry │ │ └── nfc │ │ └── implementation │ │ ├── TestEmptyFieldsNfcActivity.java │ │ └── TestFilledFieldsNfcActivity.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── be │ │ └── appfoundry │ │ └── nfc │ │ └── implementation │ │ └── MainActivity.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ └── activity_main.xml │ ├── menu │ ├── main.xml │ └── nfc.xml │ ├── values-nl │ └── strings.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── nfclib ├── .gitignore ├── build.gradle ├── proguard-rules.txt └── src │ ├── androidTest │ └── java │ │ └── be │ │ └── appfoundry │ │ └── nfclibrary │ │ └── utilities │ │ ├── TestUtilities.java │ │ ├── async │ │ ├── AbstractFailsTestsAsync.java │ │ └── GenericTaskTestsAsync.java │ │ └── sync │ │ ├── WriteEmailFailsTests.java │ │ ├── WriteEmailSucceedsTests.java │ │ ├── WriteGeolocationFailsTests.java │ │ ├── WriteGeolocationSucceedsTests.java │ │ ├── WritePhoneFailsTests.java │ │ ├── WritePhoneSucceedsTests.java │ │ ├── WriteUriFailsTests.java │ │ └── WriteUriSucceedsTests.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── be │ │ └── appfoundry │ │ └── nfclibrary │ │ ├── activities │ │ └── NfcActivity.java │ │ ├── constants │ │ ├── NfcPayloadHeader.java │ │ └── NfcType.java │ │ ├── exceptions │ │ ├── InsufficientCapacityException.java │ │ ├── ReadOnlyTagException.java │ │ ├── TagNotPresentException.java │ │ └── TagNotWritableException.java │ │ ├── tasks │ │ ├── GenericTask.java │ │ └── interfaces │ │ │ ├── AsyncOperationCallback.java │ │ │ └── AsyncUiCallback.java │ │ └── utilities │ │ ├── async │ │ ├── AbstractNfcAsync.java │ │ ├── WriteBluetoothNfcAsync.java │ │ ├── WriteCallbackNfcAsync.java │ │ ├── WriteEmailNfcAsync.java │ │ ├── WriteGeoLocationNfcAsync.java │ │ ├── WritePhoneNfcAsync.java │ │ ├── WriteSmsNfcAsync.java │ │ └── WriteUriNfcAsync.java │ │ ├── interfaces │ │ ├── AsyncNfcWriteOperation.java │ │ ├── NdefWrite.java │ │ ├── NfcMessageUtility.java │ │ ├── NfcReadUtility.java │ │ ├── NfcWriteUtility.java │ │ └── WriteUtility.java │ │ └── sync │ │ ├── NdefWriteImpl.java │ │ ├── NfcMessageUtilityImpl.java │ │ ├── NfcReadUtilityImpl.java │ │ ├── NfcWriteUtilityImpl.java │ │ └── WriteUtilityImpl.java │ └── res │ └── xml │ └── nfc_tech.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright: Benjamin Weiss (keyboardsurfer) https://github.com/keyboardsurfer 2 | # Under CC-BY-SA V3.0 (https://creativecommons.org/licenses/by-sa/3.0/legalcode) 3 | 4 | #Jenv file 5 | .java-version 6 | 7 | # built application files 8 | *.apk 9 | *.ap_ 10 | *.jar 11 | 12 | # lint folder 13 | lint 14 | 15 | # files for the dex VM 16 | *.dex 17 | 18 | # Java class files 19 | *.class 20 | 21 | # generated files 22 | bin/ 23 | gen/ 24 | classes/ 25 | gen-external-apklibs/ 26 | javadoc/ 27 | # maven output folder 28 | target 29 | 30 | # Local configuration file (sdk path, etc) 31 | local.properties 32 | 33 | # Eclipse project files 34 | .classpath 35 | .project 36 | .metadata 37 | .settings 38 | 39 | # IntelliJ files 40 | .idea 41 | *.iml 42 | 43 | # OSX files 44 | .DS_Store 45 | *.DS_Store 46 | clover/* 47 | # Windows files 48 | Thumbs.db 49 | 50 | # vi swap files 51 | *.swp 52 | 53 | # backup files 54 | *.bak 55 | 56 | # gradle directory 57 | .gradle 58 | #gradlew 59 | #gradlew.bat 60 | #gradle/ 61 | !/gradle/** 62 | build/ 63 | 64 | #for oh-my-zsh jira plugin (https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#jira) 65 | .jira-url 66 | atlassian-ide-plugin.xml 67 | 68 | .clover/ 69 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 AppFoundry 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Android NFC Library 2 | 3 | 4 | What you'll need when using this library : 5 | 6 | |Android | ver | 7 | |:-------------|:------:| 8 | | API| >=16| 9 | 10 | 11 | ## Quick start 12 | 13 | In order to get a quick demo running you could perform the following steps : 14 | 15 | * Add this to the repositories block : 16 | 17 | ``` groovy 18 | repositories { 19 | maven{ 20 | url "http://maven.appfoundry.be" 21 | } 22 | } 23 | ``` 24 | * Go to your project's `build.gradle` file, and change the dependencies block to match the following line of code there : 25 | 26 | ``` groovy 27 | compile 'be.appfoundry:nfc-lib:1.1' 28 | ``` 29 | 30 | Now go to the created activity, and either 31 | 32 | * Implement [FGD] yourself 33 | 34 | ``` java 35 | public class MyActivity{ 36 | private PendingIntent pendingIntent; 37 | private IntentFilter[] mIntentFilters; 38 | private String[][] mTechLists; 39 | private NfcAdapter mNfcAdapter; 40 | 41 | protected void onCreate(Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | setContentView(R.layout.activity_main); 44 | mNfcAdapter = NfcAdapter.getDefaultAdapter(this); 45 | pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); 46 | mIntentFilters = new IntentFilter[]{new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED)}; 47 | mTechLists = new String[][]{new String[]{Ndef.class.getName()}, 48 | new String[]{NdefFormatable.class.getName()}}; 49 | } 50 | public void onResume(){ 51 | super.onResume(); 52 | if (mNfcAdapter != null) { 53 | mNfcAdapter.enableForegroundDispatch(this, pendingIntent, mIntentFilters, mTechLists); 54 | } 55 | } 56 | public void onPause(){ 57 | super.onPause(); 58 | if (mNfcAdapter != null) 59 | { 60 | mNfcAdapter.disableForegroundDispatch(this); 61 | } 62 | } 63 | } 64 | 65 | ``` 66 | * Or extend from NfcActivity: 67 | 68 | ``` java 69 | public class MyActivity extends NfcActivity{ 70 | protected void onCreate(Bundle savedInstanceState){ 71 | super.onCreate(savedInstanceState); 72 | setContentView(R.layout.activity_main); 73 | } 74 | } 75 | ``` 76 | 77 | 78 | * **In both cases, add the following to your AndroidManifest.xml file :** 79 | ``` xml 80 | 81 | ``` 82 | 83 | ## Start Reading 84 | 85 | * Paste this in the activity if you're **extending our class** : 86 | 87 | 88 | ``` java 89 | @Override 90 | protected void onNewIntent(Intent intent) { 91 | super.onNewIntent(intent); 92 | for (String message : getNfcMessages()){ 93 | Toast.makeText(this,message,Toast.LENGTH_SHORT).show(); 94 | } 95 | } 96 | ``` 97 | 98 | * Otherwise : 99 | 100 | ``` java 101 | @Override 102 | protected void onNewIntent(Intent intent) { 103 | super.onNewIntent(intent); 104 | SparseArray res = new NfcReadUtilityImpl().readFromTagWithSparseArray(intent); 105 | for (int i =0; i < res.size() ; i++ ) { 106 | Toast.makeText(this, res.valueAt(i), Toast.LENGTH_SHORT).show(); 107 | } 108 | } 109 | ``` 110 | * If you like the Map implementation more you might as well use : 111 | 112 | ``` java 113 | @Override 114 | protected void onNewIntent(Intent intent) { 115 | super.onNewIntent(intent); 116 | for (String message : new NfcReadUtilityImpl().readFromTagWithMap(intent).values()) { 117 | Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); 118 | } 119 | } 120 | ``` 121 | 122 | * Now you're able to read the NFC Tags as long as the library supports the data in it when held to your phone! 123 | 124 | ## Write to a tag 125 | * Let your activity implement `AsyncUiCallback`: 126 | 127 | 128 | ``` java 129 | @Override 130 | public void callbackWithReturnValue(Boolean result) { 131 | String message = result ? "Success" : "Failed!"; 132 | Toast.makeText(this,message,Toast.LENGTH_SHORT).show(); 133 | } 134 | 135 | @Override 136 | public void onProgressUpdate(Boolean... booleans) { 137 | Toast.makeText(this, booleans[0] ? "We started writing" : "We could not write!",Toast.LENGTH_SHORT).show(); 138 | } 139 | 140 | @Override 141 | public void onError(Exception e) { 142 | Toast.makeText(this,e.getMessage(),Toast.LENGTH_SHORT).show(); 143 | } 144 | ``` 145 | 146 | * Create a field with an `AsyncOperationCallback` in the following way : 147 | 148 | ``` java 149 | AsyncOperationCallback mAsyncOperationCallback = new AsyncOperationCallback() { 150 | 151 | @Override 152 | public boolean performWrite(NfcWriteUtility writeUtility) throws ReadOnlyTagException, InsufficientCapacityException, TagNotPresentException, FormatException { 153 | return writeUtility.writeEmailToTagFromIntent("some@email.tld","Subject","Message",getIntent()); 154 | } 155 | }; 156 | ``` 157 | 158 | * Override the `onNewIntent(Intent)` method in the following way : 159 | 160 | ``` java 161 | @Override 162 | protected void onNewIntent(Intent intent) { 163 | super.onNewIntent(intent); 164 | new WriteEmailNfcAsync(this,mAsyncOperationCallback).executeWriteOperation(); 165 | } 166 | ``` 167 | * If you hold a tag against the phone and it is NFC Enabled, your implementation of the methods will be executed. 168 | 169 | ## Android Beam 170 | * When extending our class, all you have to do in order to enable Android Beam is call the `enableBeam()` method. 171 | * This enables Android Beam 172 | * Provides a default implementation with a standard text 173 | 174 | * If you did not opt for extending, take a look at the [official docs], or the source code. 175 | 176 | [NFC Forum]:http://members.nfc-forum.org/specs/ 177 | [FGD]:http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html#foreground-dispatch 178 | [official docs]:http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#p2p 179 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * build.gradle 3 | * NfcLibrary project. 4 | * 5 | * Created by : Daneo van Overloop - 17/6/2014. 6 | * 7 | * The MIT License (MIT) 8 | * 9 | * Copyright (c) 2014 AppFoundry. All rights reserved. 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | */ 21 | 22 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 23 | 24 | buildscript { 25 | repositories { 26 | jcenter() 27 | maven{ 28 | url "${repositoryUrl}" 29 | } 30 | maven { 31 | url 'https://maven.google.com/' 32 | name 'Google' 33 | } 34 | google() 35 | } 36 | dependencies { 37 | classpath 'com.android.tools.build:gradle:3.5.2' 38 | } 39 | } 40 | 41 | allprojects { 42 | repositories { 43 | jcenter() 44 | maven { 45 | url 'https://maven.google.com/' 46 | name 'Google' 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # gradle.properties 3 | # NfcLibrary project. 4 | # 5 | # Created by : Daneo van Overloop - 17/6/2014. 6 | # 7 | # The MIT License (MIT) 8 | # 9 | # Copyright (c) 2014 AppFoundry. All rights reserved. 10 | # 11 | # Permission is hereby granted, free of charge, to any person obtaining a copy 12 | # of this software and associated documentation files (the "Software"), to deal 13 | # in the Software without restriction, including without limitation the rights 14 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | # copies of the Software, and to permit persons to whom the Software is 16 | # furnished to do so, subject to the following conditions: 17 | # 18 | # The above copyright notice and this permission notice shall be included in all 19 | # copies or substantial portions of the Software. 20 | # 21 | 22 | # Project-wide Gradle settings. 23 | 24 | # IDE (e.g. Android Studio) users: 25 | # Settings specified in this file will override any Gradle settings 26 | # configured through the IDE. 27 | 28 | # For more details on how to configure your build environment visit 29 | # http://www.gradle.org/docs/current/userguide/build_environment.html 30 | 31 | # Specifies the JVM arguments used for the daemon process. 32 | # The setting is particularly useful for tweaking memory settings. 33 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 34 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 35 | 36 | # When configured, Gradle will run in incubating parallel mode. 37 | # This option should only be used with decoupled projects. More details, visit 38 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 39 | # org.gradle.parallel=true 40 | repositoryUrl=http://www.appfoundry.be/maven 41 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appfoundry/android-nfc-lib/47aa8f782f7ddb61409d88b2e74958cdb6f51814/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Nov 07 09:10:58 CET 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /implementationApp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | .DS_STORE 3 | *.iml -------------------------------------------------------------------------------- /implementationApp/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * build.gradle 3 | * NfcLibrary project. 4 | * 5 | * Created by : Daneo van Overloop - 17/6/2014. 6 | * 7 | * The MIT License (MIT) 8 | * 9 | * Copyright (c) 2014 AppFoundry. All rights reserved. 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | */ 21 | 22 | apply plugin: 'com.android.application' 23 | apply plugin: 'spoon' 24 | 25 | android { 26 | packagingOptions { 27 | exclude 'META-INF/LICENSE.txt' 28 | exclude 'META-INF/NOTICE.txt' 29 | exclude 'NOTICE' 30 | exclude 'LICENSE.txt' 31 | } 32 | compileSdkVersion 29 33 | buildToolsVersion '29.0.2' 34 | 35 | defaultConfig { 36 | applicationId "be.appfoundry.nfc.implementation" 37 | testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" 38 | minSdkVersion 18 39 | targetSdkVersion 29 40 | versionCode 12 41 | versionName "1.2" 42 | } 43 | buildTypes { 44 | release { 45 | minifyEnabled false 46 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 47 | } 48 | debug { 49 | debuggable true 50 | jniDebuggable true 51 | minifyEnabled false 52 | } 53 | } 54 | configurations { 55 | provided 56 | } 57 | } 58 | 59 | buildscript { 60 | repositories { 61 | //maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } 62 | jcenter() 63 | } 64 | dependencies { 65 | classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2' 66 | } 67 | } 68 | 69 | repositories{ 70 | maven{ 71 | url "http://maven.appfoundry.be" 72 | } 73 | 74 | maven { 75 | url "https://oss.sonatype.org/content/repositories/snapshots" 76 | } 77 | jcenter() 78 | } 79 | spoon { 80 | adbTimeout = 15 81 | failIfNoDeviceConnected = false 82 | } 83 | 84 | dependencies { 85 | implementation fileTree(dir: 'libs', include: ['*.jar']) 86 | implementation project(':nfclib') 87 | //compile 'be.appfoundry:nfc-lib:1.2' 88 | 89 | androidTestImplementation 'com.jakewharton.espresso:espresso:1.1-r3' 90 | androidTestImplementation 'com.squareup.spoon:spoon-client:1.7.1' 91 | 92 | implementation 'com.google.android.material:material:1.0.0' 93 | implementation 'javax.annotation:jsr250-api:1.0' 94 | } -------------------------------------------------------------------------------- /implementationApp/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # gradle.properties 3 | # NfcLibrary project. 4 | # 5 | # Created by : Daneo van Overloop - 17/6/2014. 6 | # 7 | # The MIT License (MIT) 8 | # 9 | # Copyright (c) 2014 AppFoundry. All rights reserved. 10 | # 11 | # Permission is hereby granted, free of charge, to any person obtaining a copy 12 | # of this software and associated documentation files (the "Software"), to deal 13 | # in the Software without restriction, including without limitation the rights 14 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | # copies of the Software, and to permit persons to whom the Software is 16 | # furnished to do so, subject to the following conditions: 17 | # 18 | # The above copyright notice and this permission notice shall be included in all 19 | # copies or substantial portions of the Software. 20 | # 21 | 22 | -------------------------------------------------------------------------------- /implementationApp/proguard-rules.txt: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /opt/android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the ProGuard 5 | # include property in project.properties. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} -------------------------------------------------------------------------------- /implementationApp/src/androidTest/java/be/appfoundry/nfc/implementation/TestEmptyFieldsNfcActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TestEmptyFieldsNfcActivity.java 3 | * NfcLibrary project. 4 | * 5 | * Created by : Daneo van Overloop - 17/6/2014. 6 | * 7 | * The MIT License (MIT) 8 | * 9 | * Copyright (c) 2014 AppFoundry. All rights reserved. 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | */ 21 | 22 | package be.appfoundry.nfc.implementation; 23 | 24 | import android.test.ActivityInstrumentationTestCase2; 25 | import android.widget.EditText; 26 | 27 | import com.google.android.apps.common.testing.ui.espresso.ViewInteraction; 28 | import com.squareup.spoon.Spoon; 29 | 30 | import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView; 31 | import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click; 32 | import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.typeText; 33 | import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.doesNotExist; 34 | import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId; 35 | import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText; 36 | 37 | /** 38 | * NfcLibrary by daneo 39 | * Created on 30/04/14. 40 | */ 41 | public class TestEmptyFieldsNfcActivity extends ActivityInstrumentationTestCase2 { 42 | 43 | public TestEmptyFieldsNfcActivity() { 44 | super(MainActivity.class); 45 | } 46 | 47 | @Override 48 | public void setUp() throws Exception { 49 | super.setUp(); 50 | getActivity(); 51 | } 52 | 53 | public void testEmptyUriFieldNotDisplayingAfterClick() { 54 | makeEmpty(R.id.input_text_uri_target); 55 | emptyFieldNotDisplayingToast(R.id.btn_write_uri_nfc); 56 | } 57 | 58 | public void testEmptyGeoFieldNotDisplayingAfterClick() { 59 | makeEmpty(R.id.input_text_geo_lat_target); 60 | emptyFieldNotDisplayingToast(R.id.btn_write_geolocation_nfc); 61 | } 62 | 63 | public void testEmptyEmailFieldNotDisplayingAfterClick() { 64 | makeEmpty(R.id.input_text_email_target); 65 | emptyFieldNotDisplayingToast(R.id.btn_write_email_nfc); 66 | } 67 | 68 | public void testEmptySmsFieldNotDisplayingAfterClick() { 69 | makeEmpty(R.id.input_text_sms_target); 70 | emptyFieldNotDisplayingToast(R.id.btn_write_sms_nfc); 71 | } 72 | 73 | 74 | public void testEmptyBluetoothFieldNotDisplayingAfterClick() { 75 | final EditText editText = (EditText) getActivity().findViewById(R.id.input_text_bluetooth_address); 76 | editText.post(new Runnable() { 77 | @Override 78 | public void run() { 79 | editText.setText(null); 80 | } 81 | }); 82 | emptyFieldNotDisplayingToast(R.id.btn_write_bluetooth_nfc); 83 | } 84 | 85 | public void testEmptyTelFieldNotDisplayingAfterClick() { 86 | makeEmpty(R.id.input_text_tel_target); 87 | emptyFieldNotDisplayingToast(R.id.btn_write_tel_nfc); 88 | } 89 | 90 | 91 | public void emptyFieldNotDisplayingToast(int id) { 92 | onView(withId(id)).perform(click()); 93 | 94 | // Not able to check for Toast being displayed due to their async nature 95 | 96 | // onView(withText(R.string.no_input)).check(matches(isDisplayed())); 97 | 98 | checkProgressDialogNotShowing(); 99 | makeScreenshot("end"); 100 | } 101 | 102 | private ViewInteraction makeEmpty(int id) { 103 | makeScreenshot("init"); 104 | return onView(withId(id)).perform(typeText("")); 105 | } 106 | 107 | private void makeScreenshot(String tag) { 108 | Spoon.screenshot(getActivity(), tag); 109 | } 110 | 111 | protected void checkProgressDialogNotShowing() { 112 | getInstrumentation().waitForIdleSync(); 113 | onView(withText(getActivity().getString(R.string.progressdialog_waiting_for_tag))).check(doesNotExist()); 114 | 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /implementationApp/src/androidTest/java/be/appfoundry/nfc/implementation/TestFilledFieldsNfcActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TestFilledFieldsNfcActivity.java 3 | * NfcLibrary project. 4 | * 5 | * Created by : Daneo van Overloop - 17/6/2014. 6 | * 7 | * The MIT License (MIT) 8 | * 9 | * Copyright (c) 2014 AppFoundry. All rights reserved. 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in all 19 | * copies or substantial portions of the Software. 20 | */ 21 | 22 | package be.appfoundry.nfc.implementation; 23 | 24 | import android.test.ActivityInstrumentationTestCase2; 25 | import android.widget.EditText; 26 | 27 | import com.squareup.spoon.Spoon; 28 | 29 | 30 | import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView; 31 | import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click; 32 | import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.pressImeActionButton; 33 | import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.typeText; 34 | import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches; 35 | import static com.google.android.apps.common.testing.ui.espresso.matcher.RootMatchers.withDecorView; 36 | import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.isDisplayed; 37 | import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId; 38 | import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText; 39 | import static org.hamcrest.CoreMatchers.not; 40 | import static org.hamcrest.core.Is.is; 41 | 42 | /** 43 | * NfcLibrary by daneo 44 | * Created on 14/04/14. 45 | */ 46 | public class TestFilledFieldsNfcActivity extends ActivityInstrumentationTestCase2 { 47 | 48 | private static final String TAG = TestFilledFieldsNfcActivity.class.getSimpleName(); 49 | 50 | public TestFilledFieldsNfcActivity() { 51 | super(MainActivity.class); 52 | } 53 | 54 | @Override 55 | public void setUp() throws Exception { 56 | super.setUp(); 57 | getActivity(); 58 | } 59 | 60 | public void testFilledUriFieldButtonClickShowsProgressDialog() throws Exception { 61 | //checkAndDismissBluetoothDialog(); 62 | makeScreenshot("init"); 63 | onView(withId(R.id.input_text_uri_target)).perform(typeText("google.be")); 64 | onView(withId(R.id.btn_write_uri_nfc)).perform(click()); 65 | makeScreenshot("Showing_progressdialog"); 66 | checkProgressDialogShowing(); 67 | makeScreenshot("end"); 68 | } 69 | 70 | public void testFilledGeoFieldButtonClickShowsProgressDialog() throws Exception { 71 | //checkAndDismissBluetoothDialog(); 72 | makeScreenshot("init"); 73 | onView(withId(R.id.input_text_geo_lat_target)).perform(typeText("50.2345323")); 74 | onView(withId(R.id.input_text_geo_long_target)).perform(typeText("50.2345323")); 75 | onView(withId(R.id.btn_write_geolocation_nfc)).perform(click()); 76 | makeScreenshot("Showing_progressdialog"); 77 | checkProgressDialogShowing(); 78 | makeScreenshot("end"); 79 | } 80 | 81 | public void testFilledEmailFieldButtonClickShowsProgressDialog() throws Exception { 82 | //checkAndDismissBluetoothDialog(); 83 | makeScreenshot("init"); 84 | onView(withId(R.id.input_text_email_target)).perform(typeText("daneo@derp.com")); 85 | onView(withId(R.id.btn_write_email_nfc)).perform(click()); 86 | makeScreenshot("Showing_progressdialog"); 87 | checkProgressDialogShowing(); 88 | makeScreenshot("end"); 89 | } 90 | 91 | public void testFilledSmsFieldButtonClickShowsProgressDialog() throws Exception { 92 | //checkAndDismissBluetoothDialog(); 93 | makeScreenshot("init"); 94 | onView(withId(R.id.input_text_sms_target)).perform(typeText("0123456789")); 95 | onView(withId(R.id.btn_write_sms_nfc)).perform(click()); 96 | makeScreenshot("Showing_progressdialog"); 97 | checkProgressDialogShowing(); 98 | makeScreenshot("end"); 99 | } 100 | 101 | //2131296269 102 | public void testFilledBluetoothMacAddressFieldButtonClickShowsProgressDialog() throws Exception { 103 | //checkAndDismissBluetoothDialog(); 104 | makeScreenshot("init"); 105 | final EditText text = (EditText) getActivity().findViewById(R.id.input_text_bluetooth_address); 106 | 107 | final String macAddress = "00:11:22:33:44"; 108 | 109 | text.post(new Runnable() { 110 | @Override 111 | public void run() { 112 | text.setText(macAddress); 113 | } 114 | }); 115 | 116 | makeScreenshot("Item_filled"); 117 | onView(withId(R.id.input_text_bluetooth_address)).perform(click()); 118 | 119 | 120 | // onView(withId(R.id.spinner_bluetooth_addresses)).perform(click(pressImeActionButton())); 121 | onView(withId(R.id.btn_write_bluetooth_nfc)).perform(click()); 122 | makeScreenshot("Showing_progressdialog"); 123 | checkProgressDialogShowing(); 124 | makeScreenshot("end"); 125 | } 126 | 127 | public void testFilledTelephoneFieldButtonClickShowsProgressDialog() throws Exception { 128 | //checkAndDismissBluetoothDialog(); 129 | makeScreenshot("init"); 130 | onView(withId(R.id.input_text_tel_target)).perform(typeText("0123456789")); 131 | onView(withId(R.id.btn_write_tel_nfc)).perform(click()); 132 | checkProgressDialogShowing(); 133 | } 134 | 135 | private void checkAndDismissBluetoothDialog() { 136 | onView(withText("Bluetooth")) 137 | .inRoot(withDecorView(not(is(getActivity().getWindow().getDecorView())))) 138 | .perform(click(pressImeActionButton())); 139 | } 140 | 141 | protected void checkProgressDialogShowing() { 142 | onView(withText(getActivity().getString(R.string.progressdialog_waiting_for_tag))).check(matches(isDisplayed())); 143 | } 144 | 145 | private void makeScreenshot(final String tag) { 146 | Spoon.screenshot(getActivity(),tag); 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /implementationApp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 33 | 34 | 35 | 36 | 37 | 43 | 44 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /implementationApp/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appfoundry/android-nfc-lib/47aa8f782f7ddb61409d88b2e74958cdb6f51814/implementationApp/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /implementationApp/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appfoundry/android-nfc-lib/47aa8f782f7ddb61409d88b2e74958cdb6f51814/implementationApp/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /implementationApp/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appfoundry/android-nfc-lib/47aa8f782f7ddb61409d88b2e74958cdb6f51814/implementationApp/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /implementationApp/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appfoundry/android-nfc-lib/47aa8f782f7ddb61409d88b2e74958cdb6f51814/implementationApp/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /implementationApp/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 21 | 22 | 27 | 28 | 31 | 32 | 40 | 41 | 46 | 47 |