0

Good day everyone! I am new to android development and I have a confusion. I was trying to work with iBeacons (university project) but i've encountered the following problem. It keeps saying: "Cannot resolve symbol altbeacon".

I have added this line

implementation 'org.altbeacon:android-beacon-library:2+'

in my dependencies according to official instructions https://altbeacon.github.io/android-beacon-library/configure.html

but I didn't understand where I should include this

repositories {
     mavenCentral()
   }

Here is my gradle file

plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.tarsiusv1"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}


dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.android.gms:play-services-maps:17.0.1'
    implementation 'com.google.android.gms:play-services-maps:18.1.0'
    implementation files('libs/gradle-wrapper.jar')
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'org.altbeacon:android-beacon-library:2+'
}

Full code of that android page.



import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import org.altbeacon.beacon.Beacon;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.Identifier;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.RangeNotifier;
import org.altbeacon.beacon.Region;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import java.util.Locale;



public class MainActivity extends AppCompatActivity implements BeaconConsumer, RangeNotifier{

    private Button navigationSystem;
    private Button helpSystem;
    private Button emergencySystem;
    private Button newsSystem;
    private TextToSpeech tts;
    private String destinationLocation;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if(status != TextToSpeech.ERROR) {
                    tts.setLanguage(Locale.UK);
                }
            }
        });

        navigationSystem = findViewById(R.id.navigationSystemButton);
        emergencySystem = findViewById(R.id.emergencySystemButton);
        newsSystem = findViewById(R.id.newsSystemButton);
        helpSystem = findViewById(R.id.helpSystemButton);

        navigationSystem.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                openNavigationSystemActivity();
            }
        });

        emergencySystem.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                openEmergencySystemActivity();
            }
        });

        newsSystem.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                openNewsSystemActivity();
            }
        });

        helpSystem.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                openHelpSystemActivity();
            }
        });

    }

    public void openHelpSystemActivity(){
        Intent intent = new Intent(this, HelpSystem.class);
        startActivity(intent);
    }

    public void openNavigationSystemActivity(){
        speak();
    }

    public void openEmergencySystemActivity(){
        Intent intent = new Intent(this, EmergencyActivity.class);
        startActivity(intent);
    }

    public void openNewsSystemActivity(){
        String urlStr = "https://www.youtube.com/c/NBCNews/videos";
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(urlStr));
        startActivity(intent);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == 100 && resultCode == RESULT_OK){

            destinationLocation = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS).get(0);
            //Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia");
            Uri gmmIntentUri = Uri.parse("google.navigation:q="+destinationLocation+"&mode=w");
            Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
            mapIntent.setPackage("com.google.android.apps.maps");
            startActivity(mapIntent);
        }
    }

    public void speak(){
        // voice message
        String speech = "Choose the location you want to go";
        tts.speak(speech, TextToSpeech.QUEUE_FLUSH,null);

        //waiting for the user voice input
        Intent speechIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        speechIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Start speaking" );
        startActivityForResult(speechIntent, 100);

    }


}

Aldiyar
  • 35
  • 5

1 Answers1

1

I found the problem. Previously I enabled the "toggle offline mode" in gradle window. I disabled it.

Also I changed this:

implementation 'org.altbeacon:android-beacon-library:2+'

to

implementation 'org.altbeacon:android-beacon-library:2.19'
Aldiyar
  • 35
  • 5