Re-added new download opener

This commit is contained in:
Caesar2011
2018-11-08 20:39:07 +01:00
parent 57ce9ffa26
commit 518ae756b1
3 changed files with 25 additions and 4 deletions

View File

@@ -24,6 +24,15 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.my.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application> </application>
</manifest> </manifest>

View File

@@ -15,6 +15,7 @@ import java.util.Arrays;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;
import de.sebse.fuplanner.MainActivity; import de.sebse.fuplanner.MainActivity;
import de.sebse.fuplanner.R; import de.sebse.fuplanner.R;
import de.sebse.fuplanner.services.KVV.types.Resource; import de.sebse.fuplanner.services.KVV.types.Resource;
@@ -55,7 +56,7 @@ public class Download {
if (file.getModifiedDate() != 0) { if (file.getModifiedDate() != 0) {
if (!message.isEmpty()) if (!message.isEmpty())
message += "\n"; message += "\n";
resources.getString(R.string.last_modified_on, UtilsDate.getModifiedDateTime(contextInterface.get(), file.getModifiedDate())); message += resources.getString(R.string.last_modified_on, UtilsDate.getModifiedDateTime(contextInterface.get(), file.getModifiedDate()));
} }
alertDialogBuilder alertDialogBuilder
@@ -181,9 +182,17 @@ public class Download {
} }
private void fileOpen(File url){ private void fileOpen(File url){
Uri uri = Uri.fromFile(url);
Intent intent = new Intent();//Intent.ACTION_VIEW Uri uri = FileProvider.getUriForFile(contextInterface.get(), contextInterface.get().getApplicationContext().getPackageName() + ".my.provider", url);
Intent intent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
intent = new Intent(Intent.ACTION_VIEW);
} else {
intent = new Intent();
}
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
// Check what kind of file you are trying to open, by comparing the url with extensions. // Check what kind of file you are trying to open, by comparing the url with extensions.
// When the if condition is matched, plugin sets the correct intent (mime) type, // When the if condition is matched, plugin sets the correct intent (mime) type,
// so Android knew what application to use to open the file // so Android knew what application to use to open the file
@@ -228,7 +237,6 @@ public class Download {
//so you can choose which application to use //so you can choose which application to use
intent.setDataAndType(uri, "*/*"); intent.setDataAndType(uri, "*/*");
} }
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
contextInterface.get().startActivity(intent); contextInterface.get().startActivity(intent);

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="."/>
</paths>