監視アクティビティ(ここで私のレイアウトには2つのテキストビューがあり、そのうちの1つにdiscoverTimeが保存され、別のdisappearTimeが保存されます)。Androidビーコンライブラリ - ビーコンの発見と消滅時間
public class MonitoringActivity extends Activity {
protected static final String TAG = "MonitoringActivity";
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
TextView discoverTime;
TextView disappearTime;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_monitoring);
verifyBluetooth();
logToDisplay("Application just launched");
discoverTime = (TextView) findViewById(R.id.discoverTime);
disappearTime = (TextView) findViewById(R.id.disappearTime);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Android M Permission check
if (this.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("This app needs location access");
builder.setMessage("Please grant location access so this app can detect beacons in the background.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
@TargetApi(23)
@Override
public void onDismiss(DialogInterface dialog) {
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
PERMISSION_REQUEST_COARSE_LOCATION);
}
});
builder.show();
}
}
}
私はビーコンが出たかdidEnterRegion
でそう消失しdidExitRegion
に、私はTextViewのテキストを設定したときの情報をTextViewに変更したいです。
@Override
public void didEnterRegion(Region arg0) {
// In this example, this class sends a notification to the user whenever a Beacon
// matching a Region (defined above) are first seen.
Log.d(TAG, "did enter region.");
if (!haveDetectedBeaconsSinceBoot) {
Log.d(TAG, "auto launching MainActivity");
// The very first time since boot that we detect an beacon, we launch the
// MainActivity
Intent intent = new Intent(this, MonitoringActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Important: make sure to add android:launchMode="singleInstance" in the manifest
// to keep multiple copies of this activity from getting created if the user has
// already manually launched the app.
//this.startActivity(intent);
SimpleDateFormat df = new SimpleDateFormat("EEE, d MMM yyyy, HH:mm");
String date = df.format(Calendar.getInstance().getTime());
//Toast.makeText(getApplicationContext(), date, Toast.LENGTH_LONG).show();
monitoringActivity.discoverTime.setText(date);
haveDetectedBeaconsSinceBoot = true;
} else {
if (monitoringActivity != null) {
// If the Monitoring Activity is visible, we log info about the beacons we have
// seen on its display
monitoringActivity.logToDisplay("I see a beacon again");
} else {
// If we have already seen beacons before, but the monitoring activity is not in
// the foreground, we send a notification to the user on subsequent detections.
Log.d(TAG, "Sending notification.");
sendNotification();
}
}
}
@Override
public void didExitRegion(Region region) {
if (monitoringActivity != null) {
monitoringActivity.logToDisplay("I no longer see a beacon.");
}
SimpleDateFormat df = new SimpleDateFormat("EEE, d MMM yyyy, HH:mm");
String date = df.format(Calendar.getInstance().getTime());
//Toast.makeText(getApplicationContext(), date, Toast.LENGTH_LONG).show();
monitoringActivity.disappearTime.setText(date);
}
私は私のビーコン・カバレッジのエリアから出て行くが、それは動作しませんでしたテスト。
明らかにするには、エントリメッセージは表示されているが、終了メッセージは表示されないという問題があります。出口のコールバックからログ行が表示されますか? – davidgyoung
BeaconReferenceApplicationクラスのtextviewsを変更しようとしたときにアプリが実行を停止しました...スマートフォンがPCに接続されていないので移動しなければならなかったのでログを確認できました... ..スマートフォンPCに接続されていませんか? – pb772