私は基本的に最初の答えを使ってthisを達成しようとしています。質問にはWebとSOの周りの回答がありますが、問題を解決するには問題があります。有効にして、私の目録に追加する必要があるものはありますか?私は電話の範囲内に来るビーコンに反応したい。私はアンドロイドスタジオで、Android 4.3をターゲットにして、Android Beacon Libraryで作業しています。彼らのドキュメントに基づいて、BootstrapNotifier
を実装し、Region
に設定し、ビーコンをスキャンするときはいつでも、それは自動的にdidEnterRegion
を呼び出します。私の地域はRegion region = new Region("all-beacons-region", null, null, null);
です。バックグラウンドでEddystoneビーコンに反応する
私はまた、フォアグラウンドでビーコンをスキャンして見つける非常にシンプルなアプリケーションを構築しました。だからそこに問題はない、私は間違いなく私のビーコンをピックアップし、それらから基本的な情報を引き出すことができます。
私の主な活動は次のようになります。
package com.example.justin.backgroundscantest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
そして、私のクラスには、次のようになります。
import android.app.Application;
import android.content.Intent;
import android.util.Log;
import com.example.justin.backgroundscantest.MainActivity;
import org.altbeacon.beacon.startup.BootstrapNotifier;
import org.altbeacon.beacon.startup.RegionBootstrap;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.Region;
public class TestApp extends Application implements BootstrapNotifier {
private static final String TAG = ".TestApp";
private RegionBootstrap regionBootstrap;
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "App started up");
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
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 any beacon is seen (you can specify specific id filers in the parameters below)
Region region = new Region("com.example.myapp.boostrapRegion", null, null, null);
regionBootstrap = new RegionBootstrap(this, region);
}
@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);
}
}
(編集) 最後に、AndroidManifest.xmlに:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.justin.backgroundscantest">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
それ私は何か単純か愚かなものを見逃している場合、私は好奇心が強いです。私はこの例をウェブの周りのいくつかの場所で見つけましたが、私が見逃したかもしれないことは言及しませんでした。私は非常に堅実なコーディングの背景を持っていますが、Androidには新しく、Eddystone/BLE技術にはまったく新しいものです。そして実際の問題を明確にするために:私はビーコンの範囲内で携帯電話を移動するとき、私のアプリからの反応はありません。私の期待は、それが "目覚め"てMainActivityを開始することです。私は間違いなくビーコンの範囲内にあり、ビーコンは間違いなくオンであり、再びフォアグラウンドでスキャンすることができます。それは私のアプリを目を覚ますことはありません。ありがとう!
AndroidManifest.xmlを表示できますか? – davidgyoung
質問を編集しました – brocky34
もっと見ると、私のマニフェストのにTestAppを定義するために何かする必要がありますか?私は、アプリケーションを拡張するクラスを書く方法が完全にはっきりしていないという問題があるのだろうかと思います。 –
brocky34