Skip to content

Instantly share code, notes, and snippets.

@frzleaf
Created October 19, 2015 11:56
Show Gist options
  • Save frzleaf/a3bc334f547a6d834923 to your computer and use it in GitHub Desktop.
Save frzleaf/a3bc334f547a6d834923 to your computer and use it in GitHub Desktop.
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