![](/img/trans.png)
[英]How set badge number in home screen app icon android programatically?
[英]How to add a icon on home screen while installing an android app programatically?
實際上,我想創建一個用於醫療目的的應用程序,並且我想在主屏幕上顯示一個用於緊急呼叫的圖標。 它應該在安裝應用程序時出現。 歡迎留言回復。
主活動.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();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.