افزودن میانبر در صفحه اول (HomeScreen): همزمان با اجرای برنامه
این کد رو تو اکتیویتی اصلی کپی کنید:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this );
if(!prefs.getBoolean("firstTime", false)) {
// <---- run your one time code here
Intent HomeScreenShortCut= new Intent(getApplicationContext(),
MainActivity.class);
HomeScreenShortCut.setAction(Intent.ACTION_MAIN);
HomeScreenShortCut.putExtra("duplicate", false);
//shortcutIntent is added with addIntent
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, HomeScreenShortCut);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "اسم برنامه");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESO URCE,
Intent.ShortcutIconResource.fromContext(getApplica tionContext(),
R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.I NSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
Toast.makeText(getApplicationContext(), "آیکن این برنامه برای دسترسی سریع در صفحه اصلی افزوده شد", Toast.LENGTH_LONG).show();
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("firstTime", true);
editor.commit();
}
واینو تو منیفست پروژه:
<uses-permission android:name="com.android.launcher.permission.INST ALL_SHORTCUT" />