2

この問題に関するStackOverflowの投稿をたくさん見つけましたが、それらはすべて、Notification.Builderクラスを使用する代わりに、廃止されたNotificationメソッドを使用しています。

ステータスバーの通知を正常に作成していますが、クリックしても何も起こりません。LogCatに警告が表示されます。

Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@412d6df0

通知の作成に使用しているコードは次のとおりです。

public class LunchNotificationBuilder {

private Notification notification;
public LunchNotificationBuilder(Lunch lunch, Context context) {
    Builder builder = new Builder(context);
    Calendar reminderTime = (Calendar)lunch.getReminderTime().clone();
    builder.setWhen(reminderTime.getTimeInMillis());
    builder.setTicker("Reminder for " + lunch.getTitle());
    builder.setContentTitle("LunchBunch Notification");
    builder.setContentText("Upcoming lunch at " + lunch.getTitle());
    builder.setSmallIcon(R.drawable.ic_launcher);
    Intent intent = new Intent(context, InviteDetails.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT));
    this.notification = builder.getNotification();
}

public Notification getNotification() {
    return this.notification;
}

}

Lunchクラスは、私が作成した単なるデータ構造です。心配する必要はありません。

渡されるコンテキストはApplication.getApplicationContext()です。

ドキュメントで提案されているように、Intent.FLAG_ACTIVITY_NEW_TASKフラグを設定していますが、PendingIntentにはPendingIntent.FLAG_ONE_SHOTフラグがあります。

別の注意:コードの他の場所でstartActivityを明示的に呼び出すと、起動しようとしているアクティビティ(InviteDetails)は問題なく機能します。このPendingIntentビジネスに関する何かが機能していません。

4

1 に答える 1

0

Androidの使い方がわからないことがわかりました。クリックする前に完全な通知を表示するために下にドラッグするのではなく、上部のステータスバーをクリックしていました。私のコードは機能していました。ドー!

于 2012-05-08T16:55:50.573 に答える