0

在 Android 设备上,当您单击或长按主屏幕的空白区域时,将打开“添加到家庭活动”/对话框,允许您从不同的选项中进行选择以放置在主屏幕上。

我有一个在状态栏中发出的通知,我想要做的是当单击该通知时我想打开“添加到家庭活动”。

通知工作正常。

是否有一个活动名称。我可以在单击时将其设置为通知的目标?

我检查了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)会调出添加到主屏幕。

关于如何针对我的上述要求实施此操作的任何想法。

4

1 回答 1

0

要在单击通知时开始活动,您可以使用以下内容,

                   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);

希望您可以从中获得一些东西来开始“添加到家庭活动”。

于 2012-01-19T05:51:42.473 回答