AndroidでPhonegap通知を使用する方法を自分自身で教えています。通知を表示することはかなり簡単なプロセスAndroid Phonegapアプリ - アクティビティを前面に表示する
public void triggerTestNotification(String tag, int id,Context ctxt)
{
Intent notificationIntent = new Intent(context, PallActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent contentIntent = PendingIntent.getActivity(ctxt, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification not = new Notification.Builder(ctxt)
.setContentTitle("Title").setContentText("Title")
.setTicker("Tick tock")
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setSmallIcon(ctxt.getApplicationInfo().icon).build();
NotificationManager notificationManager = (NotificationManager)
ctxt.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(tag, id, not);
}
ように見えながら、私はむしろ、より困難を発見したものを
- 以下しているユーザーは、ユーザーが離れて行くと何かをやって起動するアプリ
- を起動します他の - アプリがバックグラウンドにされ
- 通知が
- が表示されて到着した
- ユーザーが通知をクリックします。
この時点で、アプリはフォアグラウンドに戻ってきます。私は自分の意図コードを考えました
public class PallActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
finish();
forceMainActivityReload();
}
private void forceMainActivityReload()
{
PackageManager pm = getPackageManager();
Intent launchIntent =
pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());
startActivity(launchIntent);
}
@Override
protected void onResume()
{
super.onResume();
final NotificationManager notificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
}
これはどうしても問題ありません。明らかに、私はここで何か間違っている - おそらくインテントの旗で。私は正しい軌道に乗ることができるかもしれない人に多くの義務を負うだろう。
? –
私は別のプラグインでそれを見たので、そこに 'finish()'を配置しました。しかし、私は 'onCreate'の最後に移動した' finish() 'を使って自分のコードを試してみました。アプリはまだフォアグラウンドに戻らない。 – DroidOS
Pallの活動の目的は何ですか?あなたのアプリのランチャー活動にすぐにリダイレクトされます。 'PallActivity'はあなたのランチャー活動ではありませんか?あなたのマニフェストを含めることができますか? –