【发布时间】:2014-04-21 16:09:19
【问题描述】:
所以我有这个应用程序,当你按下一个按钮时,它允许你选择一个文件,并将它分享到任何允许共享的应用程序(最好是谷歌驱动器)
但是,我只能选择一个文件,并且没有出现让我选择将文件发送到的应用程序的应用程序选择。
此外,该文件也以 .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;
}
}
【问题讨论】:
标签: android audio google-drive-api share