【发布时间】:2022-06-10 17:38:39
【问题描述】:
我正在开发一个应该检测 iBeacons 的应用程序。为此,我正在使用 Android 信标库。我能够扫描并检测到指定的信标。但是,当我尝试在后台扫描时,我找到了信标,但我无法将应用程序带回前面。 我的测试过程如下:打开应用程序->开始扫描->按导航栏上的返回或主页按钮->启用iBeacon设备
代码:
override fun didEnterRegion(region: Region?) {
this.runOnUiThread {
Log.d(TAG, "did enter region.")
bringAppToFront()
Toast.makeText(this, "Beacon found", Toast.LENGTH_SHORT).show()
}
}
fun bringAppToFront(){
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
this.startActivity(intent)
}
AndroidManifest.xml
<application
android:allowBackup="true"
android:launchMode="singleInstance"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.BeaconBackgroundScan">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.BeaconBackgroundScan.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我终于收到了祝酒词,但应用程序没有重新打开
【问题讨论】: