How to upload an audio file (wav) to Google Drive
UPDATED SOLUTION BELOW
After searching and I found out some demo codes from google quickstart demo and it worked great for image https://github.com/googledrive/android-quickstart
Now I want to go further trying to upload wav file to google drive ... I have some basic knowledge of Android coding, so I try my best to figure it out myself until I get stuck.
Here are my codes.
First, I show a list of WAV files on the user's phone
for(File singleFile : files){
if(singleFile.isDirectory() && !singleFile.isHidden()){
al.addAll(Songs(singleFile));
}
else{
if(singleFile.getName().endsWith(".wav") || singleFile.getName().endsWith(".WAV")){
al.add(singleFile);
}
}
}
Next I will try to force the user to select the wav file they want to download
ArrayAdapter<String> adp = new ArrayAdapter<String>(getApplicationContext(),R.layout.songs,R.id.song,items);
listView.setAdapter(adp);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(bytes==null) {
startActivity(new Intent(getApplicationContext(), MainActivity.class).putExtra("pos", position).putExtra("songlist", Songs));
}
}
});
}
after that i am trying to use this to get the position and data of the selected song.
Intent i = getIntent();
Bundle b = i.getExtras();
Songs = (ArrayList) b.getParcelableArrayList("songlist");
position = b.getInt("pos",0);
u = Uri.parse(Songs.get(position).toString());
This is where I am stuck, I am not sure if I am in the right direction to successfully download the wav file to disk. Disclaimer, all my codes are adapted from my past codes that show a list of wav files and select it to play. so I could be wrong from the start, but I need some guidance for what I should do next, I'm not sure about converting the file to bytes / string and storing in the output stream.
I really hope someone leads me as I have searched the last two weeks about this.
Thank.
** UPDATE **
Hello guys, I found another way to upload to google drive. And I would like to share with everyone. This is a continuation of my codes from above. Here is the code.
First you will get the name of the wav file you want to select.
final String name = Songs.get(position).getName();
Then you put it in multiple lines of code.
Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), name));
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_TEXT, "Content");
share.putExtra(Intent.EXTRA_STREAM, uri );
share.setType("audio/*");
startActivity(Intent.createChooser(share, "Share Sound File"));
In this part, you can share all applications that allow you to share wav / audio files, and Google Drive is one of them.
Hope it works for you too. Enjoy
source to share
No one has answered this question yet
Check out similar questions: