Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cordova-plugin-local-notifications
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nabil Sadki
cordova-plugin-local-notifications
Commits
cb6db05d
Commit
cb6db05d
authored
Feb 14, 2018
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow query in file path to avoid conflict with Windows
parent
a75c0979
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
23 deletions
+19
-23
AssetUtil.java
src/android/notification/util/AssetUtil.java
+19
-23
No files found.
src/android/notification/util/AssetUtil.java
View file @
cb6db05d
...
@@ -36,7 +36,6 @@ import java.io.FileNotFoundException;
...
@@ -36,7 +36,6 @@ import java.io.FileNotFoundException;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URL
;
...
@@ -106,7 +105,8 @@ public final class AssetUtil {
...
@@ -106,7 +105,8 @@ public final class AssetUtil {
* @return URI pointing to the given path.
* @return URI pointing to the given path.
*/
*/
private
Uri
getUriFromPath
(
String
path
)
{
private
Uri
getUriFromPath
(
String
path
)
{
String
absPath
=
path
.
replaceFirst
(
"file://"
,
""
);
String
absPath
=
path
.
replaceFirst
(
"file://"
,
""
)
.
replaceFirst
(
"\\?.*$"
,
""
);
File
file
=
new
File
(
absPath
);
File
file
=
new
File
(
absPath
);
if
(!
file
.
exists
())
{
if
(!
file
.
exists
())
{
...
@@ -125,7 +125,8 @@ public final class AssetUtil {
...
@@ -125,7 +125,8 @@ public final class AssetUtil {
* @return URI pointing to the given path.
* @return URI pointing to the given path.
*/
*/
private
Uri
getUriFromAsset
(
String
path
)
{
private
Uri
getUriFromAsset
(
String
path
)
{
String
resPath
=
path
.
replaceFirst
(
"file:/"
,
"www"
);
String
resPath
=
path
.
replaceFirst
(
"file:/"
,
"www"
)
.
replaceFirst
(
"\\?.*$"
,
""
);
String
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
String
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
File
file
=
getTmpFile
(
fileName
);
File
file
=
getTmpFile
(
fileName
);
...
@@ -134,22 +135,16 @@ public final class AssetUtil {
...
@@ -134,22 +135,16 @@ public final class AssetUtil {
try
{
try
{
AssetManager
assets
=
context
.
getAssets
();
AssetManager
assets
=
context
.
getAssets
();
FileOutputStream
outStream
=
new
FileOutputStream
(
file
);
InputStream
in
=
assets
.
open
(
resPath
);
InputStream
inputStream
=
assets
.
open
(
resPath
);
FileOutputStream
out
=
new
FileOutputStream
(
file
);
copyFile
(
in
,
out
);
copyFile
(
inputStream
,
outStream
);
outStream
.
flush
();
outStream
.
close
();
return
getUriFromFile
(
file
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
"Asset"
,
"File not found: assets/"
+
resPath
);
Log
.
e
(
"Asset"
,
"File not found: assets/"
+
resPath
);
e
.
printStackTrace
();
e
.
printStackTrace
();
return
Uri
.
EMPTY
;
}
}
return
Uri
.
EMPTY
;
return
getUriFromFile
(
file
)
;
}
}
/**
/**
...
@@ -203,16 +198,11 @@ public final class AssetUtil {
...
@@ -203,16 +198,11 @@ public final class AssetUtil {
connection
.
setConnectTimeout
(
5000
);
connection
.
setConnectTimeout
(
5000
);
connection
.
connect
();
connection
.
connect
();
InputStream
input
=
connection
.
getInputStream
();
InputStream
in
=
connection
.
getInputStream
();
FileOutputStream
outStream
=
new
FileOutputStream
(
file
);
FileOutputStream
out
=
new
FileOutputStream
(
file
);
copyFile
(
input
,
outStream
);
outStream
.
flush
();
outStream
.
close
();
copyFile
(
in
,
out
);
return
getUriFromFile
(
file
);
return
getUriFromFile
(
file
);
}
catch
(
MalformedURLException
e
)
{
}
catch
(
MalformedURLException
e
)
{
Log
.
e
(
"Asset"
,
"Incorrect URL"
);
Log
.
e
(
"Asset"
,
"Incorrect URL"
);
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -233,13 +223,19 @@ public final class AssetUtil {
...
@@ -233,13 +223,19 @@ public final class AssetUtil {
* @param in The input stream.
* @param in The input stream.
* @param out The output stream.
* @param out The output stream.
*/
*/
private
void
copyFile
(
InputStream
in
,
OutputStream
out
)
throws
IOException
{
private
void
copyFile
(
InputStream
in
,
FileOutputStream
out
)
{
byte
[]
buffer
=
new
byte
[
1024
];
byte
[]
buffer
=
new
byte
[
1024
];
int
read
;
int
read
;
try
{
while
((
read
=
in
.
read
(
buffer
))
!=
-
1
)
{
while
((
read
=
in
.
read
(
buffer
))
!=
-
1
)
{
out
.
write
(
buffer
,
0
,
read
);
out
.
write
(
buffer
,
0
,
read
);
}
}
out
.
flush
();
out
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment