【问题标题】:Activity Not opening from the notification bar活动未从通知栏打开
【发布时间】:2016-12-09 19:25:16
【问题描述】:

期待: 我在通知栏中显示多个通知。在此通知中,我有三个按钮,例如 1、2 和 3。从通知中,如果单击 1 按钮,则如果单击 2 按钮,它必须进行第一个活动,它也必须进行第二个活动,就像 3 按钮一样。

但我被困在下面:

1.显示多个通知 => 没问题 2. 但是,如果我单击第一个按钮,它将进入第一个活动。(现在应用程序正在打开)当我再次单击第一个按钮时,通知状态栏中显示的其他一些通知不会打开第一个活动

AirshipReceiver(推送接收器)

 @Override
protected boolean onNotificationOpened(@NonNull Context context, @NonNull NotificationInfo notificationInfo, @NonNull ActionButtonInfo actionButtonInfo) {
    Log.i(TAG, "Notification action button opened. Button ID: " + actionButtonInfo.getButtonId() + ". NotificationId: " + notificationInfo.getNotificationId());
    Toast.makeText(context.getApplicationContext(),"Button Click",Toast.LENGTH_LONG).show();
    Log.e("@@@@@@@ID", String.valueOf(notificationInfo.getNotificationId()));
    Log.e("$$", String.valueOf(notificationInfo.getMessage().getAlert()));
    Log.e("eGSSSHKJHSHJS", (String) notificationInfo.getMessage().getPushBundle().get("AlarmJson"));
    String pushjson=(String) notificationInfo.getMessage().getPushBundle().get("AlarmJson");
    ***if(actionButtonInfo.getButtonId()!=null && actionButtonInfo.getButtonId().equalsIgnoreCase("Graph")) {
        Log.e("Graph","You clicked Graph");
        Toast.makeText(context.getApplicationContext(),"Graph Click",Toast.LENGTH_LONG).show();
        Intent i = new Intent(context.getApplicationContext(), **ResultActivity**.class);
        i.putExtra("From", "from@@#graphicViewRoute");
        i.putExtra("Pushjson","json@@"+pushjson);
        //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(i);
        return true;***

    }
    else if(actionButtonInfo.getButtonId()!=null && actionButtonInfo.getButtonId().equalsIgnoreCase("DD"))
    {
        Log.e("DD","You clicked DD");
        Intent i = new Intent(context.getApplicationContext(), **ResultActivity**.class);
        i.putExtra("From", "from@@#ddviewRoute");
        i.putExtra("Pushjson","json@@"+pushjson);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);

        return true;

    }

    // Return false here to allow Urban Airship to auto launch the launcher
    // activity for foreground notification action buttons
    return false;
}

ResultActivity.class:

public class ResultActivity extends CordovaActivity{
public static boolean mIsInForegroundMode;
public static String PREF_FILE = "eG_sp";
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    Log.e("ResultActivity","You ResultActivity");
    Bundle extras = getIntent().getExtras();
    String pushPage = extras.getString("From");
    String pushJSON = extras.getString("Pushjson");
    Toast.makeText(getApplicationContext(),"ResultActivity Click",Toast.LENGTH_LONG).show();
    Log.e("ResultActivity",pushPage+pushJSON);

    //super.loadUrl("file:///android_asset/www/index.html");
    SharedPreferences.Editor editor = getSharedPreferences(PREF_FILE, MODE_APPEND).edit();
    editor.putString("pushPage", pushPage);
    editor.putString("pushJSON",pushJSON);
    editor.commit();
    super.loadUrl("file:///android_asset/www/index.html");
}
@Override
protected void onPause(){
    super.onPause();
    mIsInForegroundMode = false;
}
@Override
protected void onResume() {
    super.onResume();
    mIsInForegroundMode=true;
}
@Override
protected void onStop() {
    super.onStop();
    mIsInForegroundMode=false;
}
@Override
protected void onStart() {
    super.onStart();
    mIsInForegroundMode=true;
}
@Override
public void onDestroy() {
    LOG.d(TAG, "CordovaActivity.onDestroy()");
    super.onDestroy();
    mIsInForegroundMode=false;
}

}

【问题讨论】:

  • 发布您用于创建通知的代码。
  • @David Wasser 我已经更新了帖子。请检查一下
  • 抱歉,我在这里没有看到任何创建通知的代码。请发布创建通知的代码
  • @DavidWasser 这是 Urban Airship 插件。在插件中它自己有创建通知功能。
  • 它到达接收器了吗?活动呢?对我来说真正突出的一件事是多次致电setFlags。最后一盘将获胜。设置多个标志或一起设置setFlags(IIntent.FLAG_ACTIVITY_NEW_TASK | ... )

标签: android cordova push-notification cordova-plugins urbanairship.com


【解决方案1】:

我有如下的 setFloags。现在它正在工作。

 i.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TASK| Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多