<tfoot id='an7bR'></tfoot><legend id='an7bR'><style id='an7bR'><dir id='an7bR'><q id='an7bR'></q></dir></style></legend>

    <i id='an7bR'><tr id='an7bR'><dt id='an7bR'><q id='an7bR'><span id='an7bR'><b id='an7bR'><form id='an7bR'><ins id='an7bR'></ins><ul id='an7bR'></ul><sub id='an7bR'></sub></form><legend id='an7bR'></legend><bdo id='an7bR'><pre id='an7bR'><center id='an7bR'></center></pre></bdo></b><th id='an7bR'></th></span></q></dt></tr></i><div id='an7bR'><tfoot id='an7bR'></tfoot><dl id='an7bR'><fieldset id='an7bR'></fieldset></dl></div>
          <bdo id='an7bR'></bdo><ul id='an7bR'></ul>

        <small id='an7bR'></small><noframes id='an7bR'>

        有没有办法从代码创建 ACTION_NDEF_DISCOVERED 意图

        时间:2023-09-10

          • <tfoot id='BRcHY'></tfoot>

                <tbody id='BRcHY'></tbody>

              <small id='BRcHY'></small><noframes id='BRcHY'>

              <legend id='BRcHY'><style id='BRcHY'><dir id='BRcHY'><q id='BRcHY'></q></dir></style></legend>
                <bdo id='BRcHY'></bdo><ul id='BRcHY'></ul>

              • <i id='BRcHY'><tr id='BRcHY'><dt id='BRcHY'><q id='BRcHY'><span id='BRcHY'><b id='BRcHY'><form id='BRcHY'><ins id='BRcHY'></ins><ul id='BRcHY'></ul><sub id='BRcHY'></sub></form><legend id='BRcHY'></legend><bdo id='BRcHY'><pre id='BRcHY'><center id='BRcHY'></center></pre></bdo></b><th id='BRcHY'></th></span></q></dt></tr></i><div id='BRcHY'><tfoot id='BRcHY'></tfoot><dl id='BRcHY'><fieldset id='BRcHY'></fieldset></dl></div>
                1. 本文介绍了有没有办法从代码创建 ACTION_NDEF_DISCOVERED 意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  对于我正在编写的应用程序,我想知道是否可以从代码创建 ACTION_NDEF_DISCOVERED 意图.通常,此意图是由系统在读取 ndef 格式的标签时创建的.它包含一个类型为 Tag 的 parcableextra.

                  For an app i'm writing i am wondering if it is possible to create an ACTION_NDEF_DISCOVERED intent from code. Normally this intent is created by the system when reading an ndef formatted tag. It contains a parcableextra of the type Tag.

                  意图的创建可能很容易,但是您是否也可以从代码中创建一个标签,或者我认为该类不支持该标签.

                  The creation of the intent is probably easy but can you also create a Tag from code or is that not supported by the class as i suppose.

                  目标是将带有 ndef 记录的虚拟标签广播到系统,然后可由调用 ACTION_NDEF_DISCOVERED 意图的应用程序处理.

                  The goal is to broadcast a virtual tag with an ndef record to the system that then can be handled by an app that calls on the ACTION_NDEF_DISCOVERED intent.

                  推荐答案

                  你可以使用反射获得一个模拟标签对象实例.像这样的东西应该可以工作:

                  You could get a mock tag object instance using reflection. Something like this should work:

                  NdefMessage ndefMsg = ...;
                  
                  Class tagClass = Tag.class;
                  Method createMockTagMethod = tagClass.getMethod("createMockTag", byte[].class, int[].class, Bundle[].class);
                  
                  final int TECH_NFC_A = 1;
                  final int TECH_NDEF = 6;
                  
                  final String EXTRA_NDEF_MSG = "ndefmsg";
                  final String EXTRA_NDEF_MAXLENGTH = "ndefmaxlength";
                  final String EXTRA_NDEF_CARDSTATE = "ndefcardstate";
                  final String EXTRA_NDEF_TYPE = "ndeftype";
                  
                  Bundle ndefBundle = new Bundle();
                  ndefBundle.putInt(EXTRA_NDEF_MSG, 48); // result for getMaxSize()
                  ndefBundle.putInt(EXTRA_NDEF_CARDSTATE, 1); // 1: read-only, 2: read/write
                  ndefBundle.putInt(EXTRA_NDEF_TYPE, 2); // 1: T1T, 2: T2T, 3: T3T, 4: T4T, 101: MF Classic, 102: ICODE
                  ndefBundle.putParcelable(EXTRA_NDEF_MSG, ndefMsg);
                  
                  Tag mockTag = (Tag)createMockTagMethod.invoke(null,
                          new byte[] { (byte)0x12, (byte)0x34, (byte)0x56, (byte)0x78 },
                          new int[] { TECH_NFC_A, TECH_NDEF },
                          new Bundle[] { null, ndefBundle });
                  

                  这样做的问题是您将无法连接到此标签.因此,所有需要使用真实标签或注册到NFC 服务将失败.具体来说,只有

                  The problem with this is that you will not be able to connect to this tag. Consequently, all methods of the Ndef object (that you can get from that mock Tag instance) that require IO operations with a real tag or a real tag that is registered with the NFC service will fail. Specifically, only

                  • getCachedNdefMessage(),
                  • getMaxSize(),
                  • getType(),
                  • isWritable(),和
                  • getTag()

                  会起作用的.

                  如果您不将 Tag 对象作为 NDEF_DISCOVERED 意图的一部分传递,而只使用 EXTRA_NDEF_MESSAGES 额外的意图.

                  So pretty much the same functionality would be available if you do not pass a Tag object as part of the NDEF_DISCOVERED intent and instead just use the EXTRA_NDEF_MESSAGES intent extra.

                  这篇关于有没有办法从代码创建 ACTION_NDEF_DISCOVERED 意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:区分 NTAG213 和 MF0ICU2 下一篇:iOS UITableViewCells 行被回收并且标签不起作用

                  相关文章

                2. <small id='RdMvS'></small><noframes id='RdMvS'>

                3. <legend id='RdMvS'><style id='RdMvS'><dir id='RdMvS'><q id='RdMvS'></q></dir></style></legend>
                  <i id='RdMvS'><tr id='RdMvS'><dt id='RdMvS'><q id='RdMvS'><span id='RdMvS'><b id='RdMvS'><form id='RdMvS'><ins id='RdMvS'></ins><ul id='RdMvS'></ul><sub id='RdMvS'></sub></form><legend id='RdMvS'></legend><bdo id='RdMvS'><pre id='RdMvS'><center id='RdMvS'></center></pre></bdo></b><th id='RdMvS'></th></span></q></dt></tr></i><div id='RdMvS'><tfoot id='RdMvS'></tfoot><dl id='RdMvS'><fieldset id='RdMvS'></fieldset></dl></div>

                    <tfoot id='RdMvS'></tfoot>

                        <bdo id='RdMvS'></bdo><ul id='RdMvS'></ul>