android - Android服务的onresume方法

标签 android android-service

我正在尝试制作一项等待 NFC 标签并执行某些操作的服务。我可以在 Activity 中使用以下代码块来做到这一点,但即使在研究之后也不知道如何在服务中实现它。

@Override
protected void onResume() {
    super.onResume(); // Sticky notes received from Android if
    enableNdefExchangeMode();

    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
        do_something();
    }
}

我想在服务中这样做。我不能使用 super.onResume()。我应该用什么代替这个,或者如何做?

任何帮助将不胜感激。已经感谢您的帮助

最佳答案

给你:)

我也建议在这里看看:http://developer.android.com/guide/topics/nfc/index.html更多文档、示例和代码

<service 
            android:name="com.myexample.ServiceName" >
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.nfc.action.NDEF_DISCOVERED" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="application/com.example.android.beam" />
            </intent-filter>
        </service>

更新:这是一个完整的例子:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/nfc/ForegroundDispatch.html

关于android - Android服务的onresume方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10980315/

相关文章:

android camera2 api - 在 session.capture 之后不调用 onImageAvailable

android - 应用程序通知弹出移动设备网络浏览器

启动位置服务时出现java.lang.SecurityException

android - AlarmManager 正在重新创建服务

delphi - 如何在系统启动时启动android服务?

android - 按主页按钮时黑屏

android - 如何在 PhoneRTC 视频通话中保持显示屏唤醒?

java - 从地点选择器获取地名,经纬度并在 map 中显示

android - NativeScript 的 WebView 内联播放视频

Android - 如何为 API-28 使用 startForegroundService() 和 startForeground()?