0

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)、[ホームに追加] 画面が表示されます。

上記の要件に対してこれを実装する方法についてのアイデア。

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 に答える