मैंने पृष्ठभूमि स्कैनिंग के लिए एंड्रॉइड आईबीओन लाइब्रेरी के साथ काम किया, मैंने एक सेवा बनाई और सेवा में मैंने निगरानी और लेकर दोनों को परिभाषित किया। जब सेवा नष्ट हो जाती है और मेरे लिए इसका काम होता है तो मैं सेवा शुरू करता हूं। इस तरह की नई सेवा बनाएं।
public class Beaconservice extends Service implements IBeaconConsumer {
private ArrayList<IBeacon> arrayL = new ArrayList<IBeacon>();
private BeaconServiceUtility beaconUtill = null;
private IBeaconManager iBeaconManager = IBeaconManager.getInstanceForApplication(this);
private Handler hand;
private Runnable runn;
private int count = 30;
@Override
public void onIBeaconServiceConnect() {
iBeaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<IBeacon> iBeacons, Region region) {
arrayL.clear();
arrayL.addAll((ArrayList<IBeacon>) iBeacons);
if(count>0){
count=0;
}
}
});
iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
@Override
public void didEnterRegion(Region region) {
Log.e("BeaconDetactorService", "didEnterRegion");
// logStatus("I just saw an iBeacon for the first time!");
}
@Override
public void didExitRegion(Region region) {
Log.e("BeaconDetactorService", "didExitRegion");
// logStatus("I no longer see an iBeacon");
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.e("BeaconDetactorService", "didDetermineStateForRegion");
// logStatus("I have just switched from seeing/not seeing iBeacons: " + state);
}
});
try {
iBeaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
} catch (RemoteException e) {
e.printStackTrace();
}
try {
iBeaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
beaconUtill = new BeaconServiceUtility(this);
Log.e("UUID","start service");
hand = new Handler();
runn = new Runnable() {
@Override
public void run() {
count ++;
hand.postDelayed(runn, 1000);
}
};
hand.post(runn);
super.onCreate();
}
@Override
@Deprecated
public void onStart(Intent intent, int startId) {
beaconUtill.onStart(iBeaconManager, this);
beaconUtill = new BeaconServiceUtility(this);
super.onStart(intent, startId);
}
@Override
public void onDestroy() {
beaconUtill.onStop(iBeaconManager, this);
super.onDestroy();
}
}
AndroidManifest.xml
में
<service android:name="com.beacone.keyfinder.app.Beaconservice" >
</service>
स्रोत
2015-11-04 04:22:33
वैसे उस स्थिति में जब ऐप पृष्ठभूमि में नहीं चल रहा है, तो आपको 'ब्रॉडकास्ट रिसीवर' और 'सेवा' का उपयोग करना चाहिए। ब्लूटूथ पर अपने प्रसारण कनेक्ट और डिस्कनेक्ट (बीकन के लिए स्टॉप सेवा) (बीकन के लिए सेवा को प्रारंभ) –
'Estimote' बीकन का प्रयास के लिए' Filters' सेट वे अपने स्वयं के 'SDK' और कार्यान्वयन की है। मैंने एक ऐप बनाया है जिसमें मैंने एंड्रॉइड बीकन और बीएलई के बारे में समझने के लिए किसी भी शुरुआत के लिए यह बहुत उपयोगी उपयोग किया था। इस लिंक से https://github.com/Estimote/Android-SDK –
@Zubair अहमदखान iBeacon लाइब्रेरी खोज अनुमानित बीकन के साथ-साथ कस्टम बीकन के लिए भी आज़माएं। – Lawrance