2016-04-07 2 views
0

Я создал простое приложение, которое использует CastCompanionLibrary для потоковой передачи видеофайлов на устройство Google ChromeCast. Все работает нормально, но я обнаружил, что при загрузке телефона без подключения к Интернету происходит сбой приложения. Я попытался поймать ошибку на мониторе АБР.VideoCastManager разбивает Android-приложение на загрузку телефона

java.lang.RuntimeException: Unable to start receiver com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver: java.lang.IllegalStateException: No VideoCastManager instance was found, did you forget to initialize it? 

Что заставляет меня задаться вопросом, почему мое приложение начинается с загрузки телефона вообще? Он должен был запускаться только тогда, когда пользователь запускает его.

Однако после некоторых копаний я считаю, что это связано с упомянутой ранее CastCompanionLibrary, которая регистрирует некоторые службы и приемники, используя файл манифеста.

Manifest.xml часть

<activity 
     android:name="com.google.android.libraries.cast.companionlibrary.cast.player.VideoCastControllerActivity" 
     android:screenOrientation="portrait" 
     android:label="@string/app_name" 
     android:launchMode="singleTask" 
     android:parentActivityName="lv.test.myapp.MainActivity" 
     android:theme="@style/Theme.AppCompat.Light.NoActionBar"> 
     <meta-data 
      android:name="android.support.PARENT_ACTIVITY" 
      android:value="lv.test.myapp.MainActivity" /> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
     </intent-filter> 
    </activity> 
    <receiver android:name="com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver" > 
     <intent-filter> 
      <action android:name="android.media.AUDIO_BECOMING_NOISY" /> 
      <action android:name="android.intent.action.MEDIA_BUTTON" /> 
      <action android:name="com.google.android.libraries.cast.companionlibrary.action.toggleplayback" /> 
      <action android:name="com.google.android.libraries.cast.companionlibrary.action.stop" /> 
     </intent-filter> 
    </receiver> 
    <service 
     android:name="com.google.android.libraries.cast.companionlibrary.notification.VideoCastNotificationService" 
     android:exported="false" > 
     <intent-filter> 
      <action 
       android:name="com.google.android.libraries.cast.companionlibrary.action.notificationvisibility" /> 
     </intent-filter> 
    </service> 
    <service 
     android:name="com.google.android.libraries.cast.companionlibrary.cast.reconnection.ReconnectionService"/> 
    <receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver" 
     android:enabled="true"> 
     <intent-filter> 
      <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" /> 
     </intent-filter> 
    </receiver> 

Mainactivity часть

public VideoCastManager mCastManager;  
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

//id changed for public use 

    CastConfiguration options = new CastConfiguration.Builder("000000") 
.enableAutoReconnect() 
.enableLockScreen() 
.enableWifiReconnection() 
.enableNotification() 
.build(); 

    if(mCastManager == null) { 
     VideoCastManager.initialize(this, options); 
    } 
    mCastManager = VideoCastManager.getInstance(); 
//some other not related code here 
} 

Полная ошибка я нашел

04-07 22:12:32.185 5022-5022/? E/AndroidRuntime: FATAL EXCEPTION: main 
              Process: lv.test.myapp, PID: 5022 
              java.lang.RuntimeException: Unable to start receiver com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver: java.lang.IllegalStateException: No VideoCastManager instance was found, did you forget to initialize it? 
               at android.app.ActivityThread.handleReceiver(ActivityThread.java:3114) 
               at android.app.ActivityThread.access$1800(ActivityThread.java:181) 
               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1551) 
               at android.os.Handler.dispatchMessage(Handler.java:102) 
               at android.os.Looper.loop(Looper.java:145) 
               at android.app.ActivityThread.main(ActivityThread.java:6117) 
               at java.lang.reflect.Method.invoke(Native Method) 
               at java.lang.reflect.Method.invoke(Method.java:372) 
               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
               Caused by: java.lang.IllegalStateException: No VideoCastManager instance was found, did you forget to initialize it? 
               at com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager.getInstance(VideoCastManager.java:259) 
               at com.google.android.libraries.cast.companionlibrary.remotecontrol.VideoIntentReceiver.onReceive(VideoIntentReceiver.java:49) 
               at android.app.ActivityThread.handleReceiver(ActivityThread.java:3107) 
               at android.app.ActivityThread.access$1800(ActivityThread.java:181)  
               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1551)  
               at android.os.Handler.dispatchMessage(Handler.java:102)  
               at android.os.Looper.loop(Looper.java:145)  
               at android.app.ActivityThread.main(ActivityThread.java:6117)  
               at java.lang.reflect.Method.invoke(Native Method)  
               at java.lang.reflect.Method.invoke(Method.java:372)  
               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)  
               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)  
04-07 22:12:32.200 2888-3384/? V/ApplicationPolicy: isApplicationStateBlocked userId 0 pkgname lv.test.myapp 

ответ

1

Не знаете, какую версию CCL вы используете, но если вы используете недавний, вы должны обновить манифест, чтобы удалить все фильтры намерений из блока вашего приемника, а также службу. Для получателя, похоже, кто-то пытается вызвать ваш приемник, поэтому, если вы удалите фильтры намерений, он станет частным для вашего приложения и не столкнется с такой проблемой.

+0

Что делать, если вы используете пользовательский VideoIntentReceiver? – Gi0rgi0s