add Home Screen Shortcut
//package com.omareitti;
import java.util.List;
import java.util.UUID;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
public class Utils {
public static void addHomeScreenShortcut(Context context, String name, String fromAddress, String toAddress, String fromCoords, String toCoords) {
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(context, context.getClass().getName());
shortcutIntent.setAction(Intent.ACTION_MAIN);
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (toAddress != null) shortcutIntent.putExtra("toAddress", toAddress);
if (fromAddress != null) shortcutIntent.putExtra("fromAddress", fromAddress);
if (toCoords != null) shortcutIntent.putExtra("toCoords", toCoords);
if (fromCoords != null) shortcutIntent.putExtra("fromCoords", fromCoords);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
// intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
// Intent.ShortcutIconResource.fromContext(context,
// R.drawable.icon));
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(intent);
}
}
Related examples in the same category