2011-03-17 50 views
6

我目前正在研究Android应用程序,因此我以编程方式编写主屏幕的快捷方式。就像这样:如何以编程方式在Android启动器的主屏幕上为特定页面编写快捷方式?

Intent shortcutIntent = new Intent(); 
shortcutIntent.setClassName(ai.packageName, ai.name); 
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
shortcutIntent.addCategory(Intent.ACTION_PICK_ACTIVITY); 
Intent intent = new Intent(); 
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName); 

BitmapDrawable bd=(BitmapDrawable)(res.get(app_id).activityInfo.loadIcon(p).getCurrent()); 
Bitmap newbit; 
newbit=bd.getBitmap(); 
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newbit); 

intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
context.sendBroadcast(intent); 

(它实际上是一个StackOverflow帖子,指出我这个解决方案)。

无论如何,当我在模拟器中运行应用程序时,快捷方式会从左侧写入第5页(在2.3主屏幕上)。随后的运行将快捷方式写入主屏幕左侧的第4页。

我的问题是:有没有写这个快捷方式即可中心页面或第一页(如通过索引2-d阵列似乎保持应用的快捷方式)的方式?我在API中错过了什么?

谢谢!

回答

9

您无法决定快捷方式的去向。

+0

我担心会是这样。你能详细解释一下你的答案吗? – subsecond 2011-03-18 04:56:37

+1

没有什么可以详细说明的,启动器不会让您选择快捷方式的位置。没有API来实现这一点。 – 2011-03-18 17:08:24

+1

好的。这似乎很奇怪,虽然允许的快捷方式要创建这样的,不能够有更好的控制,以在那里将被写入。我不知道它的功用。不过谢谢你的回答。我将不得不尝试一种不同的方法。 – subsecond 2011-03-18 19:02:46

相关问题