小编End*_*r87的帖子

如何?侦听位置设置被打开(Android App)

所以我花了几个星期的时间在我的Android应用程序上工作,并研究实现我需要做的最好的方法,但仍然无法正确完成..任何/所有帮助都非常感谢,因为我是仍然掌握着一切......

任务:

(假设"位置"/ GPS设置当前已关闭),我需要让我的应用程序一直在监听"位置"设置是否打开..此时,只需启动一个活动.

思路:

这些是我认为可能有用的不同方式:

  • LocationListener使用"onProviderEnabled"

  • 使用"onGpsStatusChanged"和"GPS_EVENT_STARTED"的GpsStatusListener

  • GpsProvider需要卫星(以确定它是否启动),或以某种方式使用GpsProvider的"AVAILABLE"Constant/int

  • 使用"ACTION_SERVICE_INTENT"(和/或)"ACTION_INJECTED_SETTING_CHANGED"与"onGetEnabled"或"isEnabled"的SettingInjectorService

  • Settings.Secure使用"LOCATION_MODE"!="LOCATION_MODE_OFF"

  • ContentObserver/ContentResolver

  • 意图getAction(...)

  • 某种"if/else"

问题:

任何以下任何问题的建议或答案都非常感谢..

  • 以上哪些想法是完成任务的最佳方式?越简单越好,但最重要的是它需要一直监听,并在打开位置设置时立即响应.

  • 对于上述哪个观点效果最好,我将如何实现它?(例如,我需要一个BroadcastListener?还是一个服务?它将如何组合在一起?

我非常感谢你能给我的任何建议或帮助..我仍然掌握所有这一切,但有足够的信心去做,并渴望发布我的第一个应用程序..所以谢谢你,这意味着很多并将极大地帮助我.


编辑:

好的所以这就是我到目前为止所得到的...... 继承人
我的接收者:

MyReceiver.Java

public class MyReceiver extends BroadcastReceiver {

    private final static String TAG = "LocationProviderChanged";

    boolean isGpsEnabled;
    boolean isNetworkEnabled;



    public MyReceiver() {
    // EMPTY

    // MyReceiver Close Bracket
    }



    // START OF onReceive
    @Override
    public void onReceive(Context context, Intent intent) {


        // PRIMARY RECEIVER
        if (intent.getAction().matches("android.location.PROVIDERS_CHANGED")) {

            Log.i(TAG, "Location Providers Changed");

            LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
            isGpsEnabled = …
Run Code Online (Sandbox Code Playgroud)

java gps android broadcastreceiver locationmanager

8
推荐指数
1
解决办法
7469
查看次数

"没有找到存储库" - 通过Eclipse更新Android ADT

我安装了Android SDK/ADT捆绑包,Eclipse正在运行.首先奇怪的是,当我点击"检查更新"时,它说没有可用的.虽然当我点击"安装新软件"并选择内置的android dl站点时,可以获得ADT的更新,这比安装的稍微新一些.无论如何,这不是我的问题..所以,我勾选可用的更新,并尝试安装它.几分钟的进度后,我收到以下错误消息:

  [Problem Occurred] 'Installing Software' has encountered a problem. An error occurred while collecting items to be installed -----(I click 'Details' and this is what is shown): session context was:(profile=profile, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=). 
    No repository found containing:osgi.bundle,com.android.ide.eclipse.adt,22.6.3.v201404151837-1123206
    No repository found containing: osgi.bundle,com.android.ide.eclipse.adt.package,22.6.3.v201404151837-1123206
    No repository found containing:osgi.bundle,com.android.ide.eclipse.base,22.6.3.v201404151837-1123206
   No repository found containing:osgi.bundle,com.android.ide.eclipse.ddms,22.6.3.v201404151837-1123206
    No repository found containing:osgi.bundle,com.android.ide.eclipse.gldebugger,22.6.3.v201404151837-1123206
    No repository found containing:osgi.bundle,com.android.ide.eclipse.hierarchyviewer,22.6.3.v201404151837-1123206
   No repository found containing:osgi.bundle,com.android.ide.eclipse.ndk,22.6.3.v201404151837-1123206
    No repository found containing:osgi.bundle,com.android.ide.eclipse.traceview,22.6.3.v201404151837-1123206
    No repository found containing: osgi.bundle,overlay.com.android.ide.eclipse.adt.overlay,22.6.3.v201404151837-1123206
   No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.adt,22.6.3.v201404151837-1123206 …
Run Code Online (Sandbox Code Playgroud)

eclipse android adt

2
推荐指数
1
解决办法
5554
查看次数

标签 统计

android ×2

adt ×1

broadcastreceiver ×1

eclipse ×1

gps ×1

java ×1

locationmanager ×1