Android 5.0 (L)报错 Service Intent must be explicit

文章标签: android5.0
2014-12-3 18:21:02     人阅读    

升级到android 5.0后运行我的app出现了如下错误 Service Intent must be explicit: Intent,有点看不明白.....在小于5版本中正常运行

10-23 10:18:18.945: E/AndroidRuntime(8987): java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.gms.analytics.service.START (has extras) }


代码在4.4.4或者更低的 版本中运行的很好,换成android 5.0就这样了,该如何处理?不太明白为啥会出现
 java.lang.IllegalArgumentException: Service Intent must be explicit in regard to Android 5.0
我的Manifest文件如下

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxxxx.android.phone.xxxxx"
    android:versionCode="3"
    android:versionName="v1.2.4065" >

    <uses-sdk android:minSdkVersion="12"
        android:targetSdkVersion="21" />

    <!-- Google Analytics 验证需要-->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <permission android:name="xxxxx.android.phone.xxxxx.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="xxxxx.android.phone.xxxxx.permission.C2D_MESSAGE" />
    <!-- App 接收 GCM 消息. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <!-- GCM 链接Google Services. -->
    <uses-permission android:name="android.permission.INTERNET" /> 
    <!-- GCM 需要 Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.GET_TASKS" />

    <!-- 缓存-->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />



    <supports-screens
        android:resizeable="true"
        android:smallScreens="false"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"
        android:anyDensity="true" /

    <application
        android:name="xxxxx.xxxxxApplication"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:allowBackup="true"
        android:largeHeap="true" >
        <receiver 
            android:name="com.google.android.gcm.GCMBroadcastReceiver" 
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="xxxxx.android.phone.xxxxx" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="xxxxx.android.phone.xxxxx" />
            </intent-filter>
        </receiver>

        <receiver 
            android:name="xxxxx.ConnectivityReceiver"
            android:enabled="false" >
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>

        <activity 
            android:name=".SplashActivity"
            android:configChanges="locale|orientation" 
            android:theme="@style/Theme.Splash"
            android:screenOrientation="portrait"
            android:noHistory="true" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:label="@string/app_name"
            android:theme="@style/Theme"
            android:windowSoftInputMode="adjustPan|stateVisible"
            android:name=".LoginActivity"
            android:configChanges="locale|orientation|screenSize" 
            android:screenOrientation="portrait" >
        </activity>
        <activity 
            android:name=".MainActivity" 
            android:theme="@style/Theme"
            android:configChanges="locale|orientation|screenSize" 
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan|stateVisible" />

        <activity 
            android:name=".CountryPickerActivity" 
            android:theme="@style/Theme.Floating"
            android:configChanges="locale|orientation|screenSize" 
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan|stateVisible" />
        <activity 
            android:name=".EventPickerActivity" 
            android:theme="@style/Theme.Floating"
            android:configChanges="locale|orientation|screenSize" 
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustPan|stateVisible" />
        <activity 
            android:name=".TutorialActivity"
            android:theme="@style/Theme.Transparent"
            android:configChanges="locale|orientation|screenSize"
            android:screenOrientation="portrait" />

        <activity 
            android:name=".VideoPlayerActivity" 
            android:theme="@style/Theme"
            android:configChanges="orientation|screenSize" />

        <service android:name=".GCMIntentService" android:enabled="true" />
        <meta-data android:name="com.crashlytics.ApiKey" android:value="xxxxxxxxxxxxxxxx"/>
    </application>
</manifest>


我的 GCMIntentService.java如喜爱

public class GCMIntentService extends GCMBaseIntentService {

private static final int ATTEMPTS_MAX = 3;

final static boolean USE_DEV = false;

final static String XXXXX = "https://xxxxx/api.php";

final static String XXXXX = "http://dev.xxxxx/api.php";

final static String SUBSCRIPTION_KEY = "xxxxxxxxxxxxxxx"; //app中唯一的key

    public GCMIntentService() {
        super(xxxxxx.SENDER_ID);
        if(GCMIntentService.USE_DEV) {
            host = XXXXX;
        } else {
            host = XXXXX;
        }
    }

    ...



}
}

更多更详细的错误如下,看起来是 analytics 出现了问题》

10-23 13:17:08.095: E/AndroidRuntime(10560): FATAL EXCEPTION: GAThread
10-23 13:17:08.095: E/AndroidRuntime(10560): Process: xxxxx.android.phone.xxxxx, PID: 10560
10-23 13:17:08.095: E/AndroidRuntime(10560): java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.gms.analytics.service.START (has extras) }

最终经过半天的定位终于解决了这个问题:

问题出在 Google Analytics  ,随着android版本升级到android 5.0  Google Analytics 也从v2  升级到了v3了,需要把Google Analytics  升级到V3来解决这个问题


原文地址:http://www.itmmd.com/201412/250.html
该文章由 萌萌的IT人 整理发布,转载须标明出处。

android 5.0中 Toolbar widget的xml配置信息在哪里定义?   上一篇
下一篇  Android 5.0 android:elevation 如果给button设置效果
精彩回复
#1楼    ; [评论人]:张章的小路   [发表时间]:2015-1-22 11:35:45

android 5.0 Google Analytics 也从v2 升级到了v3,这个地方如何升级?新手不太会

#1楼    ; [评论人]:沐风   [发表时间]:2015-1-22 11:35:15

不错,解决了我的问题,谢谢分享

我要追加问题,请求站长解决!
姓名:       

《程序员app》专门为程序员量身定做!