-
Notifications
You must be signed in to change notification settings - Fork 3
/
nfc.py
72 lines (60 loc) · 2.02 KB
/
nfc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
__all__ = ('CreateNfcBeamUrisCallback')
from jnius import PythonJavaClass, java_method, autoclass, cast
PythonActivity = autoclass('org.renpy.android.PythonActivity')
mContext = autoclass('android.content.Context')
NfcAdapter = autoclass('android.nfc.NfcAdapter')
NfcManager = autoclass('android.nfc.NfcManager')
Intent = autoclass('android.content.Intent')
Uri = autoclass('android.net.Uri')
File = autoclass('java.io.File')
Object = autoclass('java.lang.Object')
class CreateNfcBeamUrisCallback(PythonJavaClass):
__javainterfaces__ = ['android/nfc/NfcAdapter$CreateBeamUrisCallback']
__javacontext__ = 'app'
def __init__(self, callback):
super(CreateNfcBeamUrisCallback, self).__init__()
self.callback = callback
self.uris = []
self.changed = False
# def __init__(self):
# super(CreateNfcBeamUrisCallback, self).__init__()
#
# self.manager = cast('android.nfc.NfcManager', PythonActivity.mActivity.getSystemService(mContext.NFC_SERVICE))
#
# self.do_stop = False
# self.adapter = self.manager.getDefaultAdapter()
#
# if self.adapter is None:
# print 'This device does not support NFC.'
# return
# else:
# print 'This device does support NFC.'
# self.adapter.setBeamPushUrisCallback(self, PythonActivity.mActivity)
#
# def start(self):
# self.do_stop = False
#
# for x in range(0,5):
# print 'Def Start'
#
# if NfcAdapter.ACTION_NDEF_DISCOVERED.equals(PythonActivity.mActivity.getIntent().getAction()):
# pass
@java_method('()I')
def hashCode(self):
return id(self)
def addUris(self, fileUri):
if not self.changed:
self.uris = [cast(Uri, fileUri)]
self.changed = True
else:
self.uris.append(cast(Uri, fileUri))
@java_method('(Landroid/nfc/NfcEvent;)[Landroid/net/Uri;')
def createBeamUris(self, event):
for x in range(0,5):
print 'createBeams'
if not self.changed:
context = PythonActivity.mActivity
currentApp = File((cast(mContext, context)).getPackageResourcePath())
self.uris[0] = cast(Uri, Uri.fromFile(currentApp))
print Uri.decode(self.uris[0].getEncodedPath())
return self.uris