Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

Commit

Permalink
File provider fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iamSahdeep committed Jun 9, 2019
1 parent 987659d commit ac0bcf8
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@
</intent-filter>
</activity>
<activity android:name=".Activities.PlayerView" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.sahdeepsingh.Bop"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_provider_paths" />
</provider>

</application>

</manifest>
14 changes: 9 additions & 5 deletions app/src/main/java/com/sahdeepsingh/Bop/BopUtils/ExtraUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.sahdeepsingh.Bop.fragments.SongDetailsFragment;
import com.sahdeepsingh.Bop.playerMain.Main;

import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand All @@ -31,6 +32,7 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.palette.graphics.Palette;

public class ExtraUtils {
Expand Down Expand Up @@ -127,11 +129,13 @@ public static int getThemeColor(Context context, int colorPrimary, int dkgray) {
}

public static void shareSong(Context context, Song song) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("content:///" + song.getFilePath()));
context.startActivity(Intent.createChooser(share, "Share Sound File"));
context.getContentResolver().notifyChange(Uri.parse("content://media"), null);

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("audio/*");
Uri fileUri = FileProvider.getUriForFile(context, "com.sahdeepsingh.Bop", new File(song.getFilePath()));
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
context.startActivity(Intent.createChooser(shareIntent, "Share File"));
}

public static void showSongDetails(Context context, Long id) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sahdeepsingh.Bop.fragments;


import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
Expand All @@ -15,8 +17,11 @@
import com.sahdeepsingh.Bop.SongData.Song;
import com.squareup.picasso.Picasso;

import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;

import java.io.File;

public class SongDetailsFragment extends Fragment {

private static final String Songparam = "param1";
Expand Down Expand Up @@ -102,6 +107,7 @@ private void addtoPlaylist(View v) {
}

private void shareSong(View v) {
ExtraUtils.shareSong(v.getContext(),song);

}

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/file_provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="Share Audio" path="audio/" />
</paths>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.4.1'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Mar 11 22:43:13 IST 2019
#Thu May 30 18:51:28 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 comments on commit ac0bcf8

Please sign in to comment.