Java 从睡眠中醒来时Chromecast不投射

Java 从睡眠中醒来时Chromecast不投射,java,android,chromecast,google-cast,Java,Android,Chromecast,Google Cast,我正在开发一个应用程序,它可以将手机从睡眠中唤醒,然后开始播放。 我所做的就是制作一个广播接收器来启动这样的活动 WakeLocker.acquire(context); Intent intentAlarm = new Intent(context, AlarmRingingActivity.class); intentAlarm.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTI

我正在开发一个应用程序,它可以将手机从睡眠中唤醒,然后开始播放。 我所做的就是制作一个广播接收器来启动这样的活动

WakeLocker.acquire(context);
Intent intentAlarm = new Intent(context, AlarmRingingActivity.class);
intentAlarm.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
        | Intent.FLAG_ACTIVITY_NO_USER_ACTION |
          Intent.FLAG_ACTIVITY_SINGLE_TOP |
          Intent.FLAG_ACTIVITY_CLEAR_TOP);
intentAlarm.setAction("ACTION_VIEW");
context.startActivity(intentAlarm);
在AlarmringActivity中,我使用了以下代码

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                    WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                    WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    mMediaRouteButton = (MediaRouteButton) findViewById(R.id.media_route_button);
    CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), mMediaRouteButton);

    mCastContext = CastContext.getSharedInstance(this);

    mSelector = new MediaRouteSelector.Builder()
            // These are the framework-supported intents
            .addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
            .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
            .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
            .build();
    mMediaRouter = MediaRouter.getInstance(this);
    for (MediaRouter.RouteInfo route : mMediaRouter.getRoutes()) {
        if (route.getName().equals("Min Stue")) {
            mMediaRouter.selectRoute(route);
            Log.d("MyAlarm", "Size:" + mMediaRouter.getRoutes().size());
        }
        Log.d("MyAlarm", route + "");
    }
如果我不锁上手机,它就会开始播放,这一切都会起作用。然而,如果我锁上手机,它不会开始铸造。它显示了施法图标,我可以停止施法,但实际上它不会施法到屏幕上。此外,如果手机睡眠时间过长,它会“忘记”媒体路由,唯一可用的媒体路由就是手机本身

因此,我的问题是:

  • 当我从睡眠中醒来/解锁手机时,我如何施放
  • 如何防止应用程序“忘记”媒体路由

  • 从这一点来看,脱下HDMI扩展器似乎是唤醒chromecast的解决办法。这些论坛:也可能有帮助。确保您使用的是Chromecast盒中的电源适配器插头,而不是由USB端口供电。问题不是Chromecast正在休眠。如果我在电视关闭时播放一些内容,它会打开电视并开始播放。当手机从睡眠模式中醒来并被告知开始播放时,问题就出现了。不过,我可以看出这种混乱是从哪里来的。