0

我是android新手..我创建了一个应用程序(服务不是活动),它将用户位置发送到服务器..它在后台运行,因此应用程序对用户隐藏......我使用了异步任务(doInBackground和onPostExecute 方法)...在编码中我使用 Thread.sleep(300000) 间隔 5 分钟,但我希望这个应用程序应该在启动时运行,因为我使用了 BroadCast Receiver..但它没有运行..

签到任务:SSL error, attempting time correction:javax.net.ssl.SSLException: Not trusted server certificates

这是服务:

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // TODO Auto-generated method stub
        super.onStartCommand(intent, flags, startId);       

        Log.d("prakaash", "helllllooo");
        while(done) 
        {
            Log.i("hiiiii","hellllo");
            getLocation();
            gpsTraking();
            passing();
            try 
            {
                Thread.sleep(30000);
            }
            catch (InterruptedException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }




        return Service.START_NOT_STICKY;
    }

    @Override
    public void onCreate() {

        Log.d("YASARKHAN", "ABHISHEKRAI");
        super.onCreate();

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("distrroy","destry");

    }

    public void gpsTraking() {

        // check if GPS enabled
        if (true) {
            stAdd = "";
            double latitude = getLatitude();
            double longitude = getLongitude();
            Geocoder gc = new Geocoder(getBaseContext());
            try
            {
                List<Address> list = gc.getFromLocation(latitude, longitude, 2);
                Address a = list.get(0);
                for (int i = 0; i <= a.getMaxAddressLineIndex(); i++) {
                    stAdd = stAdd + "\n " + a.getAddressLine(i);
                }
                stAdd = stAdd + " " + a.getLocality() + "\n"
                        + a.getFeatureName();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // \n is for new line
            CharSequence d = DateFormat.format("dd-MM-yyyy hh:mm:ss",
                    new Date());
            currentTime = d.toString();
            Log.d("currentTime", currentTime);

            TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            // get IMEI
            imei = tm.getDeviceId();
            // get SimSerialNumber
            simSerialNumber = tm.getSimSerialNumber();
        }


    }


    /**
     * Function to show settings alert dialog On pressing Settings button will
     * launch Settings Options
     * */
    public void showSettingsAlert() {
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

        // Setting Dialog Title
        alertDialog.setTitle("GPS is settings");

        // Setting Dialog Message
        alertDialog
                .setMessage("GPS is not enabled. Do you want to go to settings menu?");

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

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

        // Showing Alert Message
        alertDialog.show();
    }

    @Override
    public void onLocationChanged(Location location) {
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }

    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }
    class SendFeedback extends AsyncTask<String, Void, String> 
    {
        @Override
        protected String doInBackground(String... paramArrayOfParams) 
        {
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("strIMEINumber", paramArrayOfParams[0]);
            request.addProperty("strSIMNumber", paramArrayOfParams[1]);     
            request.addProperty("strAddress", paramArrayOfParams[2]);
            request.addProperty("strTime", paramArrayOfParams[3]);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.encodingStyle = SoapSerializationEnvelope.ENC;
            envelope.setOutputSoapObject(request);
            System.setProperty("http.keepAlive", "false");

            try 
            {
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                androidHttpTransport.call(SOAP_ACTION, envelope);
                // SoapObject result = (SoapObject) envelope.getResponse();
                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                String resultData = response.toString();
                Log.d("response", resultData);
                return resultData;              
            } 
            catch (Exception e) 
            {
                Log.d("My Error", "" + e.getMessage());

            }
            return resultData;
        }

        @Override
        protected void onPostExecute(String result) 
        {
            Log.d("mayuuuur","mayureshh");
            Log.d("strResult", result);
            super.onPostExecute(result);
        }
    }
}

日志猫:

 03-15 11:37:39.761: D/AndroidRuntime(284): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
03-15 11:37:39.761: D/AndroidRuntime(284): CheckJNI is ON
03-15 11:37:39.881: D/AndroidRuntime(284): --- registering native functions ---
03-15 11:37:40.402: I/ActivityManager(58): Start proc com.android.defcontainer for service com.android.defcontainer/.DefaultContainerService: pid=290 uid=10027 gids={1015, 2001}
03-15 11:37:40.702: D/dalvikvm(290): GC_EXPLICIT freed 788 objects / 56280 bytes in 117ms
03-15 11:37:40.761: D/PackageParser(58): Scanning package: /data/app/vmdl43820.tmp
03-15 11:37:40.761: W/PackageParser(58): Unknown element under <application>: intent-filter at /data/app/vmdl43820.tmp Binary XML file line #33
03-15 11:37:40.852: D/dalvikvm(58): GC_FOR_MALLOC freed 1647 objects / 85064 bytes in 71ms
03-15 11:37:40.852: I/dalvikvm-heap(58): Grow heap (frag case) to 4.995MB for 16400-byte allocation
03-15 11:37:40.931: D/dalvikvm(58): GC_FOR_MALLOC freed 168 objects / 8904 bytes in 72ms
03-15 11:37:41.091: I/PackageManager(58): Removing non-system package:com.example.yayaa
03-15 11:37:41.091: I/ActivityManager(58): Force stopping package com.example.yayaa uid=10040
03-15 11:37:41.211: D/PackageManager(58): Scanning package com.example.yayaa
03-15 11:37:41.211: I/PackageManager(58): Package com.example.yayaa codePath changed from /data/app/com.example.yayaa-2.apk to /data/app/com.example.yayaa-1.apk; Retaining data and using new
03-15 11:37:41.221: I/PackageManager(58): /data/app/com.example.yayaa-1.apk changed; unpacking
03-15 11:37:41.232: D/installd(34): DexInv: --- BEGIN '/data/app/com.example.yayaa-1.apk' ---
03-15 11:37:41.642: D/dalvikvm(299): DexOpt: 'Lorg/kxml2/kdom/Node;' has an earlier definition; blocking out
03-15 11:37:41.652: D/dalvikvm(299): DexOpt: 'Lorg/xmlpull/v1/XmlPullParser;' has an earlier definition; blocking out
03-15 11:37:41.652: D/dalvikvm(299): DexOpt: 'Lorg/xmlpull/v1/XmlPullParserException;' has an earlier definition; blocking out
03-15 11:37:41.652: D/dalvikvm(299): DexOpt: 'Lorg/xmlpull/v1/XmlPullParserFactory;' has an earlier definition; blocking out
03-15 11:37:41.652: D/dalvikvm(299): DexOpt: 'Lorg/xmlpull/v1/XmlSerializer;' has an earlier definition; blocking out
03-15 11:37:41.671: D/dalvikvm(299): DexOpt: 'Lorg/kxml2/io/KXmlParser;' has an earlier definition; blocking out
03-15 11:37:41.682: D/dalvikvm(299): DexOpt: 'Lorg/kxml2/io/KXmlSerializer;' has an earlier definition; blocking out
03-15 11:37:41.682: D/dalvikvm(299): DexOpt: 'Lorg/kxml2/kdom/Document;' has an earlier definition; blocking out
03-15 11:37:41.682: D/dalvikvm(299): DexOpt: 'Lorg/kxml2/kdom/Element;' has an earlier definition; blocking out
03-15 11:37:42.072: I/dalvikvm(299): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-15 11:37:42.072: I/dalvikvm(299): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-15 11:37:42.081: I/dalvikvm(299): DexOpt: not resolving ambiguous class 'Lorg/kxml2/io/KXmlSerializer;'
03-15 11:37:42.081: D/dalvikvm(299): DexOpt: not verifying 'Lorg/kxml2/kdom/Node;': multiple definitions
03-15 11:37:42.091: D/dalvikvm(299): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlPullParser;': multiple definitions
03-15 11:37:42.091: D/dalvikvm(299): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlPullParserException;': multiple definitions
03-15 11:37:42.091: D/dalvikvm(299): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlPullParserFactory;': multiple definitions
03-15 11:37:42.091: D/dalvikvm(299): DexOpt: not verifying 'Lorg/xmlpull/v1/XmlSerializer;': multiple definitions
03-15 11:37:42.243: I/dalvikvm(299): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-15 11:37:42.243: I/dalvikvm(299): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-15 11:37:42.243: I/dalvikvm(299): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-15 11:37:42.251: I/dalvikvm(299): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-15 11:37:42.251: I/dalvikvm(299): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-15 11:37:42.261: I/dalvikvm(299): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParser;'
03-15 11:37:42.282: D/dalvikvm(299): DexOpt: not verifying 'Lorg/kxml2/io/KXmlParser;': multiple definitions
03-15 11:37:42.282: D/dalvikvm(299): DexOpt: not verifying 'Lorg/kxml2/io/KXmlSerializer;': multiple definitions
03-15 11:37:42.282: D/dalvikvm(299): DexOpt: not verifying 'Lorg/kxml2/kdom/Document;': multiple definitions
03-15 11:37:42.282: D/dalvikvm(299): DexOpt: not verifying 'Lorg/kxml2/kdom/Element;': multiple definitions
03-15 11:37:42.291: I/dalvikvm(299): DexOpt: not resolving ambiguous class 'Lorg/xmlpull/v1/XmlPullParserException;'
03-15 11:37:42.362: D/dalvikvm(299): DexOpt: load 159ms, verify 638ms, opt 26ms
03-15 11:37:42.392: D/installd(34): DexInv: --- END '/data/app/com.example.yayaa-1.apk' (success) ---
03-15 11:37:42.392: W/PackageManager(58): Code path for pkg : com.example.yayaa changing from /data/app/com.example.yayaa-2.apk to /data/app/com.example.yayaa-1.apk
03-15 11:37:42.402: W/PackageManager(58): Resource path for pkg : com.example.yayaa changing from /data/app/com.example.yayaa-2.apk to /data/app/com.example.yayaa-1.apk
03-15 11:37:42.402: D/PackageManager(58):   Services: com.example.yayaa.babaa
03-15 11:37:42.402: D/PackageManager(58):   Receivers: com.example.yayaa.ByReceiver
03-15 11:37:42.411: I/ActivityManager(58): Force stopping package com.example.yayaa uid=10040
03-15 11:37:42.522: I/installd(34): move /data/dalvik-cache/data@app@com.example.yayaa-1.apk@classes.dex -> /data/dalvik-cache/data@app@com.example.yayaa-1.apk@classes.dex
03-15 11:37:42.532: D/PackageManager(58): New package installed in /data/app/com.example.yayaa-1.apk
03-15 11:37:42.532: W/PackageManager(58): Unknown permission android.intent.action.USER_PRESENT in package com.example.yayaa
03-15 11:37:42.652: I/ActivityManager(58): Force stopping package com.example.yayaa uid=10040
03-15 11:37:42.751: I/ActivityManager(58): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=300 uid=10010 gids={}
03-15 11:37:42.841: W/RecognitionManagerService(58): no available voice recognition services found
03-15 11:37:43.032: D/dalvikvm(58): GC_FOR_MALLOC freed 5455 objects / 375128 bytes in 180ms
03-15 11:37:43.182: D/dalvikvm(58): GC_EXPLICIT freed 618 objects / 32776 bytes in 150ms
03-15 11:37:43.182: I/installd(34): unlink /data/dalvik-cache/data@app@com.example.yayaa-2.apk@classes.dex
03-15 11:37:43.201: D/AndroidRuntime(284): Shutting down VM
03-15 11:37:43.243: D/dalvikvm(284): Debugger has detached; object registry had 1 entries
03-15 11:37:43.312: I/ActivityThread(300): Publishing provider com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider
03-15 11:37:43.862: D/dalvikvm(152): GC_FOR_MALLOC freed 3958 objects / 239232 bytes in 59ms
03-15 11:37:48.602: D/dalvikvm(246): GC_EXPLICIT freed 1948 objects / 141368 bytes in 126ms
03-15 11:37:51.301: D/KeyguardViewMediator(58): pokeWakelock(5000)
03-15 11:37:51.541: D/KeyguardViewMediator(58): pokeWakelock(5000)
03-15 11:37:53.581: D/KeyguardViewMediator(58): pokeWakelock(5000)
03-15 11:37:53.951: D/KeyguardViewMediator(58): pokeWakelock(5000)
03-15 11:37:54.111: I/ARMAssembler(58): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x34ba58:0x34bc20] in 1018044 ns
03-15 11:39:30.771: I/CheckinService(169): Preparing to send checkin request
03-15 11:39:30.771: I/EventLogService(169): Accumulating logs since 1363327374579
03-15 11:39:30.891: V/CheckinRequestBuilder(169): pre-froyo android id is 0
03-15 11:39:31.052: I/CheckinTask(169): Sending checkin request (1372 bytes)
03-15 11:39:32.141: E/CheckinTask(169): SSL error, attempting time correction: javax.net.ssl.SSLException: Not trusted server certificate
03-15 11:39:32.632: I/CheckinTask(169): Server time agrees: delta 389 msec
03-15 11:39:32.702: D/NativeCrypto(169): Freeing OpenSSL session
03-15 11:39:32.702: D/dalvikvm(169): GC_FOR_MALLOC freed 4789 objects / 513296 bytes in 61ms
03-15 11:39:32.722: E/CheckinTask(169): Checkin failed: https://android.clients.google.com/checkin (request #0)
03-15 11:39:32.722: E/CheckinTask(169): javax.net.ssl.SSLException: Not trusted server certificate
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:371)
03-15 11:39:32.722: E/CheckinTask(169):     at android.net.SSLCertificateSocketFactory.verifyHostname(SSLCertificateSocketFactory.java:199)
03-15 11:39:32.722: E/CheckinTask(169):     at android.net.SSLCertificateSocketFactory.createSocket(SSLCertificateSocketFactory.java:256)
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:375)
03-15 11:39:32.722: E/CheckinTask(169):     at com.google.android.common.http.GoogleHttpClient$WrappedLayeredSocketFactory.createSocket(GoogleHttpClient.java:160)
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:164)
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
03-15 11:39:32.722: E/CheckinTask(169):     at android.net.http.AndroidHttpClient.execute(AndroidHttpClient.java:248)
03-15 11:39:32.722: E/CheckinTask(169):     at com.google.android.common.http.GoogleHttpClient.executeWithoutRewriting(GoogleHttpClient.java:203)
03-15 11:39:32.722: E/CheckinTask(169):     at com.google.android.common.http.GoogleHttpClient.execute(GoogleHttpClient.java:245)
03-15 11:39:32.722: E/CheckinTask(169):     at com.google.android.common.http.GoogleHttpClient.execute(GoogleHttpClient.java:313)
03-15 11:39:32.722: E/CheckinTask(169):     at com.google.android.gsf.checkin.CheckinTask.sendRequest(CheckinTask.java:239)
03-15 11:39:32.722: E/CheckinTask(169):     at com.google.android.gsf.checkin.CheckinTask.doInBackground(CheckinTask.java:146)
03-15 11:39:32.722: E/CheckinTask(169):     at com.google.android.gsf.checkin.CheckinService$1.doInBackground(CheckinService.java:221)
03-15 11:39:32.722: E/CheckinTask(169):     at com.google.android.gsf.checkin.CheckinService$1.doInBackground(CheckinService.java:228)
03-15 11:39:32.722: E/CheckinTask(169):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-15 11:39:32.722: E/CheckinTask(169):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-15 11:39:32.722: E/CheckinTask(169):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-15 11:39:32.722: E/CheckinTask(169):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
03-15 11:39:32.722: E/CheckinTask(169):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
03-15 11:39:32.722: E/CheckinTask(169):     at java.lang.Thread.run(Thread.java:1096)
03-15 11:39:32.722: E/CheckinTask(169): Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:168)
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:366)
03-15 11:39:32.722: E/CheckinTask(169):     ... 24 more
03-15 11:39:32.722: E/CheckinTask(169): Caused by: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
03-15 11:39:32.722: E/CheckinTask(169):     at org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:149)
03-15 11:39:32.722: E/CheckinTask(169):     at java.security.cert.CertPathValidator.validate(CertPathValidator.java:202)
03-15 11:39:32.722: E/CheckinTask(169):     at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:164)
03-15 11:39:32.722: E/CheckinTask(169):     ... 25 more
03-15 11:40:55.501: D/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
4

1 回答 1

1

查看 logcat 异常堆栈跟踪时,原因通常在“由:”字段中。

在这里,它是由以下原因引起的:

Caused by: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found

您可能需要为您的 http 请求设置自定义信任管理器,如这篇非常好的帖子所示:

通过 HTTPS 使用 HttpClient 信任所有证书

于 2013-03-14T12:10:11.010 回答