open file explorer in android programmatically

Solutions on MaxInterview for open file explorer in android programmatically by the best coders in the world

showing results for - "open file explorer in android programmatically"
Hannah
25 Jun 2016
1package com.android_examples.pickfile_android_examplescom;
2import android.content.Intent;
3import android.support.v7.app.AppCompatActivity;
4import android.os.Bundle;
5import android.view.View;
6import android.widget.Button;
7import android.widget.Toast;
8
9public class MainActivity extends AppCompatActivity {
10
11    Button button ;
12    Intent intent ;
13    @Override
14    protected void onCreate(Bundle savedInstanceState) {
15        super.onCreate(savedInstanceState);
16        setContentView(R.layout.activity_main);
17
18        button = (Button)findViewById(R.id.button) ;
19
20        button.setOnClickListener(new View.OnClickListener() {
21            @Override
22            public void onClick(View v) {
23
24                intent = new Intent(Intent.ACTION_GET_CONTENT);
25                intent.setType("*/*");
26                startActivityForResult(intent, 7);
27
28            }
29        });
30
31    }
32
33    @Override
34    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
35        // TODO Auto-generated method stub
36
37        switch(requestCode){
38
39            case 7:
40
41                if(resultCode==RESULT_OK){
42
43                    String PathHolder = data.getData().getPath();
44
45                    Toast.makeText(MainActivity.this, PathHolder , Toast.LENGTH_LONG).show();
46
47                }
48                break;
49
50        }
51    }
52
53}