Reputation: 385
Say i want to upload a picture or a text document
when i click on the button to chose the file
how do i make it so that it shows a bunch a popup of applications i can chose from to look at files and select on for the upload as in this picture
i currently have this
public void sendFile(View view) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
startActivityForResult(intent, READ_REQUEST_CODE);
}
but this goes straight to documents and doesn't let me choose an application like gallery or MEGA
any idea on how to implement this?
Upvotes: 0
Views: 1951
Reputation: 321
You have to understand that file selection has to be done via the Android system's File Picker. Other apps like drive and Dropbox will be listen on the navigation drawer on the left. Mega should have code inside it so that it's content is visible in the Android system's File Picker. That is how it is supposed to be. Android made the file picking process unified.
It's not the case while sharing a file though. In that case you would get option to choose from like the screenshot you posted
Upvotes: 0
Reputation: 690
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class AndroidPick_a_File extends Activity {
TextView textFile;
private static final int PICKFILE_RESULT_CODE = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonPick = (Button)findViewById(R.id.buttonpick);
textFile = (TextView)findViewById(R.id.textfile);
buttonPick.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent,PICKFILE_RESULT_CODE);
}});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
switch(requestCode){
case PICKFILE_RESULT_CODE:
if(resultCode==RESULT_OK){
String FilePath = data.getData().getPath();
textFile.setText(FilePath);
}
break;
}
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/buttonpick"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="- PICK a file -"
/>
<TextView
android:id="@+id/textfile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Upvotes: 2