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中錯過了什麼?
謝謝!
我擔心會是這樣。你能詳細解釋一下你的答案嗎? – subsecond 2011-03-18 04:56:37
沒有什麼可以詳細說明的,啓動器不會讓您選擇快捷方式的位置。沒有API來實現這一點。 – 2011-03-18 17:08:24
好的。這似乎很奇怪,雖然允許的快捷方式要創建這樣的,不能夠有更好的控制,以在那裏將被寫入。我不知道它的功用。不過謝謝你的回答。我將不得不嘗試一種不同的方法。 – subsecond 2011-03-18 19:02:46