アクティビティをナビゲートする必要がある場合は、実装に欠けているNotification class(NotificationCompat.Builder)
のバインドが必要です。
NotificationCompat.Builder builder = new **NotificationCompat.Builder(this); builder.setContentIntent(resultPendingIntent);**
ここ
resultPendingIntent
以下のように通知して活動のためbackstackを含むにするために使用されます:行の下
はどんな活動リダイレクトすることが非常に重要である
を//含むPendingIntentを取得します。全体のバックスタックPendingIntent
resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
完全なコードスニペットはhereです。
int id = 1;
Intent resultIntent = new Intent(this, ResultActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent to the top of the stack
stackBuilder.addNextIntent(resultIntent);
// Gets a PendingIntent containing the entire back stack
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(id, builder.build());
編集:
そして、あなたのマニフェストファイル内
<activity android:name=".ActivityXPTO" android:screenOrientation="sensor" android:windowSoftInputMode="stateHidden"> <intent-filter> <action android:name="ACTIVITY_XPTO" />
<category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
アプリを閉じたり、バックグラウンドで、ユーザーは012を取得するために、それは私のActivityXPTO
を開き、通知をクリックした場合は私だけ実行する必要があります。
public class ActivityXPTO extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
String idOffer = "";
Intent startingIntent = getIntent();
if (startingIntent != null) {
idOffer = startingIntent.getStringExtra("id_offer");
// Retrieve the id
}
getOfferDetails(id_offer);
}
}
}
を、以下のようなデータペイロードを介して第2ウェイ
発呼キーでとgetIntent経由MainActivityでキーを取得()および特異的活性またはそのフラグメントを呼び出します。
json1.put( "title"、 "Your Title");
json1.put( "body"、 "body content");
json1。put( "メッセージ"、 "あなたのメッセージ");
json1.put( "screen"、 "2"); // secondFragmentは、ナビゲーションドロワーの2番目の位置にあります。
json.put( "data"、json1);
GitHubのサンプルプロジェクト。
Read https://developer.android.com/training/notify-user/navigation.html – Raghunandan
@Raghunandan私の質問は異なっています。私は特定のアクティビティを開始する必要があり、それはapp.soのすべてのアクティビティになることができます上記のリンクに記載されているすべての属性をすべてのアクティビティで定義し、フラグメントをロードする必要がある場合はどうすればよいですか? – chandra
オープンする各アクティビティに関連するタイプがあります。それに基づいて私はスイッチケースを使用して、その特定の活動にナビゲートする。フラグメントはアクティビティによってホストされます。だから、その場合フラグメントを開始する必要があります – Raghunandan