Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:27:27+00:00 2026-06-16T03:27:27+00:00

I have looked through all of the other posts that have this problem, to

  • 0

I have looked through all of the other posts that have this problem, to no avail.

I have created an app, that works perfectly when all of the code is housed inside of MainActivity, but when I create a class to check the GPS, and clean up my MainActivity source file, I get an error when debugging that says “source not found”.

I am new to android and java for that matter (I typically work with c & c++), so I don’t know if this has something to do with my manifest.xml or the like, but it is driving me nuts!

I have included my code below, along with my manifest.xml file.

When going through my code line by line, the line that gives me this error is final LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE);

GpsCheck.java

package com.omegaapp.openomega;

import android.os.*;
import android.location.*;
import android.location.GpsStatus.Listener;
import android.app.*;
import android.content.*;
import com.omegaapp.*;



public class GpsCheck extends android.app.Activity{

    public GpsCheck(){
        final LocationManager manager =  (LocationManager) getSystemService(LOCATION_SERVICE);
        Listener gpsStatusListener = new Listener(){
            @Override
            public void onGpsStatusChanged(int arg0) {
                gpsEnable();

            }
        };
        manager.addGpsStatusListener(gpsStatusListener);
    }

    public boolean gpsEnable(){
        //checks weather the GPS is enabled. If not, prompts the user to enable it then checks again. Returns false if the user chooses not to enable the application.
        if(!checkGpsEnabled()){
            promptEnableGps();
        }
        return true;
    }

    private boolean checkGpsEnabled(){
        final LocationManager manager =  (LocationManager) getSystemService(LOCATION_SERVICE);
        if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
            return false;
        }
        return true;
    }

    private boolean promptNoGpsQuit(){
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setMessage("Without enabling GPS this app can not function, Would you like to quit?");
        alertDialogBuilder.setCancelable(false);
        DialogInterface.OnClickListener onClick = new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int id){
                Intent callGPSSettingIntent = new Intent(
                android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(callGPSSettingIntent);
            }
        };
        alertDialogBuilder.setPositiveButton("Goto Settings Page To Enable GPS", onClick);

        DialogInterface.OnClickListener onClickCancel = new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int id){
                dialog.cancel();
                finish();
            }
        };
        alertDialogBuilder.setNegativeButton("Quit", onClickCancel);
        AlertDialog alert = alertDialogBuilder.create();
        alert.show();
        return true;
    }

    private boolean promptEnableGps(){
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setMessage("GPS is disabled in your device. Would you like to enable it?");
        alertDialogBuilder.setCancelable(false);
        DialogInterface.OnClickListener onClick = new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int id){
                Intent callGPSSettingIntent = new Intent(
                android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(callGPSSettingIntent);
            }
        };
        alertDialogBuilder.setPositiveButton("Goto Settings Page To Enable GPS", onClick);

        DialogInterface.OnClickListener onClickCancel = new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int id){
                dialog.cancel();
                promptNoGpsQuit();
            }
        };
        alertDialogBuilder.setNegativeButton("Cancel", onClickCancel);
        AlertDialog alert = alertDialogBuilder.create();
        alert.show();
        return true;
    }

}

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.omegaapp.openomega"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.omegaapp.openomega.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:enabled="true" android:name=".BootUpReceiver"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

        <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>
</application>

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:27:28+00:00Added an answer on June 16, 2026 at 3:27 am

    Here

    public class GpsCheck extends android.app.Activity{
    
        public GpsCheck(){
    
      }
          your code  .....
    }
    

    this is not right way to create an non Activity class for getting Context of Activity . you will need to pass Activity Context to non Activity class for Accessing system services or other Activity or Application components

    Change your GpsCheck as for make it working by passing Context to GpsCheck constructor as:

    public class GpsCheck{
       Context context;
        LocationManager manager;
    
        public GpsCheck(Context context){
         this.context=context;
    
         this.manager =  (LocationManager)context.getSystemService(LOCATION_SERVICE);
         //your code here
        }
          your code  .....
    }
    

    and from your Activity send Current Activity Context as :

    GpsCheck gpscheckobj=new GpsCheck(MainActivity.this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked through several posts but I haven't quite found any answers that have
I have looked through all the OpenCV documentation that I could find and googled
I've looked through various other questions about this and they are all fixed by
I have looked through these forums to find a solution to this problem, and
I have googled this, searched this, looked through SO and other sites (I've been
First of all: I looked through other posts on stackoverflow and none of them
I've looked through so many forum posts about this simple piece of code. And
Ok.. I have looked through this site and just can't seem to find the
I have looked around some now to find a solution to this problem. I
This may be an easy one. I looked through previous questions (and other places

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.