2017-01-15 7 views
0

iBeaconからメジャーIDを文字列として取得し、それを "LoginActivity.java"というアクティビティに渡して渡すことができます私のPHPスクリプトのVolley POSTとログイン情報のユーザ名とパスワードと共に、ビーコンの値がNULLであるかどうかをチェックし、ビーコンが範囲にないというエラーを返してログインできないようにします。JavaクラスのiBeaconメジャーIDをAndroidスタジオのアクティビティに渡す

So私は主なIDを取得して文字列に変換しましたが、 "コンストラクタを解決できません"というインテントを作成するときにエラーが発生します。下に<<<<ERRORというエラーが表示されている行にマークを付けました。 (それは最後に近い)。

package com.mcrlogs.pp.test; 

/** 
* Created by myuser on 15/01/2017. 
*/ 

import android.app.Application; 
import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.bluetooth.BluetoothClass; 
import android.content.Context; 
import android.content.Intent; 

import com.estimote.sdk.Beacon; 
import com.estimote.sdk.BeaconManager; 
import com.estimote.sdk.Region; 

import java.util.List; 
import java.util.UUID; 


public class BeaconChecker extends Application { 

    private BeaconManager beaconManager; 

    public void showNotification(String title, String message) { 
     Intent notifyIntent = new Intent(this, MainActivity.class); 
     notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivities(this, 0, 
       new Intent[] { notifyIntent }, PendingIntent.FLAG_UPDATE_CURRENT); 
     Notification notification = new Notification.Builder(this) 
       .setSmallIcon(R.mipmap.security) 
       .setContentTitle(title) 
       .setContentText(message) 
       .setAutoCancel(true) 
       .setContentIntent(pendingIntent) 
       .build(); 
     notification.defaults |= Notification.DEFAULT_SOUND; 
     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(1, notification); 
    } 

    @Override 
    public void onCreate() { 
     super.onCreate(); 

     beaconManager = new BeaconManager(getApplicationContext()); 

     beaconManager.connect(new BeaconManager.ServiceReadyCallback() { 
      @Override 
      public void onServiceReady() { 
       beaconManager.startMonitoring(new Region(
         "monitored region", 
         UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"), 
         null, null)); 
      } 
     }); 

     beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() { 
      @Override 
      public void onEnteredRegion(Region region, List<Beacon> list) { 
       String iBeaconID = convertIBeaconIDToString(list.get(0).getMajor()); 
       System.out.println(iBeaconID); 
       showNotification(
         "MCR Beacon Detected!", 
         "Login enabled."); 
      } 

      private String convertIBeaconIDToString (int major) { 
       String iBeaconID = ""; 
       iBeaconID = iBeaconID.concat(Integer.toString(major)); 
       return iBeaconID; 
       Intent i = new Intent(this, LoginActivity.class); <<<<ERROR 
       i.putExtra("iBeaconID",iBeaconID); 
      } 

      @Override 
      public void onExitedRegion(Region region) { 
       // could add an "exit" notification too if you want (-: 
      } 
     }); 

    } 

} 

答えて

0

変更してみてください:

Intent i = new Intent(this, LoginActivity.class); 

へ:

Intent i = new Intent(BeaconChecker.this, LoginActivity.class); 

これはthisは、あなたが参照することを明確にIntentのコンストラクタの要件を満たすApplicationクラスです。

+0

賢い、ありがとう! –

関連する問題