[求助]使用百度定位API结果导致应用无法启动

dummyfork 2016-03-26 05:26:46
我下载了百度定位API,但是在使用中,按照DEMO在Android Studio中也做了个(appkey也申请了),通过调试模式在手机中启动发现应用无法启动,也没有确切的错误信息,只有connected ...的消息。
如下图:


monitor中显示的消息如下:
03-26 17:19:44.593 20711-20711/? D/dalvikvm: Late-enabling CheckJNI
03-26 17:19:44.663 20711-20711/com.example.helloworld W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
03-26 17:19:44.663 20711-20711/com.example.helloworld I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
03-26 17:19:44.663 20711-20711/com.example.helloworld W/dalvikvm: VFY: unable to resolve interface method 19074: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
03-26 17:19:44.663 20711-20711/com.example.helloworld D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
03-26 17:19:44.663 20711-20711/com.example.helloworld I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
03-26 17:19:44.663 20711-20711/com.example.helloworld W/dalvikvm: VFY: unable to resolve interface method 19078: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
03-26 17:19:44.663 20711-20711/com.example.helloworld D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
03-26 17:19:44.683 20711-20711/com.example.helloworld D/dalvikvm: GetMethodID: not returning static method Landroid/os/Process;.getTotalMemory ()J
03-26 17:19:44.683 20711-20711/com.example.helloworld D/dalvikvm: GetMethodID: not returning static method Landroid/os/Process;.getFreeMemory ()J
03-26 17:19:44.743 20711-20711/com.example.helloworld W/DeviceId: galaxy lib host missing meta-data,make sure you know the right way to integrate galaxy
03-26 17:19:44.743 20711-20711/com.example.helloworld W/DeviceId: galaxy lib host missing meta-data,make sure you know the right way to integrate galaxy
03-26 17:19:44.743 20711-20711/com.example.helloworld W/DeviceId: galaxy lib host missing meta-data,make sure you know the right way to integrate galaxy
03-26 17:19:44.793 20711-20711/com.example.helloworld I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.2.2.1_RB1.04.04.04.090.052_msm8974_LNX.LA.3.5.2.2.1_RB1__release_AU ()
03-26 17:19:44.793 20711-20711/com.example.helloworld I/Adreno-EGL: OpenGL ES Shader Compiler Version: E031.24.00.15
03-26 17:19:44.793 20711-20711/com.example.helloworld I/Adreno-EGL: Build Date: 07/01/15 Wed
03-26 17:19:44.793 20711-20711/com.example.helloworld I/Adreno-EGL: Local Branch: mybranch11515920
03-26 17:19:44.793 20711-20711/com.example.helloworld I/Adreno-EGL: Remote Branch: quic/LNX.LA.3.5.2.2.1_rb1
03-26 17:19:44.793 20711-20711/com.example.helloworld I/Adreno-EGL: Local Patches: NONE
03-26 17:19:44.793 20711-20711/com.example.helloworld I/Adreno-EGL: Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.2.2.1_RB1.04.04.04.090.052 + NOTHING
03-26 17:19:44.823 20711-20711/com.example.helloworld D/OpenGLRenderer: Enabling debug mode 0
03-26 17:19:44.873 20711-20711/com.example.helloworld D/baidu_location_client: baidu location connected ...
03-26 17:19:44.873 20711-20711/com.example.helloworld I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@431c96b0 time:357008167

代码如下:

package com.example.helloworld;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.BDNotifyListener;//假如用到位置提醒功能,需要import该类
import com.baidu.location.Poi;

public class MainActivity extends AppCompatActivity {
public LocationClient mLocationClient = null;

private TextView textview;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview = (TextView)findViewById(R.id.textView_1);

}

@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
// -----------location config ------------

mLocationClient = new LocationClient(getApplicationContext()); //声明LocationClient类
setLocationOption();
mLocationClient.registerLocationListener(mListener); //注册监听函数

mLocationClient.start();
}

private BDLocationListener mListener = new BDLocationListener() {

@Override
public void onReceiveLocation(BDLocation location) {
// TODO Auto-generated method stub
if (location == null)
{
Log.e("MainActivity", "Location is null");
return ;
}
Log.e("MainActivity", "Location已经传入");
StringBuffer sb = new StringBuffer(256);
sb.append("time : ");
sb.append(location.getTime());
sb.append("\nerror code : ");
sb.append(location.getLocType());
sb.append("\nlatitude : ");
sb.append(location.getLatitude());
sb.append("\nlontitude : ");
sb.append(location.getLongitude());
sb.append("\nradius : ");
sb.append(location.getRadius());
sb.append("\nCountryCode : ");
sb.append(location.getCountryCode());
sb.append("\nCountry : ");
sb.append(location.getCountry());
sb.append("\ncitycode : ");
sb.append(location.getCityCode());
sb.append("\ncity : ");
sb.append(location.getCity());
sb.append("\nDistrict : ");
sb.append(location.getDistrict());
sb.append("\nStreet : ");
sb.append(location.getStreet());
sb.append("\naddr : ");
sb.append(location.getAddrStr());
sb.append("\nDescribe: ");
sb.append(location.getLocationDescribe());
if (location.getLocType() == BDLocation.TypeGpsLocation){
sb.append("\nspeed : ");
sb.append(location.getSpeed());
sb.append("\nsatellite : ");
sb.append(location.getSatelliteNumber());
sb.append("\nheight : ");
sb.append(location.getAltitude());// 单位:米
sb.append("\ndescribe : ");
sb.append("gps定位成功");
} else if (location.getLocType() == BDLocation.TypeNetWorkLocation){
// 运营商信息
sb.append("\naddr : ");
sb.append(location.getAddrStr());
sb.append("\noperationers : ");
sb.append(location.getOperators());
sb.append("\ndescribe : ");
sb.append("网络定位成功");
}
else if (location.getLocType() == BDLocation.TypeOffLineLocation) {// 离线定位结果
sb.append("\ndescribe : ");
sb.append("离线定位成功,离线定位结果也是有效的");
} else if (location.getLocType() == BDLocation.TypeServerError) {
sb.append("\ndescribe : ");
sb.append("服务端网络定位失败,可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com,会有人追查原因");
} else if (location.getLocType() == BDLocation.TypeNetWorkException) {
sb.append("\ndescribe : ");
sb.append("网络不同导致定位失败,请检查网络是否通畅");
} else if (location.getLocType() == BDLocation.TypeCriteriaException) {
sb.append("\ndescribe : ");
sb.append("无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
}

textview.setText(sb.toString());
}
};

public void setLocationOption(){
LocationClientOption option = new LocationClientOption();
option = new LocationClientOption();
//option.setLocationMode(LocationMode.Hight_Accuracy);//可选,默认高精度,设置定位模式,高精度,低功耗,仅设备
option.setCoorType("bd09ll");//可选,默认gcj02,设置返回的定位结果坐标系,如果配合百度地图使用,建议设置为bd09ll;
option.setScanSpan(3000);//可选,默认0,即仅定位一次,设置发起定位请求的间隔需要大于等于1000ms才是有效的
option.setIsNeedAddress(true);//可选,设置是否需要地址信息,默认不需要
option.setIsNeedLocationDescribe(true);//可选,设置是否需要地址描述
option.setNeedDeviceDirect(false);//可选,设置是否需要设备方向结果
option.setLocationNotify(false);//可选,默认false,设置是否当gps有效时按照1S1次频率输出GPS结果
option.setIgnoreKillProcess(true);//可选,默认true,定位SDK内部是一个SERVICE,并放到了独立进程,设置是否在stop的时候杀死这个进程,默认不杀死
option.setIsNeedLocationDescribe(true);//可选,默认false,设置是否需要位置语义化结果,可以在BDLocation.getLocationDescribe里得到,结果类似于“在北京天安门附近”
option.setIsNeedLocationPoiList(true);//可选,默认false,设置是否需要POI结果,可以在BDLocation.getPoiList里得到
option.SetIgnoreCacheException(false);//可选,默认false,设置是否收集CRASH信息,默认收集
mLocationClient.setLocOption(option);
}

@Override
protected void onDestroy() {
super.onDestroy();
if (mLocationClient != null && mLocationClient.isStarted()) {
mLocationClient.stop();
mLocationClient.unRegisterLocationListener(mListener); //注销掉监听
mLocationClient = null;
}
}

@Override
protected void onStop() {
mLocationClient.stop();//停止定位sdk
mLocationClient.unRegisterLocationListener(mListener); //注销掉监听
super.onStop();
}
}


不清楚哪里出了问题,请各位大神们 帮我看看有什么问题没? 为什么显示connected ... 还是无法正常显示结果呢?
...全文
1761 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dummyfork 2016-03-29
  • 打赏
  • 举报
回复
谢谢大家,我知道什么原因了。 我吧权限写在了<application标签中了, 应该是在<manifest 下面。
dummyfork 2016-03-29
  • 打赏
  • 举报
回复
引用 7 楼 qq_14932665的回复:
签名后在调用试试
签名了,生成了apk,也不行
qq_14932665 2016-03-28
  • 打赏
  • 举报
回复
签名后在调用试试
dummyfork 2016-03-28
  • 打赏
  • 举报
回复
我删除了那个权限之后,启动应用,logcat消息如下: 03-28 20:46:42.278 21410-21410/? D/dalvikvm: Late-enabling CheckJNI 03-28 20:46:42.458 21410-21410/com.example.helloworld W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;) 03-28 20:46:42.458 21410-21410/com.example.helloworld I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested 03-28 20:46:42.458 21410-21410/com.example.helloworld W/dalvikvm: VFY: unable to resolve interface method 18971: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z 03-28 20:46:42.458 21410-21410/com.example.helloworld D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 03-28 20:46:42.458 21410-21410/com.example.helloworld I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode 03-28 20:46:42.458 21410-21410/com.example.helloworld W/dalvikvm: VFY: unable to resolve interface method 18975: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode; 03-28 20:46:42.458 21410-21410/com.example.helloworld D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002 03-28 20:46:42.468 21410-21410/com.example.helloworld D/dalvikvm: GetMethodID: not returning static method Landroid/os/Process;.getTotalMemory ()J 03-28 20:46:42.468 21410-21410/com.example.helloworld D/dalvikvm: GetMethodID: not returning static method Landroid/os/Process;.getFreeMemory ()J 03-28 20:46:42.518 21410-21410/com.example.helloworld W/DeviceId: galaxy lib host missing meta-data,make sure you know the right way to integrate galaxy 03-28 20:46:42.518 21410-21410/com.example.helloworld W/DeviceId: galaxy lib host missing meta-data,make sure you know the right way to integrate galaxy 03-28 20:46:42.518 21410-21410/com.example.helloworld W/DeviceId: galaxy lib host missing meta-data,make sure you know the right way to integrate galaxy 03-28 20:46:42.528 21410-21438/com.example.helloworld D/dalvikvm: Trying to load lib /data/app-lib/com.example.helloworld-1/liblocSDK6a.so 0x42f5e9e0 03-28 20:46:42.528 21410-21438/com.example.helloworld D/dalvikvm: Added shared lib /data/app-lib/com.example.helloworld-1/liblocSDK6a.so 0x42f5e9e0 03-28 20:46:42.528 21410-21438/com.example.helloworld D/dalvikvm: No JNI_OnLoad found in /data/app-lib/com.example.helloworld-1/liblocSDK6a.so 0x42f5e9e0, skipping init 03-28 20:46:42.528 21410-21438/com.example.helloworld W/dalvikvm: threadid=12: thread exiting with uncaught exception (group=0x41cdfd58) 03-28 20:46:42.528 21410-21438/com.example.helloworld E/AndroidRuntime: FATAL EXCEPTION: Thread-7960 Process: com.example.helloworld, PID: 21410 java.lang.NullPointerException at com.baidu.location.h.a.b(Unknown Source) at com.baidu.location.a.b$c.a(Unknown Source) at com.baidu.location.h.f$2.run(Unknown Source) 03-28 20:46:42.538 21410-21410/com.example.helloworld I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.2.2.1_RB1.04.04.04.090.052_msm8974_LNX.LA.3.5.2.2.1_RB1__release_AU () OpenGL ES Shader Compiler Version: E031.24.00.15 Build Date: 07/01/15 Wed Local Branch: mybranch11515920 Remote Branch: quic/LNX.LA.3.5.2.2.1_rb1 Local Patches: NONE Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.2.2.1_RB1.04.04.04.090.052 + NOTHING 03-28 20:46:42.568 21410-21410/com.example.helloworld D/OpenGLRenderer: Enabling debug mode 0 不知道和“No JNI_OnLoad found ...” 有没有关系、、 这个要如何解决?
dummyfork 2016-03-28
  • 打赏
  • 举报
回复
引用 3 楼 yiy91 的回复:
我删除了android.permission.BAIDU_LOCATION_SERVICE,还是一样,没有改善,应用一样无法运行,你可以吗?
dummyfork 2016-03-28
  • 打赏
  • 举报
回复
引用 2 楼 yiy91 的回复:
你用的哪个版本 ?
Android 定位SDK v6.2.3
yiy91 2016-03-28
  • 打赏
  • 举报
回复
yiy91 2016-03-28
  • 打赏
  • 举报
回复
你用的哪个版本 ?
dummyfork 2016-03-26
  • 打赏
  • 举报
回复
AndroidMainfest.xml也都按照百度开发环境中写的设置了

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.helloworld" >
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity" android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            android:name="com.baidu.lbsapi.API_KEY"
            android:value="rgbYTFMMV7************" />
        <service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote"
            android:permission="android.permission.BAIDU_LOCATION_SERVICE">
            <intent-filter>
                <action android:name="com.baidu.location.service_v2.6"></action>
            </intent-filter>
        </service>
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
        <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
        <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
    </application>
</manifest>

80,492

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧