0

通知からインテントを起動しようとしています:

CharSequence tickerText = "ServiceTicker"; // context.getString(R.string.service_ticker_registered_text);
long when = System.currentTimeMillis();

Builder nb = new NotificationCompat.Builder(context);
nb.setTicker(tickerText);
nb.setWhen(when);
Intent notificationIntent = new Intent(context, AccountRegistrationChanged.class);

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

RegistrationNotification contentView = new RegistrationNotification(context.getPackageName());
contentView.clearRegistrations();
if(!Compatibility.isCompatible(9)) {
    contentView.setTextsColor(notificationPrimaryTextColor);
}
contentView.addAccountInfos(context, activeAccountsInfos);

nb.setOngoing(true);
nb.setOnlyAlertOnce(true);
nb.setContentIntent(contentIntent);
nb.setContent(contentView);

Notification notification = nb.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
// We have to re-write content view because getNotification setLatestEventInfo implicitly
notification.contentView = contentView;
Log.e(THIS_FILE, "==============notification:" + notification + " contentView:" + contentView + " notificationIntent:" + notificationIntent + " contentIntent" + contentIntent + " context:" + context + " nb:" + nb);

if (showNumbers) {
    // This only affects android 2.3 and lower
    notification.number = activeAccountsInfos.size();
}
startForegroundCompat(REGISTER_NOTIF_ID, notification);

private void startForegroundCompat(int id, Notification notification) {
    // If we have the new startForeground API, then use it.
    if (mStartForeground != null) {
        Log.e(THIS_FILE, "mStartForeground");

        mStartForegroundArgs[0] = Integer.valueOf(id);
        mStartForegroundArgs[1] = notification;
        invokeMethod(mStartForeground, mStartForegroundArgs);
        return;
    }
    Log.e(THIS_FILE, "invokeMethod");

    // Fall back on the old API.
    mSetForegroundArgs[0] = Boolean.TRUE;
    invokeMethod(mSetForeground, mSetForegroundArgs);
    notificationManager.notify(id, notification);
}

最後に、すべてのインテントとビューが正しく作成されたログがあります。

10-04 22:38:49.344: E/通知 (7415):

==============notification:Notification(vibrate=null,sound=null,defaults=0x0) contentView:com.csipsimple.widgets.RegistrationNotification@44eb3ff8 notificationIntent:Intent { flg=0x10000000 cmp= com.callsfreecalls.android/.AccountRegistrationChanged } contentIntentPendingIntent{44eb3fe8: android.os.BinderProxy@44f08f98} context:com.csipsimple.service.SipService@44e9c328 nb:android.support.v4.app.NotificationCompat$Builder@44eb3e30 10-04 22:38:49.344: E/通知 (7415): mStartForeground

10-04 22:38:49.344: E/通知 (7415): mStartForeground

しかし、何も起こらなかった、このコード:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.e(THIS_FILE, "AccountRegistrationChanged");

    setContentView(R.layout.activity_account_registration_changed);
}

Activity/AccountRegistrationChanged で開始されていません...

アクティビティのマニフェストは次のとおりです。

<activity
    android:name=".AccountRegistrationChanged"
    android:label="@string/title_activity_account_registration_changed" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

なにか提案を?多分私は通知開始の意図をプッシュするために何かを起動する必要がありますか? 現在、別のアクティビティからいくつかの要素をアクティブにする必要がありますが、ハンドラーを使用したコード (以下で説明) により、デバッグで説明なしに不明なエラーが発生しました:

SipProfileState ps = activeAccountsInfos.get(i);
Message msg = new Message();
Bundle b = new Bundle();
b.putString("regState",String.valueOf(ps.getStatusCode()));
msg.setData(b);
PhonePadActivity.getUareceiverhandler().sendMessage(msg);
4

1 に答える 1

1

おそらく、アクティビティのonNewIntent()メソッドが のAccountRegistrationChanged代わりに起動されていますonCreate()AccountRegistrationChangedアクティビティは通知前にすでに作成されていましたか?

于 2012-10-04T20:00:10.843 に答える