作爲一個工作周,正如我在評論中所說的,您可以添加一個處理程序來延遲YouTube應用的啓動。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
String path = "https://www.youtube.com/watch?v=63pKwVE4Uog";
Uri uri = Uri.parse(path);
uri = Uri.parse("vnd.youtube:" + uri.getQueryParameter("v"));
Intent i= new Intent(Intent.ACTION_VIEW, uri);
i.addFlags(FLAG_ACTIVITY_NEW_TASK);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(i);
}
}, 2000);
}
嘗試添加處理程序以延遲YouTube應用的啓動。通過這種方式,您的屏幕就會打開,並在YouTube應用啓動時保持清醒 –