Я работаю над проектом, основанным на глубоком обучении.Где я должен сделать фотографию, и эта фотография должна автоматически отправляться в облако Google, облако Samsung или любой другой облачный сервис.Причина, по которой я хочу, чтобы фотография автоматически отправлялась в облако, заключается в том, что я хочу, чтобы она была загружена другим приложением, и все вычисления на этой фотографии будут выполнены в этом приложении, а результат должен быть отправлен обратно в приложение и отображен наэкран приложения Android, которое я разработал.
Я много искал и не нашел ничего полезного для своих целей.
Вот мой оригинальный код, который делает фотографии:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button Sbutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Sbutton = (Button) findViewById(R.id.Tbutton);
Sbutton.setOnClickListener(this);
getSupportActionBar().hide();
}
@Override
public void onClick(View view) {
Intent Intent3=new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
startActivity(Intent3);
}
Я нашел этот код в Интернете и попробовал его, но он не работает:
private GoogleApiClient mGoogleApiClient;
private Bitmap mBitmapToSave;
private void saveFileToDrive() {
final Bitmap image = mBitmapToSave;
Drive.DriveApi.newDriveContents(mGoogleApiClient)
.setResultCallback(new ResultCallback<DriveContentsResult>() {
@Override
public void onResult(DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
Log.i("ERROR", "Failed to create new contents.");
return;
}
OutputStream outputStream = result.getDriveContents().getOutputStream();
// Write the bitmap data from it.
ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, bitmapStream);
try {
outputStream.write(bitmapStream.toByteArray());
} catch (IOException e1) {
Log.i("ERROR", "Unable to write file contents.");
}
// Create the initial metadata - MIME type and title.
// Note that the user will be able to change the title later.
MetadataChangeSet metadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("image/jpeg").setTitle("Android Photo.png").build();
// Create an intent for the file chooser, and start it.
IntentSender intentSender = Drive.DriveApi
.newCreateFileActivityBuilder()
.setInitialMetadata(metadataChangeSet)
.setInitialDriveContents(result.getDriveContents())
.build(mGoogleApiClient);
try {
startIntentSenderForResult(
intentSender, REQUEST_CODE_CREATOR, null, 0, 0, 0);
} catch (SendIntentException e) {
Log.i("ERROR", "Failed to launch file chooser.");
}
}
});
}
@Override
protected void onResume() {
super.onResume();
if (mGoogleApiClient == null) {
// Create the API client and bind it to an instance variable.
// We use this instance as the callback for connection and connection
// failures.
// Since no account name is passed, the user is prompted to choose.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
// Connect the client. Once connected, the camera is launched.
mGoogleApiClient.connect();
}
@Override
protected void onPause() {
if (mGoogleApiClient != null) {
mGoogleApiClient.disconnect();
}
super.onPause();
}