4

나는 Estimote 비컨을 찾고 사용자에게 푸시 알림을 보낼 수있는 Android 서비스를 만들고자합니다. 샘플 코드를 다운로드하고 해당 코드를 사용하여 새로운 myService 활동을 만들었습니다. 코드가 실행 중이며 LogCat에서 Android가 비콘을 검색하고 있음을 알 수 있습니다. 불행하게도 비컨은 발견되지 않습니다. 내 코드에 어떤 문제가 있습니까?백그라운드에서 Estimote 비콘 탐지기 서비스

아니면 내가 잘못하고있는 중입니까?

package com.osos.service; 

import java.util.Collections; 
import java.util.List; 
import java.util.concurrent.TimeUnit; 

import com.estimote.sdk.Beacon; 
import com.estimote.sdk.BeaconManager; 
import com.estimote.sdk.BeaconManager.MonitoringListener; 
import com.estimote.sdk.BeaconManager.RangingListener; 
import com.estimote.sdk.Region; 
import com.estimote.sdk.utils.L; 

import android.R; 
import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.app.Service; 
import android.content.Context; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.IBinder; 
import android.os.RemoteException; 
import android.support.v4.app.TaskStackBuilder; 
import android.util.Log; 
import android.widget.TextView; 
import android.widget.Toast; 

public class MyService extends Service{ 
     private static final int NOTIFICATION_ID = 123; 
    private BeaconManager beaconManager; 
    Beacon beacon; 
    private NotificationManager myNotificationManager; 
    private NotificationManager notificationManager; 
    private static final String TAG = "MyService"; 
private static final Region ALL_ESTIMOTE_BEACONS_REGION = new Region("rid", null, null, null); 
    @Override 
    public IBinder onBind(Intent arg0) { 
     return null; 
    } 

    @Override 
    public void onCreate() { 

     beaconManager = new BeaconManager(this); 
     beaconManager.setBackgroundScanPeriod(TimeUnit.SECONDS.toMillis(1), 0); 
//  beaconManager.setRangingListener(new RangingListener() { 
//   
//   @Override 
//   public void onBeaconsDiscovered(Region arg0, List<Beacon> beacons_list) { 
//    // TODO Auto-generated method stub 
//    
//   } 
//  }); 
     Toast.makeText(this, "Jus paleidote OSOS serviza", Toast.LENGTH_LONG).show(); 
     Log.d(TAG, "onCreate"); 
      L.enableDebugLogging(true); 
      Log.d(TAG, "onStartCOmmand"); 
      try{ 
       connectToService(); 
      }catch(Exception e){ 
       System.out.println("### problem ####"); 
       System.out.println(e); 
      } 


    } 


    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) { 
     Log.d(TAG, "onStartCOmmand"); 

     beaconManager.setMonitoringListener(new MonitoringListener() { 
       @Override 
       public void onEnteredRegion(Region region, List<Beacon> beacons) { 
        switch(beacon.getMinor()){ 
        case 11111: displayNotificationOne(1,"This is OSOS"); 
        break; 
        default:  displayNotificationOne(1,"This is Sparta"); 

       } 
       } 
       @Override 
       public void onExitedRegion(Region region) { 
        displayNotificationOne(2,"Exited OSOS"); 
       } 
      }); 




     return startId; 



    } 

    protected void displayNotificationOne(int i, String msg) { 
     Log.d(TAG, "Display notif"); 
     // Invoking the default notification service 
     Notification.Builder mBuilder = new Notification.Builder(this); 

     mBuilder.setContentTitle("Simplify"); 
     mBuilder.setContentText("Jus turite nauju uzduociu"); 
     mBuilder.setTicker("Simplify: Jus turite nauju uzduociu"); 
     mBuilder.setSmallIcon(R.drawable.arrow_up_float).setAutoCancel(true).build(); 

     long[] vibrate = {0,200,500 }; 
     mBuilder.setVibrate(vibrate); 
     //mBuilder.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.groan)); 

     // Increase notification number every time a new notification arrives 

     mBuilder.setAutoCancel(true); 
     // Creates an explicit intent for an Activity in your app 
//  Intent resultIntent = new Intent(this, Welcome.class); 

     // This ensures that navigating backward from the Activity leads out of 
     // the app to Home page 
     TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
     // Adds the back stack for the Intent 
//  stackBuilder.addParentStack(StartedReviewsActivity.class); 


     // Adds the Intent that starts the Activity to the top of the stack 
//  stackBuilder.addNextIntent(resultIntent); 
     PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, 
       PendingIntent.FLAG_ONE_SHOT // can only be used once 
       ); 
     // start the activity when the user clicks the notification text 
     mBuilder.setContentIntent(resultPendingIntent); 


     myNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     // pass the Notification object to the system 
     myNotificationManager.notify(1, mBuilder.build()); 
    } 

    private void connectToService() { 
      Log.e(TAG, "Connect to service"); 
//   getActionBar().setSubtitle("Scanning..."); 
//   adapter.replaceWith(Collections.<Beacon>emptyList()); 
      beaconManager.connect(new BeaconManager.ServiceReadyCallback() { 
       @Override 
       public void onServiceReady() { 
       try { 
        beaconManager.startRanging(ALL_ESTIMOTE_BEACONS_REGION); 
       } catch (RemoteException e) { 

        Log.e(TAG, "Cannot start ranging", e); 
       } 
       } 
      }); 
      } 
    @Override 
    public void onDestroy() { 
     Toast.makeText(this, "MyService Stopped", Toast.LENGTH_LONG).show(); 
     Log.d(TAG, "onDestroy"); 
     beaconManager.disconnect(); 
    } 
} 
+0

행운? 나는 같은 문제에 직면 해있다. – Sree

답변

0

그렇습니다. 이는 비컨의 UUID, MAJOR 및 MINOR 번호를 변경하지 않았기 때문입니다. 귀하의 휴대 전화에서 추정 SDK 애플 리케이션을 다운로드하고 다음 세 숫자가 모두 당신이 이미 가지고 교체 할 수 있습니다. 그것은 일을 시작할 것이다.