The documentation says "Callers can set a document URI through EXTRA_INITIAL_URI
to indicate the initial location of documents navigator."
But it won't resolve EXTRA_INITIAL_URI
here. I tried setting the constant given for this as shown in the comment (EXTRA_INITIAL_URI = "android.provider.extra.INITIAL_URI"
), but that does not work. How do I get it to resolve?
package com.ship.saftwo;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.io.File;
public class MainActivity extends AppCompatActivity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {navigateToAppDirectory();}});}
private static final int READ_REQUEST_CODE = 42;
// adding this does not help: public static final String EXTRA_INITIAL_URI = "android.provider.extra.INITIAL_URI";
public void navigateToAppDirectory() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + File.separator + getResources().getString(R.string.app_name) + File.separator);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_INITIAL_URI, uri);
//error message: Cannot resolve symbol 'EXTRA_INITIAL_URI'
startActivityForResult(intent, READ_REQUEST_CODE);
}
}