示例#1
0
        private void EnableForegroundDispatch()
        {
            // Prepare pending Intent to call us back
            var intent = new Intent(this, typeof(MainActivity));

            intent.PutExtra(InForgoundExtra, true);
            var nfcTagFoundIntent = PendingIntent.GetActivity(this, 0, intent, 0);

            // Filter for NDEF messages with Uris
            var intentFilter = new IntentFilter(NfcAdapter.ActionNdefDiscovered);

            intentFilter.AddDataScheme("http");
            intentFilter.AddDataScheme("https");
            IntentFilter[] intentFilters = { intentFilter };

            // Activate exclusive scanning for our App
            try
            {
                nfcAdapter.EnableForegroundDispatch(this, nfcTagFoundIntent, intentFilters, null);
            }
            catch (Exception e)
            {
                LogMessage("Failed to enable foreground dispatch:\n" + e.Message);
            }
        }
示例#2
0
        private void ListenYubiKey(bool listen)
        {
            if (!_deviceActionService.SupportsNfc())
            {
                return;
            }
            var adapter = NfcAdapter.GetDefaultAdapter(this);

            if (listen)
            {
                var intent = new Intent(this, Class);
                intent.AddFlags(ActivityFlags.SingleTop);
                var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0);
                // register for all NDEF tags starting with http och https
                var ndef = new IntentFilter(NfcAdapter.ActionNdefDiscovered);
                ndef.AddDataScheme("http");
                ndef.AddDataScheme("https");
                var filters = new IntentFilter[] { ndef };
                try
                {
                    // register for foreground dispatch so we'll receive tags according to our intent filters
                    adapter.EnableForegroundDispatch(this, pendingIntent, filters, null);
                }
                catch { }
            }
            else
            {
                try
                {
                    adapter.DisableForegroundDispatch(this);
                }
                catch { }
            }
        }
示例#3
0
        private NfcSensor(Context context)
        {
            mContext    = context.ApplicationContext;
            mNfcAdapter = NfcAdapter.GetDefaultAdapter(mContext);
            mListeners  = new List <ListenerHelper>();
            mTagLock    = new Object();

            if (mNfcAdapter == null)
            {
                return;
            }

            mNfcPermission = mContext.CheckSelfPermission(Android.Manifest.Permission.Nfc) == Android.Content.PM.Permission.Granted;
            if (!mNfcPermission)
            {
                Log.Warn(TAG, "NFC permission required.");
                return;
            }

            IntentFilter ndefIntentFilter = new IntentFilter("android.nfc.action.NDEF_DISCOVERED");

            ndefIntentFilter.AddDataScheme(NFC_DATA_SCHEME);
            mNfcIntentFilters = new IntentFilter[] { ndefIntentFilter };

            mContext.RegisterReceiver(new MyBroadcastReciever(this), ndefIntentFilter);
        }
示例#4
0
        static SampleMediaRouteProvider()
        {
            IntentFilter f1 = new IntentFilter();

            f1.AddCategory(CATEGORY_SAMPLE_ROUTE);
            f1.AddAction(ACTION_GET_STATISTICS);

            IntentFilter f2 = new IntentFilter();

            f2.AddCategory(MediaControlIntent.CategoryRemotePlayback);
            f2.AddAction(MediaControlIntent.ActionPlay);
            f2.AddDataScheme("http");
            f2.AddDataScheme("https");
            addDataTypeUnchecked(f2, "video/*");

            CONTROL_FILTERS = new List <IntentFilter> ();
            CONTROL_FILTERS.Add(f1);
            CONTROL_FILTERS.Add(f2);
        }
示例#5
0
        private void RegisterUninstallReceiver()
        {
            if (uninstallReceiver != null)
            {
                UnregisterUninstallReceiver();
            }
            uninstallReceiver = new UninstallBroadcastReceiver();
            uninstallReceiver.BeatSaberUninstalled += UninstallReceiver_BeatSaberUninstalled;
            IntentFilter filter = new IntentFilter();

            filter.AddAction(Intent.ActionPackageRemoved);
            filter.AddDataScheme("package");

            RegisterReceiver(uninstallReceiver, filter);
        }
        public override void OnResume()
        {
            base.OnResume();

            UpdateNotesTab();

            // Start listening for time updates to adjust "now" bar. TIME_TICK is
            // triggered once per minute, which is how we move the bar over time.
            IntentFilter filter = new IntentFilter();

            filter.AddAction(Intent.ActionPackageAdded);
            filter.AddAction(Intent.ActionPackageRemoved);
            filter.AddAction(Intent.ActionPackageReplaced);
            filter.AddDataScheme("package");
            Activity.RegisterReceiver(packageChangesReceiver, filter);
        }
		public override void OnResume ()
		{
			base.OnResume ();
			
			UpdateNotesTab ();
	
			// Start listening for time updates to adjust "now" bar. TIME_TICK is
			// triggered once per minute, which is how we move the bar over time.
			IntentFilter filter = new IntentFilter ();
			filter.AddAction (Intent.ActionPackageAdded);
			filter.AddAction (Intent.ActionPackageRemoved);
			filter.AddAction (Intent.ActionPackageReplaced);
			filter.AddDataScheme ("package");
			Activity.RegisterReceiver (packageChangesReceiver, filter);
		}