Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 主屏幕快捷方式应用程序未安装_Java_Android - Fatal编程技术网

Java 主屏幕快捷方式应用程序未安装

Java 主屏幕快捷方式应用程序未安装,java,android,Java,Android,我找到在主屏幕上创建快捷方式的代码,它可以工作,但当我在主屏幕上单击它时,它会说:App no installed。要帮忙吗 我的代码: Intent shortcutIntent; shortcutIntent = new Intent(); shortcutIntent.setComponent(new ComponentName( getApplicationContext().getPackageName(), ".GetQuote

我找到在主屏幕上创建快捷方式的代码,它可以工作,但当我在主屏幕上单击它时,它会说:App no installed。要帮忙吗

我的代码:

        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种可能性:

  • 更改为:

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

    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);
    

  • 绝对完美,我想放弃你,但没有足够的要求。因此,仅标记为已完成。:)还有一个问题当我点击应用程序更多时间时,它总是显示快捷方式应用程序名称已创建是否可以只显示一次?应用程序未安装,如何修复?