gpt4 book ai didi

android - 我可以在我的应用未运行时收听 Eddystone 信标吗?

转载 作者:太空狗 更新时间:2023-10-29 16:14:56 25 4
gpt4 key购买 nike

Google's new Eddystone standard他们将在 Google Play 服务中提供对安卓的支持 Nearby Api .我们是否可以注册 eddystone 信标并让我们的应用程序接收 Intent ,即使应用程序未运行?

最佳答案

是的,使用 Android Beacon Library 可以做到这一点, 完全支持 Eddystone .

应用程序的后台启动机制在 Eddystone 上的工作方式与它在库支持的其他类型的信标上的工作方式相同。您在自定义 Application 类中使用 RegionBootstrap 对象。您可以阅读有关其工作原理的详细信息 here .

与 Eddystone 的唯一区别是您必须设置一个 BeaconParser 来解码 Eddystone-UID 帧,然后设置一个与您的 Eddystone 相匹配的 Region命名空间 ID:

public class MyApplicationName extends Application implements BootstrapNotifier {
private static final String TAG = ".MyApplicationName";
private RegionBootstrap regionBootstrap;

@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "App started up");
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
// Detect the main identifier (UID) frame:
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19"));

// wake up the app when a beacon matching myEddystoneNamespaceId is seen
myEddystoneNamespaceId = Identifier.parse("0x2f234454f4911ba9ffa6");
Region region = new Region("com.example.myapp.boostrapRegion", myEddystoneNamespaceId, null, null);
regionBootstrap = new RegionBootstrap(this, region);
}

@Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
// Don't care
}

@Override
public void didEnterRegion(Region arg0) {
Log.d(TAG, "Got a didEnterRegion call");
// This call to disable will make it so the activity below only gets launched the first time a beacon is seen (until the next time the app is launched)
// if you want the Activity to launch every single time beacons come into view, remove this call.
regionBootstrap.disable();
Intent intent = new Intent(this, MainActivity.class);
// IMPORTANT: in the AndroidManifest.xml definition of this activity, you must set android:launchMode="singleInstance" or you will get two instances
// created when a user launches the activity manually and it gets launched from here.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}

@Override
public void didExitRegion(Region arg0) {
// Don't care
}
}

关于android - 我可以在我的应用未运行时收听 Eddystone 信标吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31414108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com