我正在创建实现LocationListener的MainActivity类,使用FusedLocationApi来获取当前位置的GooglePlayServicesClient。它向我展示了一些奇怪的错误,但不会崩溃我的应用程序,但功能不起作用。我正在放置Log.i()来检查控件是否进入重写的方法,但似乎控件不进入这些方法。下面是代码和输出。请帮忙
public class MainActivity extends FragmentActivity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener, com.google.android.gms.location.LocationListener,android.view.View.OnClickListener
{
private LocationClient mGetLocationLocationClient;
private LocationRequest mGetLocationLocationRequest;
private Location mGetLocationcurrentLocation;
startBtn.setOnClickListener(this);
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Log.i("in onStart", "yes..");
mGetLocationLocationClient.connect();
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
Log.i("in onLocationChanged", "Yes..");
}
@Override
public void onConnectionFailed(ConnectionResult result) {
// TODO Auto-generated method stub
Log.i("connectionFailed", "yes...shit");
}
@Override
public void onConnected(Bundle connectionHint) {
// TODO Auto-generated method stub
Log.i("in onConnected", "yes..here");
/*
* mGetLocationLocationRequest = LocationRequest.create();
* mGetLocationLocationRequest
* .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
* mGetLocationLocationRequest.setInterval(50);
* mGetLocationLocationClient
* .requestLocationUpdates(mGetLocationLocationRequest, this);
*/
}
@Override
public void onDisconnected() {
// TODO Auto-generated method stub
Log.i("in onDisconnected", "yes..here");
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("in btnClick", "yes..");
if (ok == GooglePlayServicesUtil.isGooglePlayServicesAvailable(this)) {
Log.i("In googpleplayservice", "Available..");
mGetLocationLocationClient = new LocationClient(this, this, this);
mGetLocationLocationClient.connect();
// mGetLocationcurrentLocation =
// mGetLocationLocationClient.getLastLocation();
} else
// Toast.makeText(getApplicationContext(), "Not..available",
// Toast.LENGTH_SHORT).show();
mGetLocationLocationClient.disconnect();
}
这是我的logcat输出:
02-23 04:36:06.351: E/Icing(806): Couldn't handle android.intent.action.PACKAGE_ADDED intent due to initialization failure.
02-23 04:36:06.401: E/Icing(806): Couldn't handle android.intent.action.PACKAGE_REPLACED intent due to initialization failure.
02-23 04:37:30.691: D/PackageBroadcastService(806): Received broadcast action=android.intent.action.PACKAGE_REMOVED and uri=com.example.pedometer
02-23 04:37:31.001: E/Icing(806): Couldn't handle android.intent.action.PACKAGE_REMOVED intent due to initialization failure.
02-23 04:37:31.361: D/PackageBroadcastService(806): Received broadcast action=android.intent.action.PACKAGE_ADDED and uri=com.example.pedometer
02-23 04:37:31.711: D/PackageBroadcastService(806): Received broadcast action=android.intent.action.PACKAGE_REPLACED and uri=com.example.pedometer
02-23 04:37:31.761: E/Icing(806): Couldn't handle android.intent.action.PACKAGE_ADDED intent due to initialization failure.
02-23 04:37:31.781: I/PeopleContactsSync(806): CP2 sync disabled
02-23 04:37:32.341: I/PeopleContactsSync(806): CP2 sync disabled
02-23 04:37:32.411: E/Icing(806): Couldn't handle android.intent.action.PACKAGE_REPLACED intent due to initialization failure.
我不明白为什么它表现出意图问题,我从未使用它。 请任何人帮助我,我读了很多帖子,但没有找到任何答案。
提前致谢
My Manifest FIle
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pedometer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18"
/>
<!-- ACCESS_COURSE_LOCATION FOR RETREIVING LOCATION THROUGH WIFI AND CELL TOWERS
ACCESS_FINE_LOCATION FOR RETREIVING LOCATION THROUGH GPS,WIFI,CELL TOWERS -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme"
>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name="com.example.pedometer.MainActivity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
</intent-filter>
</activity>
<activity
android:name="com.example.pedometer.GetLocation"
android:label="@string/app_name"
/>
</application>
</manifest>
答案 0 :(得分:1)
您的MainActivity
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
</intent-filter>
这是为什么?这是一个广播Intent,与Activity
无关。如果你想收听这个广播的意图,你需要在BroadcastReceiver
。
请删除此内容。