我正在调整Google Cast代码,即here提供的代码。
我已完成整个工作空间设置,但是,当尝试在Android手机上运行示例应用时,我收到以下错误。
我刚刚将包名称指定为应用ID。我在哪里可以获得应用ID?我应该向Google注册以获取应用ID吗?它是如何工作的?
02-13 23:36:00.995: E/AndroidRuntime(8310): FATAL EXCEPTION: main
02-13 23:36:00.995: E/AndroidRuntime(8310): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.sample.cast.refplayer/com.google.sample.cast.refplayer.VideoBrowserActivity}: java.lang.IllegalArgumentException: Invalid appliation ID: com.google.sample.cast.refplayer
02-13 23:36:00.995: E/AndroidRuntime(8310): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
02-13 23:36:00.995: E/AndroidRuntime(8310): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
02-13 23:36:00.995: E/AndroidRuntime(8310): at android.app.ActivityThread.access$600(ActivityThread.java:127)
02-13 23:36:00.995: E/AndroidRuntime(8310): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
02-13 23:36:00.995: E/AndroidRuntime(8310): at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 23:36:00.995: E/AndroidRuntime(8310): at android.os.Looper.loop(Looper.java:137)
02-13 23:36:00.995: E/AndroidRuntime(8310): at android.app.ActivityThread.main(ActivityThread.java:4511)
02-13 23:36:00.995: E/AndroidRuntime(8310): at java.lang.reflect.Method.invokeNative(Native Method)
02-13 23:36:00.995: E/AndroidRuntime(8310): at java.lang.reflect.Method.invoke(Method.java:511)
02-13 23:36:00.995: E/AndroidRuntime(8310): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
02-13 23:36:00.995: E/AndroidRuntime(8310): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
02-13 23:36:00.995: E/AndroidRuntime(8310): at dalvik.system.NativeStart.main(Native Method)
02-13 23:36:00.995: E/AndroidRuntime(8310): Caused by: java.lang.IllegalArgumentException: Invalid appliation ID:
02-13 23:36:00.995: E/AndroidRuntime(8310): at com.google.android.gms.cast.CastMediaControlIntent.a(Unknown Source)
02-13 23:36:00.995: E/AndroidRuntime(8310): at com.google.android.gms.cast.CastMediaControlIntent.categoryForCast(Unknown Source)
02-13 23:36:00.995: E/AndroidRuntime(8310): at com.google.sample.castcompanionlibrary.cast.BaseCastManager.<init>(BaseCastManager.java:183)
02-13 23:36:00.995: E/AndroidRuntime(8310): at com.google.sample.castcompanionlibrary.cast.VideoCastManager.<init>(VideoCastManager.java:215)
02-13 23:36:00.995: E/AndroidRuntime(8310): at com.google.sample.castcompanionlibrary.cast.VideoCastManager.initialize(VideoCastManager.java:168)
02-13 23:36:00.995: E/AndroidRuntime(8310): at com.google.sample.cast.refplayer.CastApplication.getCastManager(CastApplication.java:51)
02-13 23:36:00.995: E/AndroidRuntime(8310): at com.google.sample.cast.refplayer.VideoBrowserActivity.onCreate(VideoBrowserActivity.java:55)
02-13 23:36:00.995: E/AndroidRuntime(8310): at android.app.Activity.performCreate(Activity.java:4470)
02-13 23:36:00.995: E/AndroidRuntime(8310): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
02-13 23:36:00.995: E/AndroidRuntime(8310): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
02-13 23:36:00.995: E/AndroidRuntime(8310): ... 11 more
02-13 23:36:01.115: D/dalvikvm(8310): GC_CONCURRENT freed 168K, 3% free 13426K/13831K, paused 7ms+7ms
02-13 23:36:01.305: I/Process(8310): Sending signal. PID: 8310 SIG: 9
答案 0 :(得分:4)
最好的方法是创建自己的接收器(Styled Media Receiver)。当您注册时,您会获得一个应用ID;我建议您访问Cast developers网站,熟悉Chromecast及其工作原理。获得应用程序ID后,您需要将其插入res / values / string.xml,其中YOUR_APP_ID字符串为。
答案 1 :(得分:4)
删除引号:
- CastMediaControlIntent.categoryForCast("CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID")
+ CastMediaControlIntent.categoryForCast(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID)
答案 2 :(得分:0)
如果使用默认媒体接收器,则不必注册应用程序。检查此Changelog页。
您可以在CastOptionsProvider中添加默认的应用程序ID,如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"
/link> <script
src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
crossorigin="anonymous"></script>
<title>ReqRes</title>
</head>
<body>
<div class="container my-5">
<div class="text-center">
<h1 class="display-4 text-center mb-3 h1 font-weight-bold">Assignment</h1>
<button class="btn btn-primary my-3" id="get">GET</button>
<button class="btn btn-info" id="post">POST</button>
<button class="btn btn-warning" id="update">PUT</button>
<button class="btn btn-danger" id="delete">DELETE</button>
</div>
<hr>
<div id="res"></div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js"></script>
<script src="start.js"></script>
</body>
</html>