2017-03-06 6 views
0

私はfirebaseの通知を受けていますが、通知をクリックすると、MainActivityページが表示されています。次のページのアクティビティを取得したいです 私はそれを得ることができませんここ がMainActivityの代わりに通知をクリックすると

MainActivity

package com.example.reema.firebase1; 

import android.os.Bundle; 
import android.support.v7.app.ActionBarActivity; 
import android.util.Log; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 

import com.google.firebase.iid.FirebaseInstanceId; 


public class MainActivity extends ActionBarActivity { 
    private String TAG; 

    //private static final String TAG = ; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Button btn = (Button) findViewById(R.id.btn); 
     btn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       String tkn = FirebaseInstanceId.getInstance().getToken(); 
       Toast.makeText(MainActivity.this, "Current token [" + tkn + "]", 
         Toast.LENGTH_LONG).show(); 
       Log.d("App", "Token [" + tkn + "]"); 

      } 
     }); 
    } 



    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_main, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 

FireMsgService

以下のコードで助けてください
package com.example.reema.firebase1; 

import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Context; 
import android.content.Intent; 
import android.support.v4.app.NotificationCompat; 
import android.util.Log; 

import com.google.firebase.messaging.FirebaseMessagingService; 
import com.google.firebase.messaging.RemoteMessage; 

public class FireMsgService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     super.onMessageReceived(remoteMessage); 

     Log.d("Msg", "Message received [" + remoteMessage + "]"); 

     // Create Notification 
//  Intent intent = new Intent(this, Nextpage.class); 
//  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
// 
// 
//  PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410, 
//    intent, PendingIntent.FLAG_ONE_SHOT); 
// 
//  NotificationCompat.Builder notificationBuilder = new 
//    NotificationCompat.Builder(this) 
//    .setSmallIcon(R.drawable.firebase_icon) 
//    .setContentTitle("Message") 
//    .setContentText(remoteMessage.getNotification().getBody()) 
//    .setAutoCancel(true) 
//    .setContentIntent(pendingIntent); 
// 
//  NotificationManager notificationManager = 
//    (NotificationManager) 
//      getSystemService(Context.NOTIFICATION_SERVICE); 
// 
//  notificationManager.notify(1410, notificationBuilder.build()); 
     // Context context; 
     Context context = getApplicationContext(); 
     int icon = R.drawable.firebase_icon; 
     CharSequence tickerText = "Call Blocker"; 
     CharSequence title = "Call Blocker"; 
     long when = System.currentTimeMillis(); 
     NotificationManager notificationManager = (NotificationManager) context 
       .getSystemService(Context.NOTIFICATION_SERVICE); 
     Notification notification = new Notification(icon, tickerText, when); 

     Intent notificationIntent = new Intent(context, Nextpage.class); 

     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
       | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

     PendingIntent intent = PendingIntent.getActivity(context, 0, 
       notificationIntent, 0); 
     NotificationCompat.Builder notificationBuilder = new 
       NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.firebase_icon) 
       .setContentTitle("Message") 
       .setContentText(remoteMessage.getNotification().getBody()) 
       .setAutoCancel(true) 
       .setContentIntent(intent); 
     //notification.setLatestEventInfo(context, title, tickerText, intent); 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 
     notificationManager.notify(0, notification); 
    } 
} 

NEXTPAGE

package com.example.reema.firebase1; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 


public class Nextpage extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_another); 
     TextView textView = (TextView) findViewById(R.id.informationTextView); 
     textView.setText("You clicked the button {0} times in the previous activity."); 


    } 
} 
+0

マニフェストを投稿できますか? – Hmm

答えて

0

理由は、あなたが実際にそれからあなたの通知を得ることはありませんが、あなたがNotificationBuilderを作成しているです。

Context context = getApplicationContext(); 
    int icon = R.drawable.firebase_icon; 
    CharSequence tickerText = "Call Blocker"; 
    CharSequence title = "Call Blocker"; 
    long when = System.currentTimeMillis(); 
    NotificationManager notificationManager = (NotificationManager) context 
      .getSystemService(Context.NOTIFICATION_SERVICE); 

    Intent notificationIntent = new Intent(context, Nextpage.class); 

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
      | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 

    PendingIntent intent = PendingIntent.getActivity(context, 0, 
      notificationIntent, 0); 
    NotificationCompat.Builder notificationBuilder = new 
      NotificationCompat.Builder(this) 
      .setSmallIcon(R.drawable.firebase_icon) 
      .setContentTitle("Message") 
      .setContentText(remoteMessage.getNotification().getBody()) 
      .setAutoCancel(true) 
      .setContentIntent(intent); 
    Notification notification = notificationBuilder.build(); 
    //notification.setLatestEventInfo(context, title, tickerText, intent); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notificationManager.notify(0, notification); 
+0

アプリが終了すると通知が来て、MainActivityがオープンしていますが、アプリが開いているときに通知が来ていません – Disha

+0

@Dishaこれは元の返答コードですか、 –

+0

通知がクリックされたときに変更がなかった場合は、 – Disha

関連する問題