Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
af00d91f
authored
Mar 23, 2020
by
olly
Committed by
Oliver Woodman
Mar 25, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Request storage permission if missing
PiperOrigin-RevId: 302345647
parent
6927192a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
3 deletions
demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java
demos/main/src/main/java/com/google/android/exoplayer2/demo/SampleChooserActivity.java
View file @
af00d91f
...
@@ -35,6 +35,7 @@ import android.widget.ExpandableListView.OnChildClickListener;
...
@@ -35,6 +35,7 @@ import android.widget.ExpandableListView.OnChildClickListener;
import
android.widget.ImageButton
;
import
android.widget.ImageButton
;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.app.AppCompatActivity
;
import
com.google.android.exoplayer2.ParserException
;
import
com.google.android.exoplayer2.ParserException
;
...
@@ -66,6 +67,7 @@ public class SampleChooserActivity extends AppCompatActivity
...
@@ -66,6 +67,7 @@ public class SampleChooserActivity extends AppCompatActivity
private
static
final
String
GROUP_POSITION_PREFERENCE_KEY
=
"SAMPLE_CHOOSER_GROUP_POSITION"
;
private
static
final
String
GROUP_POSITION_PREFERENCE_KEY
=
"SAMPLE_CHOOSER_GROUP_POSITION"
;
private
static
final
String
CHILD_POSITION_PREFERENCE_KEY
=
"SAMPLE_CHOOSER_CHILD_POSITION"
;
private
static
final
String
CHILD_POSITION_PREFERENCE_KEY
=
"SAMPLE_CHOOSER_CHILD_POSITION"
;
private
String
[]
uris
;
private
boolean
useExtensionRenderers
;
private
boolean
useExtensionRenderers
;
private
DownloadTracker
downloadTracker
;
private
DownloadTracker
downloadTracker
;
private
SampleAdapter
sampleAdapter
;
private
SampleAdapter
sampleAdapter
;
...
@@ -86,7 +88,6 @@ public class SampleChooserActivity extends AppCompatActivity
...
@@ -86,7 +88,6 @@ public class SampleChooserActivity extends AppCompatActivity
Intent
intent
=
getIntent
();
Intent
intent
=
getIntent
();
String
dataUri
=
intent
.
getDataString
();
String
dataUri
=
intent
.
getDataString
();
String
[]
uris
;
if
(
dataUri
!=
null
)
{
if
(
dataUri
!=
null
)
{
uris
=
new
String
[]
{
dataUri
};
uris
=
new
String
[]
{
dataUri
};
}
else
{
}
else
{
...
@@ -110,8 +111,7 @@ public class SampleChooserActivity extends AppCompatActivity
...
@@ -110,8 +111,7 @@ public class SampleChooserActivity extends AppCompatActivity
DemoApplication
application
=
(
DemoApplication
)
getApplication
();
DemoApplication
application
=
(
DemoApplication
)
getApplication
();
useExtensionRenderers
=
application
.
useExtensionRenderers
();
useExtensionRenderers
=
application
.
useExtensionRenderers
();
downloadTracker
=
application
.
getDownloadTracker
();
downloadTracker
=
application
.
getDownloadTracker
();
SampleListLoader
loaderTask
=
new
SampleListLoader
();
loadSample
();
loaderTask
.
execute
(
uris
);
// Start the download service if it should be running but it's not currently.
// Start the download service if it should be running but it's not currently.
// Starting the service in the foreground causes notification flicker if there is no scheduled
// Starting the service in the foreground causes notification flicker if there is no scheduled
...
@@ -162,6 +162,37 @@ public class SampleChooserActivity extends AppCompatActivity
...
@@ -162,6 +162,37 @@ public class SampleChooserActivity extends AppCompatActivity
sampleAdapter
.
notifyDataSetChanged
();
sampleAdapter
.
notifyDataSetChanged
();
}
}
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
@NonNull
String
[]
permissions
,
@NonNull
int
[]
grantResults
)
{
if
(
grantResults
.
length
==
0
)
{
// Empty results are triggered if a permission is requested while another request was already
// pending and can be safely ignored in this case.
return
;
}
if
(
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
loadSample
();
}
else
{
Toast
.
makeText
(
getApplicationContext
(),
R
.
string
.
sample_list_load_error
,
Toast
.
LENGTH_LONG
)
.
show
();
finish
();
}
}
private
void
loadSample
()
{
Assertions
.
checkNotNull
(
uris
);
for
(
int
i
=
0
;
i
<
uris
.
length
;
i
++)
{
Uri
uri
=
Uri
.
parse
(
uris
[
i
]);
if
(
Util
.
maybeRequestReadExternalStoragePermission
(
this
,
uri
))
{
return
;
}
}
SampleListLoader
loaderTask
=
new
SampleListLoader
();
loaderTask
.
execute
(
uris
);
}
private
void
onSampleGroups
(
final
List
<
SampleGroup
>
groups
,
boolean
sawError
)
{
private
void
onSampleGroups
(
final
List
<
SampleGroup
>
groups
,
boolean
sawError
)
{
if
(
sawError
)
{
if
(
sawError
)
{
Toast
.
makeText
(
getApplicationContext
(),
R
.
string
.
sample_list_load_error
,
Toast
.
LENGTH_LONG
)
Toast
.
makeText
(
getApplicationContext
(),
R
.
string
.
sample_list_load_error
,
Toast
.
LENGTH_LONG
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment