mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Request storage permission if missing
PiperOrigin-RevId: 302345647
This commit is contained in:
parent
6927192a9d
commit
af00d91f79
@ -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
|
|||||||
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
|
|||||||
|
|
||||||
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
|
|||||||
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
|
|||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user