1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.nfc.reader; 17 18 import android.app.Activity; 19 import android.content.Intent; 20 import android.nfc.NfcAdapter; 21 import android.os.Bundle; 22 import android.util.Log; 23 24 public class BaseReaderActivity extends Activity { 25 private static final String TAG = "BaseReaderActivity"; 26 27 // Intent action that's sent after the test condition is met. 28 protected static final String ACTION_TEST_PASSED = 29 "com.android.nfc.reader.ACTION_TEST_PASSED"; 30 /** Call this in child classes when test condition is met */ setTestPassed()31 protected void setTestPassed() { 32 Intent intent = new Intent(ACTION_TEST_PASSED); 33 sendBroadcast(intent); 34 } 35 36 protected NfcAdapter mAdapter; 37 38 @Override onCreate(Bundle savedInstanceState)39 protected void onCreate(Bundle savedInstanceState) { 40 super.onCreate(savedInstanceState); 41 mAdapter = NfcAdapter.getDefaultAdapter(this); 42 } 43 44 /** Set Poll tech */ setPollTech(int pollTech)45 public void setPollTech(int pollTech) { 46 Log.d(TAG, "setting polltech to " + pollTech); 47 mAdapter.setDiscoveryTechnology(this, pollTech, NfcAdapter.FLAG_LISTEN_KEEP); 48 } 49 50 /** Reset Poll tech */ resetPollTech()51 public void resetPollTech() { 52 mAdapter.resetDiscoveryTechnology(this); 53 } 54 } 55