0

当我使用动态快捷方式时,出现异常:</p>

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.waterbottle.v1/com.waterbottle.v1.NovaMainActivity}: java.lang.IllegalStateException: Launcher activity not found for package com.waterbottle.v1
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalStateException: Launcher activity not found for package com.waterbottle.v1
at android.os.Parcel.readException(Parcel.java:1692)
at android.os.Parcel.readException(Parcel.java:1637)
at android.content.pm.IShortcutService$Stub$Proxy.setDynamicShortcuts(IShortcutService.java:356)
at android.content.pm.ShortcutManager.setDynamicShortcuts(ShortcutManager.java:495)
at com.waterbottle.main.guide.MainActivity.createShortcut(MainActivity.java:392)
at com.waterbottle.main.guide.MainActivity.onCreate(MainActivity.java:348)
at com.waterbottle.v1.NovaMainActivity.onCreate(NovaMainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6119) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

这是我的代码:

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("waterbottle://needreview"));

        ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
        ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "addReview")
                .setShortLabel("Add review")
                .setLongLabel("Add review")
                .setIcon(Icon.createWithResource(getApplicationContext(), R.drawable.comments))
                .setIntent(intent)
                .build();
        ArrayList<ShortcutInfo> shortcutInfos = new ArrayList<>();
        shortcutInfos.add(shortcut);
        shortcutManager.addDynamicShortcuts(shortcutInfos);
    }

我把它放在我的 MainActivity onCreate();

这是 ShortcutManager.java 代码:

/**
 * Publish the list of shortcuts.  All existing dynamic shortcuts from the caller app
 * will be replaced.  If there are already pinned shortcuts with the same IDs,
 * the mutable pinned shortcuts are updated.
 *
 * <p>This API will be rate-limited.
 *
 * @return {@code true} if the call has succeeded. {@code false} if the call is rate-limited.
 *
 * @throws IllegalArgumentException if {@link #getMaxShortcutCountPerActivity()} is exceeded,
 * or when trying to update immutable shortcuts.
 *
 * @throws IllegalStateException when the user is locked.
 */
public boolean setDynamicShortcuts(@NonNull List<ShortcutInfo> shortcutInfoList) {
    try {
        return mService.setDynamicShortcuts(mContext.getPackageName(),
                new ParceledListSlice(shortcutInfoList), injectMyUserId());
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}

我不知道什么是“用户被锁定时的 IllegalStateException”。方法。

这是我的整个清单文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.waterbottle.main">
    <uses-permission xmlns:tools="http://schemas.android.com/tools"
        android:name="android.permission.PACKAGE_USAGE_STATS"
        tools:ignore="ProtectedPermissions" />
    <application>
        <activity
            android:name="com.waterbottle.main.guide.SplashScreenActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/dpapp_name"
            android:screenOrientation="nosensor"
            android:theme="@style/Theme.WaterbottleNoTitle.SplashBackground">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.BROWSABLE" />
            </intent-filter>
            <meta-data android:name="android.app.shortcuts"
                android:resource="@xml/shortcuts" />
        </activity>  
        <activity
            android:name="com.waterbottle.main.guide.MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:screenOrientation="nosensor"
            android:windowSoftInputMode="adjustNothing">

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="home"
                    android:scheme="waterbottle" />
            </intent-filter>
        </activity>  
        <activity
            android:name="com.waterbottle.ugc.review.ui.NeedReviewActivity"
            android:launchMode="singleTop"
            android:screenOrientation="nosensor"
            android:windowSoftInputMode="stateHidden|adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data
                    android:host="recommenddealreview"
                    android:scheme="waterbottle" />
                <data
                    android:host="needreview"
                    android:scheme="waterbottle" />
            </intent-filter>
        </activity>    
        <activity
            android:name="com.waterbottle.main.city.CityListPickerActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="selectcity"
                    android:scheme="waterbottle" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/city_searchable" />
            <meta-data
                android:name="android.app.default_searchable"
                android:value="com.waterbottle.city.CityListActivity" />
        </activity>
        <activity
            android:name="com.waterbottle.main.city.CityListSwitchActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="switchcity"
                    android:scheme="waterbottle" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/city_searchable" />
            <meta-data
                android:name="android.app.default_searchable"
                android:value="com.waterbottle.city.CityListActivity" />
        </activity>
        <activity
            android:name="com.waterbottle.main.home.UserCodeActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:launchMode="singleTask"
            android:screenOrientation="nosensor"
            android:windowSoftInputMode="stateHidden|adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="usercode"
                    android:scheme="waterbottle" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.waterbottle.main.login.nativelogin.LoginActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor"
            android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data
                    android:host="login"
                    android:scheme="waterbottle" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.waterbottle.main.login.nativelogin.FastLoginActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data
                    android:host="fastlogin"
                    android:scheme="waterbottle" />
                <data
                    android:host="sublogin"
                    android:scheme="waterbottle" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.waterbottle.main.login.nativelogin.SignupActivity"
            android:configChanges="orientation|keyboardHidden|keyboard"
            android:screenOrientation="nosensor">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="signup"
                    android:scheme="waterbottle" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.waterbottle.main.login.nativelogin.LoginWebActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="nosensor">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />

                <data
                    android:host="loginweb"
                    android:scheme="waterbottle" />
            </intent-filter>
        </activity>

        <service android:name=".guide.SplashDownloadIntentService" />
        <service
            android:name="com.waterbottle.main.accessibilityservice.NovaAccessibilityService"
            android:enabled="true"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
            <intent-filter>
                <action android:name="android.accessibilityservice.AccessibilityService" />
            </intent-filter>

            <meta-data
                android:name="android.accessibilityservice"
                android:resource="@xml/accessibility_service_config" />
        </service>

    </application>

</manifest>
4

1 回答 1

1

应用快捷方式需要这一权限:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

在应用程序快捷方式上设置任何意图操作时...

任何活动<intent-filter>Manifest.xml需要对其进行过滤:

Intent.ACTION_MAIN要求:

<action android:name="android.intent.action.MAIN"/>

Intent.ACTION_DEFAULT要求:

<action android:name="android.intent.action.DEFAULT"/>

Intent.ACTION_VIEW要求:

<action android:name="android.intent.action.VIEW"/>

@see意图和意图过滤器,<意图过滤器>,ShortcutManager

于 2017-01-30T08:37:24.033 回答