从android连接到aspx页面?

时间:2013-04-27 13:30:34

标签: android sql-server

我开发了一个应用程序获取位置,但我需要使用aspx网页将其保存到服务器。 我在网页上创建了表格,我需要使用唯一ID作为imei将这些lat保存到网页页面?

我创建了一张imei,latlong,datetime
的表格 aspx name / http://Log.aspx /

任何人都可以帮助我,但我搜索了很多,但我无法理解。

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

        {
            // initialize location manager

            manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

            // check if GPS is enabled
            // else switch on gps

            if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                Intent intent = new Intent(
                        "android.location.GPS_ENABLED_CHANGE");
                intent.putExtra("enabled", true);
                this.sendBroadcast(intent);

                String provider = Settings.Secure.getString(
                        getContentResolver(),
                        Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
                if (!provider.contains("gps")) { // if gps is disabled
                    final Intent poke = new Intent();
                    poke.setClassName("com.android.settings",
                            "com.android.settings.widget.SettingsAppWidgetProvider");
                    poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
                    poke.setData(Uri.parse("3"));
                    this.sendBroadcast(poke);

                }
            }

            else {

                // get a location provider from location manager
                // empty criteria searches through all providers and returns the
                // best one

                String providerName = manager.getBestProvider(new Criteria(),
                        true);
                Location location = manager.getLastKnownLocation(providerName);

                TextView tv = (TextView) findViewById(R.id.locationResults);
                if (location != null) {
                    tv.setText(location.getLatitude() + " latitude, "
                            + location.getLongitude() + " longitude");

                    Intent intent = new Intent(
                            "android.location.GPS_ENABLED_CHANGE");
                    intent.putExtra("disabled", false);
                    this.sendBroadcast(intent);

                    String provider = Settings.Secure.getString(
                            getContentResolver(),
                            Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
                    if (provider.contains("gps")) { // if gps is enabled
                        final Intent poke = new Intent();
                        poke.setClassName("com.android.settings",
                                "com.android.settings.widget.SettingsAppWidgetProvider");
                        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
                        poke.setData(Uri.parse("3"));
                        this.sendBroadcast(poke);

                    }

                }

                else {

                    // get cell id
                    TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
                    GsmCellLocation loc = (GsmCellLocation) mTelephonyManager
                            .getCellLocation();
                    String networkOperator = mTelephonyManager
                            .getNetworkOperator();

                    Log.d("CID", Integer.toString(loc.getCid()));
                    Log.d("LAC", Integer.toString(loc.getLac()));
                    int mcc = Integer.parseInt(networkOperator.substring(0, 3));
                    int mnc = Integer.parseInt(networkOperator.substring(3));

                    TextView tv1 = (TextView) findViewById(R.id.locationResults);
                    if (loc != null) {
                        tv.setText("Cell ID: " + loc.getCid() + " , " + "Lac: "
                                + loc.getLac() + "mcc : " + mcc + "mnc : "
                                + mnc);
                        // to write it to file
                        appendData("Cell ID: " + loc.getCid() + " , " + "Lac: "
                                + loc.getLac() + "mcc : " + mcc + "mnc : "
                                + mnc);
                    }

                }

                manager.requestLocationUpdates(providerName, 1000 * 60 * 15, 0,
                        this);
            }
        }
    }

    // Find the closest Bart Station
    public String findClosestBart(Location loc) {
        double lat = loc.getLatitude();
        double lon = loc.getLongitude();

        double curStatLat = 0;
        double curStatLon = 0;
        double shortestDistSoFar = Double.POSITIVE_INFINITY;
        double curDist;
        String curStat = null;
        String closestStat = null;

        // sort through all the stations
        // write some sort of for loop using the API.

        curDist = Math.sqrt(((lat - curStatLat) * (lat - curStatLat))
                + ((lon - curStatLon) * (lon - curStatLon)));
        if (curDist < shortestDistSoFar) {
            closestStat = curStat;
        }

        return closestStat;

    }

    @Override
    public void onLocationChanged(Location location) {
        TextView tv = (TextView) findViewById(R.id.locationResults);
        if (location != null) {
            tv.setText(location.getLatitude() + " latitude, "
                    + location.getLongitude() + " longitude");
            // to write the file..
            appendData(location.getLatitude() + " latitude, "
                    + location.getLongitude() + " longitude");
        } else {
            tv.setText("Problem getting gps NETWORK ID : ");

        }
    }

1 个答案:

答案 0 :(得分:0)

几个月前我写了一个WS:

    <%@ WebService   Language="VBScript" Class="DataIns" %>

Imports System
Imports System.Web.Services
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Data 
Imports System.Globalization

<WebService(Namespace:="http://www.mysite.org/webservices/")> Public Class DataIns :Inherits WebService



<WebMethod()> Public Function devIns (ByVal dm As String) As String


    Dim strArr() As String
    Dim rtnVal As String
    strArr = dm.split("^")

    Dim connection As   SqlConnection
    Dim connection1 As  SqlConnection
    Dim connection2 As  SqlConnection
    Dim cmd As  SqlCommand 
    Dim connectionString As String
    connectionString = ConfigurationManager.ConnectionStrings("sqlsds").ConnectionString      
    connection = New SqlConnection(connectionString)   



       Dim cmdtrans As SqlCommand
       Dim cmdCheck As SqlCommand 

       Dim result as String
       Dim sqltrans as String 
       Dim notes as String
       Dim notes1 As String 

       sqltrans= "select dbo.fnCheckBlackList(@p_imei)"
       cmdtrans=new sqlcommand(sqltrans,connection)
       cmdtrans.Parameters.AddWithValue("@p_imei",strArr(0))
       Try
           connection.Open()
           notes=cmdtrans.ExecuteScalar()

       Catch ex As Exception
          notes = ex.Message
       Finally 
          connection.Close()    
       End Try  

       notes = If(IsDBNull(notes),"","") 

       if notes.Trim().Equals("TIMEUP") then  

            Context.Response.Output.Write("Save Completed Wipeout")
            Context.Response.End()
             return string.Empty
        else
            connection1 = New SqlConnection(connectionString)
            result = "select dbo.fnCheckImeiDateWise(@p_imei)"
            cmdCheck=new sqlcommand(result,connection1)
            cmdCheck.Parameters.AddWithValue("@p_imei",strArr(0))


            Try
                       connection1.Open()
                       notes1=cmdCheck.ExecuteScalar()
            Catch ex As Exception
                      notes1 = ex.Message
            Finally
                connection1.close()
            End Try 

            if notes1.Trim().Equals("FINE") then 

                connection2 = New SqlConnection(connectionString)   

                cmd = New SqlCommand("dbo.spInsertDeviceData", connection2)
                cmd.CommandType = CommandType.StoredProcedure   


                cmd.Parameters.AddWithValue("@p_imei", strArr(0))
                cmd.Parameters.AddWithValue("@p_location", strArr(1))
                cmd.Parameters.AddWithValue("@p_aic", Integer.Parse(strArr(2)))
                cmd.Parameters.AddWithValue("@p_adc", Integer.Parse(strArr(3)))
                cmd.Parameters.AddWithValue("@p_ail", strArr(4))
                cmd.Parameters.AddWithValue("@p_adl", strArr(5))
                cmd.Parameters.AddWithValue("@p_tsss", Double.Parse(strArr(6)))
                cmd.Parameters.AddWithValue("@p_ts", Double.Parse(strArr(7)))
                cmd.Parameters.AddWithValue("@p_tsgp", Double.Parse(strArr(8)))
                cmd.Parameters.AddWithValue("@p_tvpc", Double.Parse(strArr(9)))

                Try

                  connection2.Open()
                  rtnVal = cmd.ExecuteNonQuery()

                Catch ex As Exception
                  rtnVal = ex.Message

                Finally
                    connection2.Close()
                End Try
                'Context.Response.Output.Write(rtnVal)

                Dim  parameterString As String

                  Dim dow2 As String

                parameterString = ConfigurationManager.AppSettings("FREQUENCY")
                parameterString = parameterString + "|"


                parameterString = parameterString + getNewTime(ConfigurationManager.AppSettings("UPDATEAT1"))
                parameterString = parameterString + "|"
                parameterString = parameterString + ConfigurationManager.AppSettings("DAYOFWEEK1")

                dow2 = ConfigurationManager.AppSettings("DAYOFWEEK2")


                if String.IsNullOrEmpty(dow2) then 

                else

                    parameterString = parameterString +"*"
                    parameterString = parameterString + dow2

                end if  
                parameterString = parameterString + "|"
                parameterString = parameterString  + ConfigurationManager.AppSettings("DAYOFMONTH") 


                Context.Response.Output.Write("Save Completed" + "|"+  parameterString)
                Context.Response.End()
                return string.Empty  
            else
                Context.Response.Output.Write("ERROR")
                Context.Response.End()
                return string.Empty  
            End If
    End If 




end function

end class

这被称为

http://www.mysite.org/DataIns.asmx/dIns?dm=<data-separated=by-^>