2011-01-30 60 views
0

在Android设备上单击或长按主屏幕的空白区域时,会打开“添加到家庭活动”对话框,允许您从不同选项中选择放置在主屏幕上。如何在Android中调用“添加到家庭”活动?

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

通知工作正常。

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

我查了Android Launcher source code

我发现这一点:

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)可以调出添加到主屏幕。

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

+0

你意识到用户可以自由使用不同的主屏幕,对吧?而这个工作原理可能取决于主屏幕。 – Falmarri 2011-01-30 21:37:36

回答

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

从这个希望你能得到的东西,开始“添加到主活动”。

相关问题