Created
December 29, 2020 08:27
-
-
Save melikeeroglu/5d0ae4b69b12bf237f1d4778a1b5a6fe to your computer and use it in GitHub Desktop.
HmsDriveActivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.melike.drive.huawei; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.provider.MediaStore; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Button; | |
import com.unity3d.player.UnityPlayerActivity; | |
import java.io.IOException; | |
import java.io.InputStream; | |
public class HmsDriveActivity extends UnityPlayerActivity { | |
GalleryListener myListener; | |
void getImageInputStreamFromGallery(GalleryListener listener) { | |
myListener = listener; | |
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); | |
intent.setType("image/*"); | |
startActivityForResult(intent, 1); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if(resultCode == Activity.RESULT_OK && requestCode == 1) { | |
try { | |
String mimeType = getContentResolver().getType(data.getData()); | |
InputStream inputStream = getContentResolver().openInputStream(data.getData()); | |
int size = inputStream.available(); | |
myListener.getGalleryUri(inputStream, mimeType, size); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
interface GalleryListener { | |
void getGalleryUri(InputStream inputStream, String mimeType, int size); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment