Как позвонить «Добавить в Дом» Активность в Android? - PullRequest
0 голосов
/ 30 января 2011

На устройствах Android при щелчке или длительном нажатии в пустой области главного экрана открывается диалоговое окно «Добавить в домашнюю активность / действие», позволяющее выбрать один из вариантов для размещения на главном экране.

У меня есть уведомление, которое уходит в строке состояния, и я хочу, чтобы при нажатии на это уведомление я хотел открыть действие Добавить в дом.

Уведомление работает нормально.

Существует ли класс name.class активности, который я мог бы установить в качестве цели уведомления при нажатии?

Я проверил Исходный код Android Launcher .

Я нашел это:

    if (mWorkspace.allowLongPress()) {
1747             if (cellInfo.cell == null) {
1748                 if (cellInfo.valid) {
1749                     // User long pressed on empty space
1750                     mWorkspace.setAllowLongPress(false);
1751                     showAddDialog(cellInfo);
1752                 }
1753             } else {
1754                 if (!(cellInfo.cell instanceof Folder)) {
1755                     // User long pressed on an item
1756                     mWorkspace.startDrag(cellInfo);
1757                 }
1758             }
1759         }
1760         return true;

Скорее всего, showAddDialog(cellInfo) вызывает экран «Добавить на главный экран».

Любые идеи о том, как мне реализовать это для моего требования выше.

1 Ответ

0 голосов
/ 19 января 2012

Чтобы начать действие, когда вы нажимаете на уведомление, вы можете использовать что-то вроде ниже,

                   NotificationManager mNoficationManager;
            mNoficationManager = (NotificationManager) mCntxt.getSystemService(Context.NOTIFICATION_SERVICE);
            Intent intent1 = new Intent();
    ComponentName comp = new ComponentName("YOURPACKAGE TO START","YOUR ACTIVIT TO BE STARTED");
    intent1.setComponent(comp);
    intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


    /* SEND NOTIFICATION */
    PendingIntent pi = PendingIntent.getActivity(mCntxt, 0, intent1, 0);
    Notification n = new Notification();
    n.flags = Notification.FLAG_ONGOING_EVENT;
    n.defaults |= Notification.DEFAULT_SOUND;
    n.tickerText = "some text for tickering";
    mNoficationManager.notify(some int value for your notification id, n);

    int icon = mCntxt.getApplicationInfo().icon;
            Notification notification = new Notification(icon,"some text title",System.currentTimeMillis());
            notification.setLatestEventInfo(mCntxt, "Some text", " some text ", pi);

    notification.defaults |= Notification.DEFAULT_SOUND;
    mNoficationManager.notify(NOTIFICATION_ID, notification);

Надеюсь, что из этого можно извлечь что-то для начала "Добавить в домашнюю активность".

...