Re-added new download opener
This commit is contained in:
@@ -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>
|
||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
4
app/src/main/res/xml/provider_paths.xml
Normal file
4
app/src/main/res/xml/provider_paths.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths>
|
||||||
|
<external-path name="external_files" path="."/>
|
||||||
|
</paths>
|
||||||
Reference in New Issue
Block a user