blob: 6f1cf310d6e50690f78daae7bf0e6488d33a385f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
package github.daneren2005.dsub.util.compat;
import android.content.Context;
import androidx.mediarouter.media.MediaRouter;
import android.util.Log;
import com.google.android.gms.cast.CastDevice;
import com.google.android.gms.cast.CastMediaControlIntent;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.security.ProviderInstaller;
import static com.google.android.gms.cast.CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID;
import github.daneren2005.dsub.service.ChromeCastController;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.service.RemoteController;
import github.daneren2005.dsub.util.EnvironmentVariables;
public final class GoogleCompat {
private static final String TAG = GoogleCompat.class.getSimpleName();
public static boolean playServicesAvailable(Context context){
int result = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
if(result != ConnectionResult.SUCCESS){
Log.w(TAG, "No play services, failed with result: " + result);
return false;
}
return true;
}
public static void installProvider(Context context) throws Exception{
ProviderInstaller.installIfNeeded(context);
}
public static String castApplicationId() {
if (EnvironmentVariables.CAST_APPLICATION_ID != null) {
return EnvironmentVariables.CAST_APPLICATION_ID;
} else {
return DEFAULT_MEDIA_RECEIVER_APPLICATION_ID;
}
}
public static boolean castAvailable() {
if (castApplicationId() == DEFAULT_MEDIA_RECEIVER_APPLICATION_ID) {
Log.i(TAG, "Using DEFAULT_MEDIA_RECEIVER_APPLICATION_ID for casting");
}
try {
Class.forName("com.google.android.gms.cast.CastDevice");
} catch (Exception ex) {
Log.w(TAG, "Chromecast library not available");
return false;
}
return true;
}
public static RemoteController getController(DownloadService downloadService, MediaRouter.RouteInfo info) {
CastDevice device = CastDevice.getFromBundle(info.getExtras());
if(device != null) {
return new ChromeCastController(downloadService, device);
} else {
return null;
}
}
public static String getCastControlCategory() {
return CastMediaControlIntent.categoryForCast(castApplicationId());
}
}
|