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
4f4147d0
Commit
4f4147d0
authored
Dec 10, 2015
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #588 crash when basename & extension can't be extracted
parent
52054f5d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
45 deletions
+43
-45
CHANGELOG.md
CHANGELOG.md
+1
-0
AssetUtil.java
src/android/notification/AssetUtil.java
+42
-45
No files found.
CHANGELOG.md
View file @
4f4147d0
...
@@ -5,6 +5,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo
...
@@ -5,6 +5,7 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo
#### Version 0.8.3 (not yet released)
#### Version 0.8.3 (not yet released)
-
New "quarter" intervall for iOS & Android
-
New "quarter" intervall for iOS & Android
-
Fixed #588 crash when basename & extension can't be extracted (Android)
-
Fixed #732 loop between update and trigger (Android)
-
Fixed #732 loop between update and trigger (Android)
-
Fixed #710 crash due to >500 notifications (Android)
-
Fixed #710 crash due to >500 notifications (Android)
-
Fixed #682 crash while resuming app from notification (Android 6)
-
Fixed #682 crash while resuming app from notification (Android 6)
...
...
src/android/notification/AssetUtil.java
View file @
4f4147d0
...
@@ -42,6 +42,7 @@ import java.io.OutputStream;
...
@@ -42,6 +42,7 @@ 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
;
import
java.util.UUID
;
/**
/**
* Util class to map unified asset URIs to native URIs. URIs like file:///
* Util class to map unified asset URIs to native URIs. URIs like file:///
...
@@ -152,21 +153,15 @@ class AssetUtil {
...
@@ -152,21 +153,15 @@ class AssetUtil {
* URI pointing to the given path
* URI pointing to the given path
*/
*/
private
Uri
getUriFromAsset
(
String
path
)
{
private
Uri
getUriFromAsset
(
String
path
)
{
File
dir
=
context
.
getExternalCacheDir
();
String
resPath
=
path
.
replaceFirst
(
"file:/"
,
"www"
);
String
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
File
file
=
getTmpFile
(
fileName
);
if
(
dir
==
null
)
{
if
(
file
==
null
)
{
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
return
Uri
.
EMPTY
;
return
Uri
.
EMPTY
;
}
}
String
resPath
=
path
.
replaceFirst
(
"file:/"
,
"www"
);
String
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
String
storage
=
dir
.
toString
()
+
STORAGE_FOLDER
;
File
file
=
new
File
(
storage
,
fileName
);
//noinspection ResultOfMethodCallIgnored
new
File
(
storage
).
mkdir
();
try
{
try
{
AssetManager
assets
=
context
.
getAssets
();
AssetManager
assets
=
context
.
getAssets
();
FileOutputStream
outStream
=
new
FileOutputStream
(
file
);
FileOutputStream
outStream
=
new
FileOutputStream
(
file
);
...
@@ -197,29 +192,19 @@ class AssetUtil {
...
@@ -197,29 +192,19 @@ class AssetUtil {
* URI pointing to the given path
* URI pointing to the given path
*/
*/
private
Uri
getUriForResourcePath
(
String
path
)
{
private
Uri
getUriForResourcePath
(
String
path
)
{
File
dir
=
context
.
getExternalCacheDir
();
if
(
dir
==
null
)
{
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
return
Uri
.
EMPTY
;
}
String
resPath
=
path
.
replaceFirst
(
"res://"
,
""
);
String
resPath
=
path
.
replaceFirst
(
"res://"
,
""
);
int
resId
=
getResIdForDrawable
(
resPath
);
int
resId
=
getResIdForDrawable
(
resPath
);
File
file
=
getTmpFile
();
if
(
resId
==
0
)
{
if
(
resId
==
0
)
{
Log
.
e
(
"Asset"
,
"File not found: "
+
resPath
);
Log
.
e
(
"Asset"
,
"File not found: "
+
resPath
);
return
Uri
.
EMPTY
;
return
Uri
.
EMPTY
;
}
}
String
resName
=
extractResourceName
(
resPath
);
if
(
file
==
null
)
{
String
extName
=
extractResourceExtension
(
resPath
);
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
String
storage
=
dir
.
toString
()
+
STORAGE_FOLDER
;
return
Uri
.
EMPTY
;
File
file
=
new
File
(
storage
,
resName
+
extName
);
}
//noinspection ResultOfMethodCallIgnored
new
File
(
storage
).
mkdir
();
try
{
try
{
Resources
res
=
context
.
getResources
();
Resources
res
=
context
.
getResources
();
...
@@ -249,21 +234,13 @@ class AssetUtil {
...
@@ -249,21 +234,13 @@ class AssetUtil {
* Uri of the downloaded file
* Uri of the downloaded file
*/
*/
private
Uri
getUriFromRemote
(
String
path
)
{
private
Uri
getUriFromRemote
(
String
path
)
{
File
dir
=
context
.
getExternalCacheDir
();
File
file
=
getTmpFile
();
if
(
dir
==
null
)
{
if
(
file
==
null
)
{
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
return
Uri
.
EMPTY
;
return
Uri
.
EMPTY
;
}
}
String
resName
=
extractResourceName
(
path
);
String
extName
=
extractResourceExtension
(
path
);
String
storage
=
dir
.
toString
()
+
STORAGE_FOLDER
;
File
file
=
new
File
(
storage
,
resName
+
extName
);
//noinspection ResultOfMethodCallIgnored
new
File
(
storage
).
mkdir
();
try
{
try
{
URL
url
=
new
URL
(
path
);
URL
url
=
new
URL
(
path
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
...
@@ -343,7 +320,7 @@ class AssetUtil {
...
@@ -343,7 +320,7 @@ class AssetUtil {
* Resource path as string
* Resource path as string
*/
*/
int
getResIdForDrawable
(
String
clsName
,
String
resPath
)
{
int
getResIdForDrawable
(
String
clsName
,
String
resPath
)
{
String
drawable
=
extractResourc
eName
(
resPath
);
String
drawable
=
getBas
eName
(
resPath
);
int
resId
=
0
;
int
resId
=
0
;
try
{
try
{
...
@@ -396,7 +373,7 @@ class AssetUtil {
...
@@ -396,7 +373,7 @@ class AssetUtil {
* @param resPath
* @param resPath
* Resource path as string
* Resource path as string
*/
*/
private
String
extractResourc
eName
(
String
resPath
)
{
private
String
getBas
eName
(
String
resPath
)
{
String
drawable
=
resPath
;
String
drawable
=
resPath
;
if
(
drawable
.
contains
(
"/"
))
{
if
(
drawable
.
contains
(
"/"
))
{
...
@@ -411,19 +388,39 @@ class AssetUtil {
...
@@ -411,19 +388,39 @@ class AssetUtil {
}
}
/**
/**
*
Extract extension of drawable resource from path
.
*
Returns a file located under the external cache dir of that app
.
*
*
* @
param resPath
* @
return
*
Resource path as string
*
File with a random UUID name
*/
*/
private
String
extractResourceExtension
(
String
resPath
)
{
private
File
getTmpFile
()
{
String
extName
=
"png"
;
// If random UUID is not be enough see
// https://github.com/LukePulverenti/cordova-plugin-local-notifications/blob/267170db14044cbeff6f4c3c62d9b766b7a1dd62/src/android/notification/AssetUtil.java#L255
return
getTmpFile
(
UUID
.
randomUUID
().
toString
());
}
if
(
resPath
.
contains
(
"."
))
{
/**
extName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'.'
));
* Returns a file located under the external cache dir of that app.
*
* @param name
* The name of the file
* @return
* File with the provided name
*/
private
File
getTmpFile
(
String
name
)
{
File
dir
=
context
.
getExternalCacheDir
();
if
(
dir
==
null
)
{
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
return
null
;
}
}
return
extName
;
String
storage
=
dir
.
toString
()
+
STORAGE_FOLDER
;
//noinspection ResultOfMethodCallIgnored
new
File
(
storage
).
mkdir
();
return
new
File
(
storage
,
name
);
}
}
/**
/**
...
...
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