Choosing photo using new Google Photos app is broken
Below code is working for me to get content URI on latest Google Photos as well.
What i have tried is writing to temp file and return temp image URI, if it has authority in content URI.
You can try same:
private static String getImageUrlWithAuthority(Context context, Uri uri)
{
InputStream is = null;
if (uri.getAuthority() != null)
{
try
{
is = context.getContentResolver().openInputStream(uri);
Bitmap bmp = BitmapFactory.decodeStream(is);
return writeToTempImageAndGetPathUri(context, bmp).toString();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
finally
{
try
{
if (is != null)
{
is.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
return null;
}
private static Uri writeToTempImageAndGetPathUri(Context inContext, Bitmap inImage)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
Unable to pick image from Google Photos app
The issue is that I was not connected to the network so Google Photos was unable to retrieve the selected image. See my response to @adityakamble49.
Selecting photo from new Google Photos app has incorrect orientation
I gave up and used this amazing library instead. Kudos for the work!
https://github.com/coomar2841/image-chooser-library
Pick Image From Gallery Or Google Photos Failing
Try
getPathFromInputStreamUri()
, this will fix the content uri problem from google photo app
Kotlin (UPDATED)
fun getPathFromInputStreamUri(context: Context, uri: Uri): String? {
var filePath: String? = null
uri.authority?.let {
try {
context.contentResolver.openInputStream(uri).use {
val photoFile: File? = createTemporalFileFrom(it)
filePath = photoFile?.path
}
} catch (e: FileNotFoundException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
}
return filePath
}
@Throws(IOException::class)
private fun createTemporalFileFrom(inputStream: InputStream?): File? {
var targetFile: File? = null
return if (inputStream == null) targetFile
else {
var read: Int
val buffer = ByteArray(8 * 1024)
targetFile = createTemporalFile()
FileOutputStream(targetFile).use { out ->
while (inputStream.read(buffer).also { read = it } != -1) {
out.write(buffer, 0, read)
}
out.flush()
}
targetFile
}
}
private fun createTemporalFile(): File = File(getDefaultDirectory(), "tempPicture.jpg")
Java
public static String getPathFromInputStreamUri(Context context, Uri uri) {
InputStream inputStream = null;
String filePath = null;
if (uri.getAuthority() != null) {
try {
inputStream = context.getContentResolver().openInputStream(uri);
File photoFile = createTemporalFileFrom(inputStream);
filePath = photoFile.getPath();
} catch (FileNotFoundException e) {
Logger.printStackTrace(e);
} catch (IOException e) {
Logger.printStackTrace(e);
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
return filePath;
}
private static File createTemporalFileFrom(InputStream inputStream) throws IOException {
File targetFile = null;
if (inputStream != null) {
int read;
byte[] buffer = new byte[8 * 1024];
targetFile = createTemporalFile();
OutputStream outputStream = new FileOutputStream(targetFile);
while ((read = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
outputStream.flush();
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return targetFile;
}
private static File createTemporalFile() {
return new File(Utils.getDefaultDirectory(), "tempPicture.jpg");
}
Not able to pick photos and videos from Google photos app in nexus 5 marshmallow
You can use this to pick all types of Files.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);
Google photos on iPhone, only upload select photos
Follow the below steps in your Iphone.
- Go to app store and download google photos
- Login to your account in google photos now go to settings in google photos there you
will see "BACKUP & SYNC" - Open it and turn-off the Backup & Sync from it.
Now you can upload your photos to google drive
- Sign in your google account
- Click on "+"Sign and create a new folder and give the Name you want.
- After that open that folder and click on the "+"sign it will ask you from where you
want to add photos so click your file destination and select the photos you want to
upload and click upload. - Now if your friends are using Android phone then no worry just generate the share link
and give permission of Read,Write so that they can view and edit the photos or can add
the photos in it.
Let me know whether it worked or not.
Related Topics
Android: How to Make an Activity Return Results to the Activity Which Calls It
Android Studio Stuck on "Gradle: Resolve Dependencies '_Debugcompile'" or 'Detachedconfiguration1'
Create New Project on Android, Error: Studio Unknown Host 'Services.Gradle.Org'
Transparent Alertdialog Has Black Background
Android: Open Activity Without Save into the Stack
How to Create Android Spinner Without Down Triangle on the Right Side of the Widget
How to Determine If an Android Service Is Running in the Foreground
Sqlite Returned an Error Code of 14
Android Toggle Button Custom Look
Android Resources$Notfoundexception: Resource Id #0X7F030027
Getting MAC Address in Android 6.0
Theme/Style Is Not Applied When Inflater Used with Applicationcontext
How to Pass Bundle from Fragment to Fragment
How to Save Scroll Position of Recyclerview in Android
Differencebetween @Id and @+Id