2016-07-21 17 views
0

Ich kann auf dem Startbildschirm kein Verknüpfungssymbol hinzufügen. Ich möchte dies nur mit Manifest tun und nicht durch Hinzufügen einer Methode zur Aktivität.Wie man Verknüpfungssymbol auf dem Startbildschirm in Android hinzufügen?

i müde dieser Code in manifest:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.app.fz.atifandroid"> 
    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="21" /> 
    <uses-permission 
     android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> 
    <uses-permission 
     android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <application 
     android:allowBackup="true" 
     android:icon="@drawable/icon_image" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/Theme.AppCompat.Light.NoActionBar"> 


    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:configChanges="orientation|screenSize"> 
     > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 

    </activity> 
    <!--<activity android:name=".MainActivity"/>--> 
</application> 
</manifest> 
+0

ich Ihre Frage upvoted. Ich fand es echt. – Ironman

+0

check this out [link] (http://stackoverflow.com/questions/6337431/android-create-shortcuts-on-the-home-screen/20536046#20536046) –

+0

Bereits beantwortet in [Wie Verknüpfung zum Startbildschirm hinzufügen in android programmatisch] (http://stackoverflow.com/questions/16873256/how-to-add-shortcut-to-home-screen-in-android-programatically) – ShivBuyya

Antwort

0

Überprüfen Sie den Link, da diese Frage zu Android create shortcuts on the home screen ähnlich ist.

Ein weiterer Weg ist, wenn Sie die App aus dem Play Store herunterladen dann in Play-Store-Einstellungen können Sie das Symbol hinzufügen, um Homescreen dann wird das App-Symbol in Homescreen erstellen.

Ich hoffe, das hilft.

0

Try this,

in Java,

private void ShortcutIcon(){ 

Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class); 
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

Intent addIntent = new Intent(); 
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Test"); 
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher)); 
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
getApplicationContext().sendBroadcast(addIntent); 
} 

Vergessen Sie nicht die Erlaubnis, manifest.xml

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

Glücklich Codierung hinzuzufügen !!!

+0

sollte Shortcut-Symbol dasselbe wie Launcher-Symbol sein? Wenn ja, wird mein Launcher-Icon in den mimp-Ordner anstatt in den ziehbaren Ordner gestellt, sollte ich eine Verknüpfungssymbol-Ressource aus dem Mimp-Ordner bekommen? –

0

Zuerst müssen wir die Berechtigung INSTALL_SHORTCUT zu Android Manifest xml hinzufügen.

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

Die addShortcut() -Methode erstellen Sie eine neue Verknüpfung auf dem Startbildschirm.

private void addShortcut() { 
    //Adding shortcut for MainActivity 
    //on Home screen 
    Intent shortcutIntent = new Intent(getApplicationContext(), 
      MainActivity.class); 

    shortcutIntent.setAction(Intent.ACTION_MAIN); 

    Intent addIntent = new Intent(); 
    addIntent 
      .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut"); 
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, 
      Intent.ShortcutIconResource.fromContext(getApplicationContext(), 
        R.drawable.ic_launcher)); 

    addIntent 
      .setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
    getApplicationContext().sendBroadcast(addIntent); 
} 

Auch diesen Code setzen mehrere Verknüpfungen zu vermeiden:

if(!getSharedPreferences(Utils.APP_PREFERENCE, Activity.MODE_PRIVATE).getBoolean(Utils.IS_ICON_CREATED, false)){ 
      addShortcut(); 
      getSharedPreferences(Utils.APP_PREFERENCE, Activity.MODE_PRIVATE).edit().putBoolean(Utils.IS_ICON_CREATED, true); 
     } 

Es beantwortet here

+0

Ich bekomme "kann nicht lösen Symbol utils" Fehler, wie zu beheben? – user3304007