如何使用phonegap在android中打开位置设置

如何使用phonegap在android中打开位置设置,android,cordova,phonegap-plugins,webintents,Android,Cordova,Phonegap Plugins,Webintents,我正在尝试使用phonegap的WebIntent插件在android中打开位置设置。我使用phonegap的GPSDetector插件来检测位置是否处于活动状态,如果未处于活动状态,我想打开位置设置。激活位置后,按后退按钮并转到index.html window.plugins.webintent.startActivity({ action: 'android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS'}, f

我正在尝试使用phonegap的WebIntent插件在android中打开位置设置。我使用phonegap的GPSDetector插件来检测位置是否处于活动状态,如果未处于活动状态,我想打开位置设置。激活位置后,按后退按钮并转到index.html

window.plugins.webintent.startActivity({
      action: 'android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS'},
      function() {},
      function() {alert('Failed to open URL via Android Intent')}
 );
在这种情况下,我不知道哪一个是动作,我试过这样做,但没有成功。 我制作了一个活动,并在其中添加了onCreate方法:

startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
但是用这种方式,我不知道在用户打开位置(Gps)后如何将其发送回index.html。
请帮忙,非常感谢

我没有使用任何可用的插件。我写了自己的插件,这是该插件的java代码。检查这是否有用。这是你对我的要求

if (CHECK_LOCATION_SERVICES_ENABLED.equals(action))
  {
      try 
      {   boolean locationServicesEnabled=false;
          if(this.ctx.getContext()!=null)
          {
              //Location services not enabled

              final Context context = this.ctx.getContext();
              (new Thread(new Runnable() {

                  @Override
                  public void run() {
                      Looper.prepare();

                      final Handler innerHandler = new Handler() {
                          @Override
                          public void handleMessage(Message message) {
                              /*Toast.makeText(myContext,android.os.Build.VERSION.RELEASE,
                              Toast.LENGTH_LONG).show();*/                                                                
                              LocationManager lm = null;
                              boolean gps_enabled=false,network_enabled=false;
                                 if(lm==null)
                                     lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
                                 try{
                                 gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
                                 }catch(Exception ex){}
                                 try{
                                 network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
                                 }catch(Exception ex){}

                                if(!gps_enabled && !network_enabled){
                                    AlertDialog.Builder alertDialog = new AlertDialog.Builder(
                                            context);

                                    alertDialog.setTitle("FindMe");

                                    alertDialog
                                            .setMessage("You must enable Location Services for using FindMe.\nDo you want to go to Location Sources Settings?");

                                    alertDialog.setPositiveButton("Settings",
                                            new DialogInterface.OnClickListener() {
                                                public void onClick(DialogInterface dialog, int which) {
                                                    Intent intent = new Intent(
                                                            Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                                    context.startActivity(intent);
                                                }
                                            });

                                    alertDialog.setNegativeButton("Cancel",
                                            new DialogInterface.OnClickListener() {
                                                public void onClick(DialogInterface dialog, int which) {
                                                    dialog.cancel();
                                                }
                                            });

                                    alertDialog.show();

                                 }
                          }

                          @Override
                          public void dispatchMessage(Message message) {
                              handleMessage(message);
                          }
                      };

                      Message message = innerHandler.obtainMessage();
                      innerHandler.dispatchMessage(message);
                      Looper.loop();
                  }
              })).start();

          }
          return new PluginResult(PluginResult.Status.OK,"success ");               
      }                    
      catch (Exception ex)
      {                          
           Log.d("FindMePlugin", ex.toString());
           return new PluginResult(PluginResult.Status.ERROR, "error"+ex.toString());
      }             
  }

谢谢你的回答,我昨天几乎和你一样解决了这个问题,我使用adroid本机代码进行CordovaActivity。