Vui lòng không tự động làm điều đó !!! Cho phép người dùng chọn thời tiết hoặc không muốn tắt phím tắt của bạn!
Đây là mã bạn cần:
//Create shortcutIntent here with the intent that will launch you app.
Intent shortcutIntent = (...)
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// Sets the custom shortcut's title
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,sName);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
// add the shortcut
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
Đừng quên một phép bổ sung trong Manifest!
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
Nguồn
2010-07-26 08:20:15
Có thể thực hiện tự động khi người dùng CÀI ĐẶT ứng dụng không? – Moshik
Tôi chưa bao giờ nghe nói về ứng dụng tự khởi chạy Trong android ... Bạn có thể thực thi đoạn mã này khi khởi chạy thủ công lần đầu tiên của ứng dụng của bạn. –
Những gì tôi làm cho ứng dụng của mình là tạo tùy chọn boolean "actiondone", theo mặc định là "false" Nếu (! Actiondone) thì tôi đặt tùy chọn này thành true và thực hiện hành động "firstboot". Hy vọng bạn đã quen thuộc với các tùy chọn ... –