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
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
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
Rizwan,
can you share modified code?
Thanks
Michal
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