所以我有這個程序,當你按下一個按鈕,它可以讓你選擇一個文件,並將其分享到允許共享(最好是谷歌驅動器)的任何應用程序無法與Android應用程序共享音頻文件
然而,我只能選擇一個文件,並且應用程序選擇不會出現,因此我可以選擇一個應用程序來發送文件。
此外,該文件也以.3gpp格式保存。
我的代碼:
import java.util.List;
import android.os.Build;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
Button cameraButton;
Button recordSoundButton;
Button launchGallery;
Button AudioViewer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cameraButton = (Button)findViewById(R.id.cameraButton); //create buttons and check for ids
cameraButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
takeAPhoto();
}
});
recordSoundButton = (Button)findViewById(R.id.recordSoundButton);
recordSoundButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
OpenUpRecordSound();
}//end openRecord Sound
});//end record sound button listener
launchGallery = (Button)findViewById(R.id.PhotoViewer);
launchGallery.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
LaunchUpAPhotoGallery();
}
});//end launch Gallery button listener
AudioViewer = (Button)findViewById(R.id.AudioViewer);
AudioViewer.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
LaunchFileManager();
}//end on click
});//end audio viewer listener
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// For the main activity, make sure the app icon in the action bar
// does not behave as a button
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
} //end if
} //end onCreate
public void OpenUpRecordSound(){
startActivity(new Intent(MainActivity.this, RecordASound.class));
}//end openupRecord sound
public void takeAPhoto(){
//fire up the camera app on the phone
Intent i = new Intent();
i.setAction(Intent.ACTION_CAMERA_BUTTON);
i.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_CAMERA));
sendOrderedBroadcast(i, null);
// Ensure that there is a camera app on the phone!
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(i, 0);
boolean isIntentSafe = activities.size() > 0;
// Start an activity if it's safe
if (isIntentSafe) {
startActivity(i);
}//end if
}//end takeAPhoto
public void LaunchUpAPhotoGallery(){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("image/*");
startActivity(intent);
}//end Photo launcher handler thingy
public void LaunchFileManager(){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivity(Intent.createChooser(intent, "Share the sound file"));
}//end launch file manager
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}