繁体   English   中英

主屏幕快捷方式应用没有安装

[英]Home screen shortcut app no installed

我找到了在主屏幕上创建快捷方式的代码,但是当我在主屏幕上点击它时,它会说:App没有安装。 一些帮助?

我的代码:

        Intent shortcutIntent;
    shortcutIntent = new Intent();
    shortcutIntent.setComponent(new ComponentName(
            getApplicationContext().getPackageName(), ".GetQuoteActivity"));

    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    final Intent putShortCutIntent = new Intent();
    putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
            shortcutIntent);

    // Sets the custom shortcut's title
    putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,  "Get Quote");
    putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(
            GetQuoteActivity.this, R.drawable.ic_launcher));
    putShortCutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(putShortCutIntent);
}

AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.files.getquote"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

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

<application android:icon="@drawable/ic_launcher"  android:label="@string/app_name" >
        <activity 
            android:name=".GetQuoteActivity" 
            android:theme="@android:style/Theme.NoTitleBar"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest

2种可能性:

  1. 改为:

     shortcutIntent.setComponent(new ComponentName( getApplicationContext().getPackageName(), GetQuoteActivity.class)); 
  2. 使用此代码创建快捷方式:

     Intent shortcutIntent = new Intent (this, YourActivity.class); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Title"); addIntent.putExtra("duplicate", false); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon)); sendBroadcast(addIntent); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM