rhodes 3.0.1.beta.5 → 3.0.1.beta.6
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/nfc.txt +2 -0
- data/lib/extensions/nfc/ext/nfc/platform/android/AndroidManifest.xml +0 -2
- data/lib/extensions/nfc/ext/nfc/platform/android/jni/src/nfc.cpp +69 -0
- data/lib/extensions/nfc/ext/nfc/platform/android/src/com/rhomobile/nfc/Nfc.java +17 -7
- data/lib/extensions/nfc/ext/nfc/platform/android/src/com/rhomobile/nfc/NfcActivity.java +6 -16
- data/platform/android/build/android.rake +5 -15
- data/platform/android/build/androidcommon.rb +22 -1
- data/platform/shared/net/HttpServer.cpp +5 -1
- data/rhodes.gemspec +1 -1
- metadata +4 -4
data/doc/nfc.txt
CHANGED
@@ -5,6 +5,8 @@ NFC (Near Field Communication). NFC API provide access to NFC functionality. You
|
|
5
5
|
NFC API implemented in native extension. You should add "nfc" to extension list in your nuild.yml before start using NFC in your application. And also do not forget enable NFC for start process NFC events - Rho::NFCManager.enable.
|
6
6
|
NFC Ruby API based on Android NFC API. We recommended investigate Android doc for understand NFC Techs etc. See [Android NFC](http://developer.android.com/guide/topics/nfc/index.html)
|
7
7
|
|
8
|
+
NOTE: Before start using of NFC functionality, do not forget check current platform for supporting of NFC ! Use this : Rho::NFCManager.is_supported
|
9
|
+
|
8
10
|
## NFC events
|
9
11
|
There are two different NFC callback can be received (you should setup callbacks before!) :
|
10
12
|
* NFC callback : it executed when Android ACTION_NDEF_DISCOVERED or ACTION_TAG_DISCOVERED events processed.
|
@@ -29,6 +29,24 @@ void loge(const char* text) {
|
|
29
29
|
}
|
30
30
|
|
31
31
|
|
32
|
+
static bool checkSDK() {
|
33
|
+
bool sdk_ok = false;
|
34
|
+
JNIEnv *env = jnienv();
|
35
|
+
jclass cls = rho_find_class(env, "com/rhomobile/nfc/NfcActivity");
|
36
|
+
if (!cls) {
|
37
|
+
loge("NfcActivity class not found !");
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
jmethodID mid = env->GetStaticMethodID(cls, "getSDKVersion", "()I");
|
41
|
+
if (!mid) {
|
42
|
+
loge("NfcActivity.getSDKVersion() NOT FOUND !");
|
43
|
+
return false;
|
44
|
+
}
|
45
|
+
int version = env->CallStaticIntMethod(cls, mid);
|
46
|
+
env->DeleteLocalRef(cls);
|
47
|
+
return (version >= 9);
|
48
|
+
}
|
49
|
+
|
32
50
|
class CNfcJavaClass {
|
33
51
|
public:
|
34
52
|
CNfcJavaClass() {
|
@@ -608,6 +626,9 @@ private:
|
|
608
626
|
|
609
627
|
|
610
628
|
extern "C" void rho_nfc_set_callback(const char* callback_url) {
|
629
|
+
if (!checkSDK()) {
|
630
|
+
return;
|
631
|
+
}
|
611
632
|
JNIEnv *env = jnienv();
|
612
633
|
CNfcJavaClass cls;
|
613
634
|
if (!cls.get()) return;
|
@@ -619,6 +640,9 @@ extern "C" void rho_nfc_set_callback(const char* callback_url) {
|
|
619
640
|
}
|
620
641
|
|
621
642
|
extern "C" void rho_nfc_enable(int enable) {
|
643
|
+
if (!checkSDK()) {
|
644
|
+
return;
|
645
|
+
}
|
622
646
|
JNIEnv *env = jnienv();
|
623
647
|
CNfcJavaClass cls;
|
624
648
|
if (!cls.get()) return;
|
@@ -628,14 +652,23 @@ extern "C" void rho_nfc_enable(int enable) {
|
|
628
652
|
}
|
629
653
|
|
630
654
|
extern "C" int rho_nfc_is_enabled(void) {
|
655
|
+
if (!checkSDK()) {
|
656
|
+
return 0;
|
657
|
+
}
|
631
658
|
return JavaHelper_exec_int_void("isEnabled");
|
632
659
|
}
|
633
660
|
|
634
661
|
extern "C" int rho_nfc_is_supported(void) {
|
662
|
+
if (!checkSDK()) {
|
663
|
+
return 0;
|
664
|
+
}
|
635
665
|
return JavaHelper_exec_int_void("isSupported");
|
636
666
|
}
|
637
667
|
|
638
668
|
extern "C" void rho_nfc_set_tech_callback(const char* callback_url) {
|
669
|
+
if (!checkSDK()) {
|
670
|
+
return;
|
671
|
+
}
|
639
672
|
JNIEnv *env = jnienv();
|
640
673
|
CNfcJavaClass cls;
|
641
674
|
if (!cls.get()) return;
|
@@ -647,6 +680,9 @@ extern "C" void rho_nfc_set_tech_callback(const char* callback_url) {
|
|
647
680
|
}
|
648
681
|
|
649
682
|
extern "C" void rho_nfc_perform_open_application_event() {
|
683
|
+
if (!checkSDK()) {
|
684
|
+
return;
|
685
|
+
}
|
650
686
|
JNIEnv *env = jnienv();
|
651
687
|
CNfcJavaClass cls;
|
652
688
|
if (!cls.get()) return;
|
@@ -664,6 +700,9 @@ extern "C" void rho_nfc_set_listen_tech_list(VALUE tech_list) {
|
|
664
700
|
extern "C" VALUE rho_nfc_get_tech_list() {
|
665
701
|
|
666
702
|
logi("rho_nfc_get_tech_list START");
|
703
|
+
if (!checkSDK()) {
|
704
|
+
return rho_ruby_get_NIL();
|
705
|
+
}
|
667
706
|
JNIEnv *env = jnienv();
|
668
707
|
CNfcJavaClass cls;
|
669
708
|
if (!cls.get()) return rho_ruby_get_NIL();
|
@@ -928,6 +967,9 @@ extern "C" VALUE rho_nfc_tech_NfcA_transceive(VALUE data) {
|
|
928
967
|
|
929
968
|
// return HASH
|
930
969
|
extern "C" VALUE rho_nfc_convert_byte_array_to_NdeRecord_hash(VALUE array) {
|
970
|
+
if (!checkSDK()) {
|
971
|
+
return rho_ruby_get_NIL();
|
972
|
+
}
|
931
973
|
initJavaIds();
|
932
974
|
|
933
975
|
JNIEnv *env = jnienv();
|
@@ -954,6 +996,9 @@ extern "C" VALUE rho_nfc_convert_byte_array_to_NdeRecord_hash(VALUE array) {
|
|
954
996
|
|
955
997
|
// return byte array
|
956
998
|
extern "C" VALUE rho_nfc_convert_NdeRecord_hash_to_byte_array(VALUE hash) {
|
999
|
+
if (!checkSDK()) {
|
1000
|
+
return rho_ruby_get_NIL();
|
1001
|
+
}
|
957
1002
|
initJavaIds();
|
958
1003
|
|
959
1004
|
VALUE ruby_id = rho_ruby_hash_aref(hash, "id");
|
@@ -981,6 +1026,9 @@ extern "C" VALUE rho_nfc_convert_NdeRecord_hash_to_byte_array(VALUE hash) {
|
|
981
1026
|
|
982
1027
|
// return array of byte array
|
983
1028
|
extern "C" VALUE rho_nfc_convert_NdeMessage_byte_array_to_NdeRecords_array(VALUE array) {
|
1029
|
+
if (!checkSDK()) {
|
1030
|
+
return rho_ruby_get_NIL();
|
1031
|
+
}
|
984
1032
|
|
985
1033
|
initJavaIds();
|
986
1034
|
|
@@ -1011,6 +1059,9 @@ extern "C" VALUE rho_nfc_convert_NdeMessage_byte_array_to_NdeRecords_array(VALUE
|
|
1011
1059
|
|
1012
1060
|
// return byte array
|
1013
1061
|
extern "C" VALUE rho_nfc_convert_NdeRecords_array_to_NdeMessage_byte_array(VALUE array) {
|
1062
|
+
if (!checkSDK()) {
|
1063
|
+
return rho_ruby_get_NIL();
|
1064
|
+
}
|
1014
1065
|
initJavaIds();
|
1015
1066
|
|
1016
1067
|
JNIEnv *env = jnienv();
|
@@ -1044,6 +1095,9 @@ extern "C" VALUE rho_nfc_convert_NdeRecords_array_to_NdeMessage_byte_array(VALUE
|
|
1044
1095
|
// String make_string_from_payload(byte[] payload, int tnf, byte[] type)
|
1045
1096
|
// return string
|
1046
1097
|
extern "C" VALUE rho_nfc_make_string_from_payload(VALUE payload, int tnf, VALUE type) {
|
1098
|
+
if (!checkSDK()) {
|
1099
|
+
return rho_ruby_get_NIL();
|
1100
|
+
}
|
1047
1101
|
|
1048
1102
|
CRubyByteArray c_payload(payload);
|
1049
1103
|
CRubyByteArray c_type(type);
|
@@ -1063,6 +1117,9 @@ extern "C" VALUE rho_nfc_make_string_from_payload(VALUE payload, int tnf, VALUE
|
|
1063
1117
|
|
1064
1118
|
// return byte[]
|
1065
1119
|
extern "C" VALUE rho_nfc_make_payload_with_absolute_uri(const char* str) {
|
1120
|
+
if (!checkSDK()) {
|
1121
|
+
return rho_ruby_get_NIL();
|
1122
|
+
}
|
1066
1123
|
|
1067
1124
|
CRubyString c_s(str);
|
1068
1125
|
|
@@ -1082,6 +1139,9 @@ extern "C" VALUE rho_nfc_make_payload_with_absolute_uri(const char* str) {
|
|
1082
1139
|
|
1083
1140
|
// return byte[]
|
1084
1141
|
extern "C" VALUE rho_nfc_make_payload_with_well_known_text(const char* language, const char* str) {
|
1142
|
+
if (!checkSDK()) {
|
1143
|
+
return rho_ruby_get_NIL();
|
1144
|
+
}
|
1085
1145
|
CRubyString c_lang(language);
|
1086
1146
|
CRubyString c_s(str);
|
1087
1147
|
|
@@ -1101,6 +1161,9 @@ extern "C" VALUE rho_nfc_make_payload_with_well_known_text(const char* language,
|
|
1101
1161
|
|
1102
1162
|
// return byte[]
|
1103
1163
|
extern "C" VALUE rho_nfc_make_payload_with_well_known_uri(int prefix, const char* str) {
|
1164
|
+
if (!checkSDK()) {
|
1165
|
+
return rho_ruby_get_NIL();
|
1166
|
+
}
|
1104
1167
|
CRubyString c_s(str);
|
1105
1168
|
|
1106
1169
|
JNIEnv *env = jnienv();
|
@@ -1117,10 +1180,16 @@ extern "C" VALUE rho_nfc_make_payload_with_well_known_uri(int prefix, const char
|
|
1117
1180
|
}
|
1118
1181
|
|
1119
1182
|
extern "C" void rho_nfc_p2p_enable_foreground_nde_push(VALUE nde_message_byte_array) {
|
1183
|
+
if (!checkSDK()) {
|
1184
|
+
return;
|
1185
|
+
}
|
1120
1186
|
JavaHelper_exec_void_bytearray(nde_message_byte_array, "p2p_enable_foreground_nde_push");
|
1121
1187
|
}
|
1122
1188
|
|
1123
1189
|
extern "C" void rho_nfc_p2p_disable_foreground_nde_push() {
|
1190
|
+
if (!checkSDK()) {
|
1191
|
+
return;
|
1192
|
+
}
|
1124
1193
|
JNIEnv *env = jnienv();
|
1125
1194
|
CNfcJavaClass cls;
|
1126
1195
|
if (!cls.get()) return;
|
@@ -123,21 +123,31 @@ public class Nfc implements RhodesActivityListener {
|
|
123
123
|
return ourInstance;
|
124
124
|
}
|
125
125
|
|
126
|
-
|
127
|
-
|
126
|
+
public static NfcAdapter getDefaultAdapter(Context ctx) {
|
127
|
+
Context context = ctx;
|
128
|
+
if (ctx == null) {
|
129
|
+
context = RhodesActivity.getContext();
|
130
|
+
}
|
128
131
|
NfcAdapter da = null;
|
129
132
|
try {
|
130
|
-
int sdkVersion =
|
133
|
+
int sdkVersion = Build.VERSION.SDK_INT;
|
131
134
|
if (sdkVersion >= Build.VERSION_CODES.GINGERBREAD_MR1) {
|
132
|
-
da = NfcAdapter.getDefaultAdapter(
|
133
|
-
}
|
135
|
+
da = NfcAdapter.getDefaultAdapter(RhodesActivity.getContext());
|
136
|
+
}
|
134
137
|
else if (sdkVersion >= Build.VERSION_CODES.GINGERBREAD) {
|
135
138
|
da = NfcAdapter.getDefaultAdapter();
|
136
139
|
}
|
137
140
|
}
|
138
141
|
catch (Exception e) {
|
139
142
|
// nothing
|
143
|
+
Utils.platformLog(TAG, "Exception during get NFCAdapter");
|
144
|
+
e.printStackTrace();
|
140
145
|
}
|
146
|
+
return da;
|
147
|
+
}
|
148
|
+
|
149
|
+
public static int isSupported() {
|
150
|
+
NfcAdapter da = getDefaultAdapter(null);
|
141
151
|
if (da == null) {
|
142
152
|
return 0;
|
143
153
|
}
|
@@ -194,7 +204,7 @@ public class Nfc implements RhodesActivityListener {
|
|
194
204
|
|
195
205
|
public void onPause(RhodesActivity activity) {
|
196
206
|
log(" $$$$$$$$$ onPause() ");
|
197
|
-
NfcAdapter nfcAdapter =
|
207
|
+
NfcAdapter nfcAdapter = getDefaultAdapter(RhodesActivity.getContext());
|
198
208
|
if (nfcAdapter != null) {
|
199
209
|
nfcAdapter.disableForegroundDispatch(activity);
|
200
210
|
nfcAdapter.disableForegroundNdefPush(activity);
|
@@ -203,7 +213,7 @@ public class Nfc implements RhodesActivityListener {
|
|
203
213
|
|
204
214
|
public void onResume(RhodesActivity activity) {
|
205
215
|
log(" $$$$$$$$$ onResume() ");
|
206
|
-
NfcAdapter nfcAdapter =
|
216
|
+
NfcAdapter nfcAdapter = getDefaultAdapter(RhodesActivity.getContext());
|
207
217
|
if ((nfcAdapter != null) && (ourIsEnable)) {
|
208
218
|
IntentFilter[] filters = new IntentFilter[1];
|
209
219
|
filters[0] = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
|
@@ -1,26 +1,10 @@
|
|
1
1
|
package com.rhomobile.nfc;
|
2
2
|
|
3
|
-
import java.util.Iterator;
|
4
|
-
|
5
3
|
import android.app.Activity;
|
6
|
-
import android.content.BroadcastReceiver;
|
7
|
-
import android.content.Context;
|
8
4
|
import android.content.Intent;
|
9
|
-
import android.net.Uri;
|
10
|
-
import android.nfc.NdefMessage;
|
11
|
-
import android.nfc.NdefRecord;
|
12
|
-
import android.nfc.NfcAdapter;
|
13
|
-
import android.nfc.Tag;
|
14
5
|
import android.os.Build;
|
15
6
|
import android.os.Bundle;
|
16
|
-
import android.os.Parcelable;
|
17
|
-
import android.util.Log;
|
18
|
-
|
19
|
-
import com.rhomobile.rhodes.PushService;
|
20
7
|
import com.rhomobile.rhodes.RhodesActivity;
|
21
|
-
import com.rhomobile.rhodes.RhodesActivityListener;
|
22
|
-
import com.rhomobile.rhodes.RhodesApplication;
|
23
|
-
import com.rhomobile.rhodes.RhodesService;
|
24
8
|
import com.rhomobile.rhodes.Utils;
|
25
9
|
|
26
10
|
public class NfcActivity extends Activity {
|
@@ -30,6 +14,10 @@ public class NfcActivity extends Activity {
|
|
30
14
|
|
31
15
|
private static Intent ourIntent = null;
|
32
16
|
|
17
|
+
private static int getSDKVersion() {
|
18
|
+
return Build.VERSION.SDK_INT;
|
19
|
+
}
|
20
|
+
|
33
21
|
@Override
|
34
22
|
protected void onCreate(Bundle savedInstanceState) {
|
35
23
|
Utils.platformLog(TAG, " $$$$$$$ NfcActivity onCreate !!! START ");
|
@@ -89,6 +77,7 @@ public class NfcActivity extends Activity {
|
|
89
77
|
}
|
90
78
|
|
91
79
|
private void processNewIntent(Intent intent) {
|
80
|
+
/*
|
92
81
|
super.onNewIntent(intent);
|
93
82
|
String action = intent.getAction();
|
94
83
|
|
@@ -108,6 +97,7 @@ public class NfcActivity extends Activity {
|
|
108
97
|
startActivity(run_intent);
|
109
98
|
|
110
99
|
}
|
100
|
+
*/
|
111
101
|
}
|
112
102
|
|
113
103
|
|
@@ -1468,20 +1468,15 @@ namespace "device" do
|
|
1468
1468
|
final_apkfile = $targetdir + "/" + $appname + "-debug.apk"
|
1469
1469
|
resourcepkg = $bindir + "/rhodes.ap_"
|
1470
1470
|
|
1471
|
-
|
1472
|
-
|
1473
|
-
unless $?.success?
|
1474
|
-
puts "Error building APK file"
|
1475
|
-
exit 1
|
1476
|
-
end
|
1477
|
-
|
1471
|
+
apk_build $androidsdkpath, simple_apkfile, resourcepkg, dexfile, true
|
1472
|
+
|
1478
1473
|
puts "Align Debug APK file"
|
1479
1474
|
args = []
|
1480
1475
|
args << "-f"
|
1481
1476
|
args << "-v"
|
1482
1477
|
args << "4"
|
1483
|
-
args <<
|
1484
|
-
args <<
|
1478
|
+
args << simple_apkfile
|
1479
|
+
args << final_apkfile
|
1485
1480
|
puts Jake.run($zipalign, args)
|
1486
1481
|
unless $?.success?
|
1487
1482
|
puts "Error running zipalign"
|
@@ -1515,12 +1510,7 @@ namespace "device" do
|
|
1515
1510
|
signed_apkfile = $targetdir + "/" + $appname + "_tmp_signed.apk"
|
1516
1511
|
resourcepkg = $bindir + "/rhodes.ap_"
|
1517
1512
|
|
1518
|
-
|
1519
|
-
Jake.run($apkbuilder, [simple_apkfile, "-u", "-z", resourcepkg, "-f", dexfile])
|
1520
|
-
unless $?.success?
|
1521
|
-
puts "Error building APK file"
|
1522
|
-
exit 1
|
1523
|
-
end
|
1513
|
+
apk_build $androidsdkpath, simple_apkfile, resourcepkg, dexfile, false
|
1524
1514
|
|
1525
1515
|
if not File.exists? $keystore
|
1526
1516
|
puts "Generating private keystore..."
|
@@ -207,7 +207,7 @@ def cc_run(command, args, chdir = nil)
|
|
207
207
|
cmdstr = argv.map! { |x| x.to_s }.map! { |x| x =~ / / ? '"' + x + '"' : x }.join(' ')
|
208
208
|
puts cmdstr
|
209
209
|
$stdout.flush
|
210
|
-
argv = cmdstr if RUBY_VERSION =~ /^1\.
|
210
|
+
argv = cmdstr if RUBY_VERSION =~ /^1\.[89]/
|
211
211
|
IO.popen(argv) do |f|
|
212
212
|
while data = f.gets
|
213
213
|
puts data
|
@@ -335,3 +335,24 @@ def cc_clean(name)
|
|
335
335
|
rm_rf x if File.exists? x
|
336
336
|
end
|
337
337
|
end
|
338
|
+
|
339
|
+
def apk_build(sdk, apk_name, res_name, dex_name, debug)
|
340
|
+
puts "Building APK file..."
|
341
|
+
prev_dir = Dir.pwd
|
342
|
+
Dir.chdir File.join(sdk, "tools")
|
343
|
+
#"-classpath", File.join("lib", "sdklib.jar"), "com.android.sdklib.build.ApkBuilderMain",
|
344
|
+
if debug
|
345
|
+
params = [apk_name, "-z", res_name, "-f", dex_name]
|
346
|
+
else
|
347
|
+
params = [apk_name, "-u", "-z", res_name, "-f", dex_name]
|
348
|
+
end
|
349
|
+
|
350
|
+
Jake.run("apkbuilder" + $bat_ext, params)
|
351
|
+
|
352
|
+
unless $?.success?
|
353
|
+
Dir.chdir prev_dir
|
354
|
+
puts "Error building APK file"
|
355
|
+
exit 1
|
356
|
+
end
|
357
|
+
Dir.chdir prev_dir
|
358
|
+
end
|
@@ -1051,7 +1051,11 @@ bool CHttpServer::decide(String const &method, String const &arg_uri, String con
|
|
1051
1051
|
|
1052
1052
|
#ifdef OS_ANDROID
|
1053
1053
|
//Work around malformed Android WebView URLs
|
1054
|
-
if ((uri
|
1054
|
+
if (!String_startsWith(uri, "/app") &&
|
1055
|
+
!String_startsWith(uri, "/public") &&
|
1056
|
+
!String_startsWith(uri, "/data"))
|
1057
|
+
{
|
1058
|
+
RAWTRACE1("Malformed URL: '%s', adding '/app' prefix.", uri.c_str());
|
1055
1059
|
uri = CFilePath::join("/app", uri);
|
1056
1060
|
}
|
1057
1061
|
#endif
|
data/rhodes.gemspec
CHANGED
@@ -3,7 +3,7 @@ require "lib/rhodes.rb"
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = %q{rhodes}
|
6
|
-
s.version = "3.0.1.beta.
|
6
|
+
s.version = "3.0.1.beta.6"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.authors = ["Rhomobile"]
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhodes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 62196423
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 0
|
9
9
|
- 1
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 3.0.1.beta.
|
11
|
+
- 6
|
12
|
+
version: 3.0.1.beta.6
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Rhomobile
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-05-
|
20
|
+
date: 2011-05-31 00:00:00 -07:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|