简体   繁体   中英

How to add a icon on home screen while installing an android app programatically?

Actually i want to create an app for medical purpose and i want a icon on home screen for emergency call. It should come while installing an app. Kindly post answer.

MainActivity.java

public class MainActivity extends Activity {

//Shortcut Icon
    Context mContext=SplashScreen.this;
    SharedPreferences appPreferences;
    boolean isAppInstalled = false;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Added for full ascreen


         appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
          isAppInstalled = appPreferences.getBoolean("isAppInstalled",false);
          if(isAppInstalled==false)
          {
              *//**
               * create short cut code
               *//*
              Intent shortcutIntent = new Intent(getApplicationContext(),MainActivity.class);
              shortcutIntent.setAction(Intent.ACTION_MAIN);
              Intent intent = new Intent();
              intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
              Resources res = getResources();
              String App_name = String.format(res.getString(R.string.app_name)); //your app name
              intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, App_name);
              intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.app_img)); //your app image
              intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
              getApplicationContext().sendBroadcast(intent);
              *//**
               * Make preference true
               *//*
              SharedPreferences.Editor editor = appPreferences.edit();
              editor.putBoolean("isAppInstalled", true);
              editor.commit();
              Toast.makeText(getApplicationContext(), "Shortcut Created", Toast.LENGTH_SHORT).show();
          }


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM