如何调用“添加到主页” Android 中的活动?

发布于 2024-10-15 14:22:37 字数 1125 浏览 1 评论 0原文

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

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

该通知工作正常。

是否有一个活动 name.class 我可以将其设置为单击时通知的目标?

我检查了 Android启动器源代码

我发现了这一点:

    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) 会调出“添加到主屏幕”。

关于如何根据我的上述要求实现这一点的任何想法。

On Android devices when you click or long press on an empty area of a home screen, the Add to Home Activity/dialog opens up allowing you to choose from different options to put on the home screen.

I have a notification that goes off at the status bar, what I want to do is when that notification is clicked I want to open the Add to Home Activity.

The notification is working fine.

Is there an activity name.class that I could set as the target of the notification when clicked?

I checked Android Launcher source code.

I found this:

    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;

Most certainly showAddDialog(cellInfo) brings up the Add to Home screen.

Any ideas on how do I go about implementing this for my requirement above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜扑 2024-10-22 14:22:37

要在单击通知时启动活动,您可以使用如下所示的内容,

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

希望您可以从中导出一些内容来启动“添加到家庭活动”。

To start an activity when you click the notification you can use some thing like below,

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

Hope from this you can derive something to start "Add to Home Activity".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文