相关疑难解决方法(0)

Android 5.0(L)Service Intent必须在Google Analytics中明确

我的代码工作在<5但在Android 5.0中我遇到了一个我不太明白的问题.

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) }
Run Code Online (Sandbox Code Playgroud)

即使是现在,我的代码也适用于4.4.4及以下版本.那么我需要做什么?我将在下面发布相关代码.此外,在我的谷歌搜索期间,我发现这篇关于java.lang.IllegalArgumentException的帖子:服务意图必须是关于Android 5.0的显式,但我不明白它的含义.

表现

<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" />

    <!-- Required for Google Analytics -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- For push notifications (GCM) -->
    <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 receives GCM messages. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <!-- GCM connects to Google Services. -->
    <uses-permission android:name="android.permission.INTERNET" /> 
    <!-- GCM requires a Google account. --> …
Run Code Online (Sandbox Code Playgroud)

illegalargumentexception android-5.0-lollipop

68
推荐指数
5
解决办法
5万
查看次数

Android L (API 21) - java.lang.IllegalArgumentException:服务意图必须是显式的

Android 新版本 - “Lollipop”(API 21)带来了很多变化,但如果您希望将您的应用程序定位到该 API,它会付出一些代价。

当我们开始让我们的应用程序适应新的 API 时,我们遇到的第一个问题是 IllegalArgumentException: Service Intent must be explicit

如果您遇到了该问题,并且您实际上打算以显式方式使用您的意图(这意味着在启动服务时您希望恰好命中 1 个服务操作),那么这里有一个快速解决方法来转换隐式 --> 显式:

public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
        // Retrieve all services that can match the given intent
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);

        // Make sure only one match was found
        if (resolveInfo == null || resolveInfo.size() != 1) {
            return null;
        }

        // Get component info and create ComponentName
        ResolveInfo serviceInfo = resolveInfo.get(0);
        String packageName …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-service android-5.0-lollipop

3
推荐指数
1
解决办法
3081
查看次数