| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package eVVM.apk.ui.home;
- import android.app.PendingIntent;
- import android.content.Intent;
- import android.nfc.NfcAdapter;
- import eVVM.apk.mvp.MvpActivity;
- import eVVM.apk.ui.home.uploadChip.UploadChipPresenter;
- public class BaseNfcActivity extends MvpActivity<UploadChipPresenter> {
- protected NfcAdapter mNfcAdapter;
- private PendingIntent mPendingIntent;
- /**
- * onCreat->onStart->onResume->onPause->onStop->onDestroy
- * 启动Activity,界面可见时.
- */
- @Override
- protected void onStart() {
- super.onStart();
- //此处adapter需要重新获取,否则无法获取message
- mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
- //一旦截获NFC消息,就会通过PendingIntent调用窗口
- mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()), 0);
- }
- /**
- * 获得焦点,按钮可以点击
- */
- @Override
- public void onResume() {
- super.onResume();
- //设置处理优于所有其他NFC的处理
- if (mNfcAdapter != null)
- mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
- }
- /**
- * 暂停Activity,界面获取焦点,按钮可以点击
- */
- @Override
- public void onPause() {
- super.onPause();
- //恢复默认状态
- if (mNfcAdapter != null)
- mNfcAdapter.disableForegroundDispatch(this);
- }
- @Override
- protected int getLayoutId() {
- return 0;
- }
- @Override
- protected int getTitleId() {
- return 0;
- }
- @Override
- protected void initView() {
- }
- @Override
- protected void initData() {
- }
- @Override
- public void onPointerCaptureChanged(boolean hasCapture) {
- }
- @Override
- protected UploadChipPresenter createPresenter() {
- return new UploadChipPresenter();
- }
- }
|