App icons on home screen

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

App icons on home screen

1,212 Views
rizwan_s
Contributor II

Hi All,

I am working on android 5.0.0 lollipop version.

I need App icons on the Home screen other than menu through source code modification instead of Drag and drop method.

Could you please suggest me how to proceed?

Regards

Rizwan Syed

Labels (2)
0 Kudos
7 Replies

802 Views
rizwan_s
Contributor II

Hi Michal,

Thanks for the information.

Still the result is same.App icons are not coming on Home screen.

Do i need to give make clean for this?

Regards

Rizwan Syed

0 Kudos

802 Views
rizwan_s
Contributor II

modified files:AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.calendar.tests"
    android:versionCode="1"
        android:versionName="1.0" >

     <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />


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

    <application
         android:icon="@R.mipmap.ic_launcher_calendar"
        android:label="@string/calender"
        android:theme="@style/calender" >

<activity
            android:name="com.manish.home.shortcut.CalendarApplication"
            android:exported="true"
            android:label="@string/calender" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

CalenderApplication.java file:

package com.android.calendar;

import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.content.SharedPreferences;

public class CalendarApplication extends Application {

    SharedPreferences appPref;
    boolean isFirstTime = false;
    @Override
    public void onCreate() {
        super.onCreate();
    
    //setContentView(R.layout.simple_frame_layout);
    createShortCut();
        /*
         * Ensure the default values are set for any receiver, activity,
         * service, etc. of Calendar
         */
        GeneralPreferences.setDefaultValues(this);

        // Save the version number, for upcoming 'What's new' screen.  This will be later be
        // moved to that implementation.
        Utils.setSharedPreference(this, GeneralPreferences.KEY_VERSION,
                Utils.getVersionCode(this));

        // Initialize the registry mapping some custom behavior.
        ExtensionsFactory.init(getAssets());


    }
 /**
 * Method gets invoked when 'Create Shortcut' button is clicked
 *
 * @param v
 */
 public void createShortCut(){
 appPref = getSharedPreferences("isFirstTime", 0);
 isFirstTime = appPref.getBoolean("isFirstTime", true);
 if (isFirstTime==false) {
 Intent shortCutInt = new Intent(getApplicationContext(),
 //MainActivity.class);
 CalendarApplication.class);
 shortCutInt.setAction(Intent.ACTION_MAIN);
 //Intent addInt = new Intent();

        Intent addInt = new Intent(Intent.ACTION_MAIN, null);
        addInt.addCategory("com.android.calender.SHORTCUT");

 addInt.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortCutInt);
 addInt.putExtra(Intent.EXTRA_SHORTCUT_NAME, "MyAppShortcut");
 addInt.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
 Intent.ShortcutIconResource.fromContext(getApplicationContext(),
 R.mipmap.ic_launcher_calendar));
 // Set Install action in Intent
 addInt.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
 // Broadcast the created intent
 getApplicationContext().sendBroadcast(addInt);
 SharedPreferences.Editor editor = appPref.edit();
 editor.putBoolean("isFirstTime", true);
 editor.commit();
 }
 }
 
}

Regards

Rizwan Syed

0 Kudos

802 Views
mike_susen
NXP Employee
NXP Employee

Hi Rizwan,

in manifest file please edit <intent-filter>to this

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

Hope it helps 

Michal

0 Kudos

802 Views
rizwan_s
Contributor II

Hi Michal

Thank you for your suggestion.It is working.

Instead of creating separate function,implementing the code after oncreate function works fine.

Regards

Rizwan Syed

0 Kudos

802 Views
rizwan_s
Contributor II

Hi michal,

Thanks for the information.

I tried this , but still am unable to get App icon on the main screen.

Regards

Rizwan Syed

0 Kudos

802 Views
mike_susen
NXP Employee
NXP Employee

Rizwan,

can you share modified code?

Thanks

Michal

0 Kudos

802 Views
mike_susen
NXP Employee
NXP Employee

Hi Rizwan,

one way is edit launcher's source code and add piece of code regarding this tutorial http://www.androidhub4you.com/2013/10/android-create-shortcut-of-application.html 

Michal

0 Kudos