add Home Screen Shortcut : Screen « Hardware « Android






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

1.Multiscreen size
2.Nested PreferenceScreen
3.Get the size of Default Display Screen
4.Screen Orientation
5.Rows have different number of columns and content doesn't fit on screen: column 4 of row 2 shrinks all of the other columns
6.Demonstrates the Tab scrolling when too many tabs are displayed to fit in the screen.
7.Using PreferenceScreen
8.Splash Screen
9.Get the optimal preview size for the given screen size.
10.Methods for converting between the physics world coordinates and the screen coordinates.
11.Get screen Orientation
12.Return the supported picture size that best fits on the device screen.
13.Screen Short
14.Set full screen mode