私はアンドロイドを新しくしています。私はアンドロイドでgcmの統合部分を学んでいます。この問題は、マニフェストにランチャーとしてマークされていないアクティビティを呼び出すことができませんでした。私はgcm通知とすべてのデータを受け取ることができますが、アクティビティを呼び出すことはできません。なぜこうなった?そして、この問題は、アプリがバックグラウンドから削除された場合にのみ発生します。アプリが実行されていない、またはバックグラウンドから削除されていないときにアプリケーションコンテキストを保存して取得する方法はありますか?GcmListenerServiceから非ランチャークラスを呼び出す方法は?
public class NotificationsListenerService extends GcmListenerService {
public static final int MESSAGE_NOTIFICATION_ID = 435345;
private static final String TAG = "MyGcmListenerService";
@Override
public void onMessageReceived(String from, Bundle data) {
//String message = data.getString("message");
String message = data.getBundle("notification").getString("body");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " + message);
Log.d(TAG, "GCM DATA: " + data);
try{
String CODE=data.getString("code");
if(CODE!=null){
switch (CODE){
case "666":
String id=data.getString("id");
Code666(id);
break;
}
}
}catch (Exception e){
e.printStackTrace();
}
}
private void Code666(String _id) {
Context context = getBaseContext();
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra("_id",_id);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.floatinglogo)
.setContentTitle("Horn OK")
.setContentText("HelpNeeded!")
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}
}
ありがとうございます! Sidharth
ではありませんが、 'flag_activity_new task'何かをしてみてください。 –
関連コードを投稿してください。 –
保留中のインテントを送信して通知を表示するコードを送信してください。 –