信标Android应用程序。无法循环

时间:2018-09-10 08:49:18

标签: java android altbeacon

我正在尝试使用AltBeacon规范开发Beacon Android应用程序,从而该应用程序将启动服务,停止并再次重复服务。到目前为止,我已经能够启动和停止服务,但是,我无法重复第一个“ If”语句。我可以知道我在想什么吗?

b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view)
        {
            // Enter details
            if (major.getText().toString().equals("") || minor.getText().toString().equals(""))
            {
                SuperActivityToast.create(getActivity(), new Style(), Style.TYPE_BUTTON)
                        .setText("Please fill Major and Minor details!")
                        .setDuration(Style.DURATION_LONG)
                        .setFrame(Style.FRAME_LOLLIPOP)
                        .setColor(PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_PURPLE))
                        .setAnimations(Style.ANIMATIONS_POP).show();

            }
            // If user has entered
            {
                final Beacon beacon = new Beacon.Builder()
                        .setId1(uuid1)
                        .setId2(major.getText().toString())
                        .setId3(minor.getText().toString())
                        .setManufacturer(0x0118)
                        .setTxPower(-69)
                        .setRssi(-66)
                        .setBluetoothName("Hall 1")
                        .setDataFields(Arrays.asList(new Long[] {0l}))
                        .build();

                BeaconParser beaconParser = new BeaconParser()
                        .setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");

                // Making the instance of BeaconTransmitter
                final BeaconTransmitter beaconTransmitter = new BeaconTransmitter(getActivity(), beaconParser);

                // Start Advertising the above Beacon Object
                beaconTransmitter.startAdvertising(beacon);

                // Toasting the message that beacon succesfully made
                SuperActivityToast.create(getActivity(), new Style(), Style.TYPE_BUTTON)
                        .setText("Successfully Started!")
                        .setDuration(Style.DURATION_LONG)
                        .setFrame(Style.FRAME_LOLLIPOP)
                        .setColor(PaletteUtils.getSolidColor(PaletteUtils.MATERIAL_PURPLE))
                        .setAnimations(Style.ANIMATIONS_POP).show();

                // Making some animation and changing the text of button
                AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
                alphaAnimation.setDuration(1500);
                alphaAnimation.setFillEnabled(true);
                alphaAnimation.setInterpolator(new BounceInterpolator());
                b1.startAnimation(alphaAnimation);
                b1.setText("Stop Broadcasting");

                b1.setOnClickListener(new View.OnClickListener()
                {
                    public void onClick(View view)
                    {
                        beaconTransmitter.stopAdvertising();
                        b1.setText("Broadcast Beacon");
                    }
                });
            }
        }
    });

0 个答案:

没有答案