如何将HCE hostapduservice绑定到android上的主要活动 [英] how to bind HCE hostapduservice to main activity on android

查看:114
本文介绍了如何将HCE hostapduservice绑定到android上的主要活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hy..i有一项任务是让我的kitkat-nexus充当标签。我有ACS 122U作为读者。我已阅读本网站http://blog.opendatalab.de/hack/2013/11/07/android-host-card-emulation-with-acr122/中的程序示例。然后我在我自己的日食上尝试了代码。



主要活动:



hy..i have a task to make my kitkat-nexus to act as a tag. I have ACS 122U as reader. i have read the program example in this site http://blog.opendatalab.de/hack/2013/11/07/android-host-card-emulation-with-acr122/. then i tryed the code on my own eclipse.

main activity :

public class MainActivity extends Activity implements OnMessageReceived, ReaderCallback {

    private NfcAdapter nfcAdapter;
    private ListView listView;
    private IsoDepAdapter isoDepAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView)findViewById(R.id.listView);
        isoDepAdapter = new IsoDepAdapter(getLayoutInflater());
        listView.setAdapter(isoDepAdapter);
        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        Log.i("end of onCreate-----","onCreate HCE");
    }

    @Override
    public void onResume() {
        super.onResume();
        //nfcAdapter.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
            //  null);

        //nfcAdapter.disableReaderMode(this); //tambahan poipo
        Log.i("onResume---", "onResume");
    }

    @Override
    public void onPause() {
        super.onPause();
        nfcAdapter.disableReaderMode(this);
        Log.i("onPause---", "onPause");
    }

    @Override
    public void onTagDiscovered(Tag tag) {
        IsoDep isoDep = IsoDep.get(tag);
        IsoDepTransceiver transceiver = new IsoDepTransceiver(isoDep, this);
        Thread thread = new Thread(transceiver);
        Log.i("dibawah thread", "ontagdiscovered");
        thread.start();
    }

    @Override
    public void onMessage(final byte[] message) {
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                isoDepAdapter.addMessage(new String(message));
                Log.i("didlmrun---", "onMessage");
            }
        });

        Log.i("diluarrun---", "onMessage");
    }

    @Override
    public void onError(Exception exception) {
        onMessage(exception.getMessage().getBytes());
    }
}







hostapduservice:



...

...

...






hostapduservice :

...
...
...

@Override
    public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
        if (selectAidApdu(apdu)) {
            Log.i("HCEDEMO====", "Application selected====");
            return getWelcomeMessage();
        }
        else {
            Log.i("HCEDEMO======", "Received: =====" + new String(apdu));
            return getNextMessage();
        }
    }



...

...

...





然后在清单文件中:




...
...
...


then in the manifest file :

<uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.NFC" />
    <uses-feature android:name="FEATURE_NFC_HOST_CARD_EMULATION"/>




    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <service
            android:name=".MyHostApduService"
            android:exported="true"
            android:permission="android.permission.BIND_NFC_SERVICE" >
            <intent-filter>
                <action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
            </intent-filter>

            <meta-data
                android:name="android.nfc.cardemulation.host_apdu_service"
                android:resource="@xml/apduservice" />
        </service>

         <activity
            android:name="de.grundid.hcedemo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>


        </activity>

    </application>







ok ,,,当我跑上面的源代码,我看到我的acs122u连续闪烁,当我点击它附近的nexus。但我没有看到来自hostapdu服务的log.i(....)。在eclipse log cat中,主活动中只有一些log.i。我应该怎么做将hostapdu服务绑定到主要活动,所以我的nexus可以充当标签... ???在此先感谢...: - )




ok,,when i ran the above source code,, i saw my acs122u blinking continously when i tapped my nexus near to it. but i didn't see the log.i(....) from hostapdu service. In the eclipse log cat, there were just some log.i from main activity. what should i do to bind that hostapdu service to main activity, so my nexus can act as a tag...??? thanks in advance... :-)

推荐答案

这篇关于如何将HCE hostapduservice绑定到android上的主要活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆