其实我想创建一个用于医疗目的的应用程序,我想在主屏幕上显示紧急呼叫的图标。它应该在安装应用程序时出现。请回复。
答案 0 :(得分:0)
<强> 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();
}
}