Skip to content

Commit

Permalink
check for null
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmet Inan committed Aug 6, 2023
1 parent 0350f70 commit caf830c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions app/src/main/java/com/aicodix/assempix/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@

package com.aicodix.assempix;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.ShareActionProvider;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.MenuItemCompat;

import android.Manifest;
import android.content.ContentResolver;
import android.content.ContentValues;
Expand All @@ -41,6 +32,15 @@
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.ShareActionProvider;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.MenuItemCompat;

import com.aicodix.assempix.databinding.ActivityMainBinding;

import java.io.File;
Expand Down Expand Up @@ -201,9 +201,17 @@ private void storePayload(String mime, String suffix, Date date) {
values.put(MediaStore.Images.ImageColumns.MIME_TYPE, mime);
ContentResolver resolver = getContentResolver();
Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
if (uri == null) {
statusMessage(R.string.storing_picture_failed);
return;
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
try {
ParcelFileDescriptor descriptor = getContentResolver().openFileDescriptor(uri, "w");
if (descriptor == null) {
statusMessage(R.string.storing_picture_failed);
return;
}
FileOutputStream stream = new FileOutputStream(descriptor.getFileDescriptor());
stream.write(payload);
stream.close();
Expand Down

0 comments on commit caf830c

Please # to comment.