【问题标题】:Launch an app from notification从通知启动应用程序
【发布时间】:2014-11-24 09:38:28
【问题描述】:

我正在使用 PhoneGap 构建一个应用程序,它围绕我创建的计时器展开。我目前正在苦苦挣扎,因为如果计时器达到零,我需要一种让应用程序自行打开的方法。我目前已经设置了计时器何时用完的通知,用户可以从那里启动应用程序。但是,如果用户“错过”通知或类似的东西,我需要一种启动应用程序的方法。

例如,当移动设备上的本地“计时器”应用程序上的计时器用完时,它会自行打开以通知用户时间已用完。

任何建议都将不胜感激,

谢谢。

【问题讨论】:

    标签: android ios notifications mobile-application


    【解决方案1】:

    只需编写用于打开启动器活动的代码,而不是在您的服务类中显示通知。当计时器用完时,启动器活动将启动而不是通知。 代码将如下所示:

    public class AlarmService extends Service {
    
        @Override
        public IBinder onBind(Intent intent) {
            return null;
        }
    
        @Override
        public int onStartCommand(Intent intent, int flags, int startId) {
            //calling Launcher Activity
            Intent alarmIntent = new Intent(getBaseContext(), AlarmScreen.class);
            alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            alarmIntent.putExtras(intent);
    
            getApplication().startActivity(LauncherActivity.class);
    
            AlarmManagerHelper.setAlarms(this);
    
            return super.onStartCommand(intent, flags, startId);
        }
    }
    

    希望您对这个答案感到满意。

    【讨论】:

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