Catch IllegalArgumentException when trying to insert an entry to TvContract.Channels.CONTENT_URI

HarmonyOS has FEATURE_LEANBACK but doesn't support this URI
This commit is contained in:
Cameron Gutman 2020-11-10 10:46:39 -06:00
parent 34a1697d50
commit 9d8df04c5c

View File

@ -77,8 +77,18 @@ public class TvChannelHelper {
return; return;
} }
Uri channelUri = context.getContentResolver().insert( Uri channelUri;
TvContract.Channels.CONTENT_URI, builder.toContentValues());
try {
channelUri = context.getContentResolver().insert(
TvContract.Channels.CONTENT_URI, builder.toContentValues());
} catch (IllegalArgumentException e) {
// This can happen on HarmonyOS devices which report to
// support Leanback APIs, yet don't implement this URI
e.printStackTrace();
return;
}
if (channelUri != null) { if (channelUri != null) {
long id = ContentUris.parseId(channelUri); long id = ContentUris.parseId(channelUri);
updateChannelIcon(id); updateChannelIcon(id);
@ -144,8 +154,15 @@ public class TvChannelHelper {
return; return;
} }
context.getContentResolver().insert(TvContract.PreviewPrograms.CONTENT_URI, try {
builder.toContentValues()); context.getContentResolver().insert(TvContract.PreviewPrograms.CONTENT_URI,
builder.toContentValues());
} catch (IllegalArgumentException e) {
// This can happen on HarmonyOS devices which report to
// support Leanback APIs, yet don't implement this URI
e.printStackTrace();
return;
}
TvContract.requestChannelBrowsable(context, channelId); TvContract.requestChannelBrowsable(context, channelId);
} }