简体   繁体   English

如何在Android中读取NFC标签并调用Web服务

[英]How to read NFC Tag and call Webservice in Android

I'm now developing an android application with the NFC concept . 我现在正在使用NFC concept开发一个android应用程序。 In that application I need to pick my application if I swipe the NFC card and if I select my application my application must start calling webservice. 在该应用程序中,如果我刷NFC卡,则需要选择我的应用程序;如果选择了我的应用程序,则我的应用程序必须开始调用Web服务。

when it comes to my problem, If suppose my app crashed ,when I swipe the card next time ,the option to choose the application doesn't open .Instead,my application directly launched and couldn't call the webservice data. 当遇到问题时,如果我的应用程序崩溃了,那么当我下次刷卡时,选择应用程序的选项就不会打开。相反,我的应用程序直接启动了,无法调用Web服务数据。

On the whole.I'm getting last page when it crashed .But I need to open as fresh 总的来说,当它崩溃时我到达最后一页。但是我需要重新打开

I came to know that I need to make changes in OnResume() and OnNewIntent() . 我知道我需要在OnResume() and OnNewIntent()进行更改。

I used , In OnResume() 我在OnResume()中使用了

    super.onResume();
         mNfcAdapter.enableForegroundDispatch(this, nfcPendingIntent,      mNdefExchangeFilters, null);
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
NdefMessage[] msgs = getNdefMessages(getIntent());

byte[] payload = msgs[0].getRecords()[0].getPayload();


//Toast.makeText(this, new String(payload), Toast.LENGTH_LONG).show();
Student=new String(payload);



if(Student.equals(rakesh)
{
new Webservice.execute("");  // Calling SOAP Webservice
}

But,I can't find any changes with my problem .and one more thing that the problem will be resolve after I just open and close an another NFC project 但是,我找不到与我的问题有关的任何更改。 在我打开和关闭另一个NFC项目之后,问题将得到解决的另一件事

Please help. 请帮忙。

Yeah ! 是的 I got the solution .I forget a simple thing that I left calling onStop() method and my problem was,when my application stops(when Crashed).It runs in background as the previous activity. 我得到了解决方案。我忘记了一个简单的事情,我留下了一个调用onStop()方法的问题,而我的问题是,当我的应用程序停止时(当崩溃时)。它作为上一个活动在后台运行。

I just tried the following, 我只是尝试以下,

   public void onStop()
{
super.onStop();
this.finish();
}

This may be helpful to others. 这可能对其他人有帮助。

Thanks.. 谢谢..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM