Created
October 19, 2015 11:56
-
-
Save frzleaf/a3bc334f547a6d834923 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.le.myapplication; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.design.widget.Snackbar; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.Toolbar; | |
import android.view.View; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.widget.Button; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
public static int MA_TRA_VE = 912; // cai nay dat the nao cung duoc | |
TextView tvFile; | |
Button btnPick; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
tvFile = (TextView) findViewById(R.id.textView); | |
btnPick = (Button) findViewById(R.id.button); | |
btnPick.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); | |
intent.setType("*/*"); | |
startActivityForResult(intent, MA_TRA_VE ); | |
} | |
}); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if ( requestCode == MA_TRA_VE ){ | |
// data la file ma minh vua chon. Sau do dung duong dan cua no de | |
// su dung vao muc dich cua minh | |
Uri fileVuaChon = data.getData(); | |
tvFile.setText(fileVuaChon.toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment