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
3649f4bc
Commit
3649f4bc
authored
Apr 14, 2014
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`image:` accepts remote URLs and local URIs (#76)
parent
14dfd156
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
133 additions
and
20 deletions
+133
-20
CHANGELOG.md
CHANGELOG.md
+1
-0
README.md
README.md
+22
-6
Options.java
src/android/Options.java
+109
-10
Receiver.java
src/android/Receiver.java
+1
-4
No files found.
CHANGELOG.md
View file @
3649f4bc
...
...
@@ -3,6 +3,7 @@
-
[
enhancement:
]
Android 2.x (SDK >= 7) support (Thanks to
**khizarsonu**
)
-
[
enhancement:
]
Scope parameter for
`isScheduled`
and
`getScheduledIds`
-
[
enhancement:
]
Callbacks for
`cancel`
&
`cancelAll`
-
[
enhancement:
]
`image:`
accepts remote URLs and local URIs (Android)
#### Version 0.7.4 (22.03.2014)
-
[
bugfix:
]
Platform specific properties were ignored.
...
...
README.md
View file @
3649f4bc
...
...
@@ -73,6 +73,7 @@ More informations can be found [here][PGB_plugin].
-
[
enhancement:
]
Android 2.x (SDK >= 7) support (Thanks to
**khizarsonu**
)
-
[
enhancement:
]
Scope parameter for
`isScheduled`
and
`getScheduledIds`
-
[
enhancement:
]
Callbacks for
`cancel`
&
`cancelAll`
-
[
enhancement:
]
`image:`
accepts remote URLs and local URIs (Android)
#### Further informations
-
See
[
CHANGELOG.md
][
changelog
]
to get the full changelog for the plugin.
...
...
@@ -325,18 +326,33 @@ window.plugin.notification.local.setDefaults({ autoCancel: true });
### Small and large icons on Android
By default all notifications will display the app icon. But an specific icon can be defined through the
`icon`
and
`smallIcon`
properties.
#### Resource icons
The following example shows how to display the
`<package.name>.R.drawable.ic_launcher`
icon as the notifications icon.
```
javascript
/**
* Displays the <package.name>.R.drawable.ic_launcher icon
*/
window
.
plugin
.
notification
.
local
.
add
({
icon
:
'ic_launcher'
});
```
/**
* Displays the android.R.drawable.ic_dialog_email icon
*/
See below how to use the
`android.R.drawable.ic_dialog_email`
icon as the notifications small icon.
```
javascript
window
.
plugin
.
notification
.
local
.
add
({
smallIcon
:
'ic_dialog_email'
});
```
#### Local icons
The
`icon`
property also accepts local file URIs. The URI points to a relative path within the www folder.
```
javascript
window
.
plugin
.
notification
.
local
.
add
({
icon
:
'file://img/logo.png'
});
//=> /assets/www/img/logo.png
```
#### Remote icons
The
`icon`
property also accepts remote URLs. If the device cannot download the image, it will fallback to the app icon.
```
javascript
window
.
plugin
.
notification
.
local
.
add
({
icon
:
'https://cordova.apache.org/images/cordova_bot.png'
});
```
### Notification sound on Android
The sound must be a absolute or relative Uri pointing to the sound file. The default sound is
`RingtoneManager.TYPE_NOTIFICATION`
.
...
...
src/android/Options.java
View file @
3649f4bc
...
...
@@ -21,6 +21,10 @@
package
de
.
appplant
.
cordova
.
plugin
.
localnotification
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Calendar
;
import
java.util.Date
;
...
...
@@ -30,8 +34,14 @@ import org.json.JSONObject;
import
android.app.Activity
;
import
android.app.AlarmManager
;
import
android.content.Context
;
import
android.content.res.AssetManager
;
import
android.content.res.Resources
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.media.RingtoneManager
;
import
android.net.Uri
;
import
android.os.StrictMode
;
import
android.os.StrictMode.ThreadPolicy
;
/**
* Class that helps to store the options that can be specified per alarm.
...
...
@@ -153,21 +163,23 @@ public class Options {
/**
* Returns the icon's ID
*/
public
int
getIcon
()
{
int
icon
=
0
;
String
iconName
=
options
.
optString
(
"icon"
,
"icon"
)
;
public
Bitmap
getIcon
()
{
String
icon
=
options
.
optString
(
"icon"
,
"icon"
)
;
Bitmap
bmp
=
null
;
icon
=
getIconValue
(
packageName
,
iconName
)
;
icon
=
"https://lh3.ggpht.com/r4Qq0soacA8Lz1gwo81cC5NlsOJE60HCmXOrN7I-pr9dG7ucae83nFY3uBvnFn4G1e5XzcmPRmNUrMIZi-wpSq9e30G9HwQWka8coPc"
;
if
(
icon
==
0
)
{
icon
=
getIconValue
(
"android"
,
iconName
);
if
(
icon
.
startsWith
(
"http"
))
{
bmp
=
getIconFromURL
(
icon
);
}
else
if
(
icon
.
startsWith
(
"file://"
))
{
bmp
=
getIconFromURI
(
icon
);
}
if
(
icon
==
0
)
{
icon
=
android
.
R
.
drawable
.
ic_menu_info_details
;
if
(
bmp
==
null
)
{
bmp
=
getIconFromRes
(
icon
)
;
}
return
options
.
optInt
(
"icon"
,
icon
)
;
return
bmp
;
}
/**
...
...
@@ -184,7 +196,7 @@ public class Options {
}
if
(
resId
==
0
)
{
resId
=
getIcon
(
);
resId
=
getIcon
Value
(
packageName
,
"icon"
);
}
return
options
.
optInt
(
"smallIcon"
,
resId
);
...
...
@@ -249,4 +261,91 @@ public class Options {
return
icon
;
}
/**
* Converts an resource to Bitmap.
*
* @param icon
* The resource name
* @return
* The corresponding bitmap
*/
private
Bitmap
getIconFromRes
(
String
icon
)
{
Resources
res
=
LocalNotification
.
context
.
getResources
();
int
iconId
=
0
;
iconId
=
getIconValue
(
packageName
,
icon
);
if
(
iconId
==
0
)
{
iconId
=
getIconValue
(
"android"
,
icon
);
}
if
(
iconId
==
0
)
{
iconId
=
android
.
R
.
drawable
.
ic_menu_info_details
;
}
Bitmap
bmp
=
BitmapFactory
.
decodeResource
(
res
,
iconId
);
return
bmp
;
}
/**
* Converts an Image URL to Bitmap.
*
* @param src
* The external image URL
* @return
* The corresponding bitmap
*/
private
Bitmap
getIconFromURL
(
String
src
)
{
Bitmap
bmp
=
null
;
ThreadPolicy
origMode
=
StrictMode
.
getThreadPolicy
();
try
{
URL
url
=
new
URL
(
src
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
StrictMode
.
ThreadPolicy
policy
=
new
StrictMode
.
ThreadPolicy
.
Builder
().
permitAll
().
build
();
StrictMode
.
setThreadPolicy
(
policy
);
connection
.
setDoInput
(
true
);
connection
.
connect
();
InputStream
input
=
connection
.
getInputStream
();
bmp
=
BitmapFactory
.
decodeStream
(
input
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
StrictMode
.
setThreadPolicy
(
origMode
);
return
bmp
;
}
/**
* Converts an Image URI to Bitmap.
*
* @param src
* The internal image URI
* @return
* The corresponding bitmap
*/
private
Bitmap
getIconFromURI
(
String
src
)
{
AssetManager
assets
=
LocalNotification
.
context
.
getAssets
();
Bitmap
bmp
=
null
;
try
{
String
path
=
src
.
replace
(
"file:/"
,
"www"
);
InputStream
input
=
assets
.
open
(
path
);
bmp
=
BitmapFactory
.
decodeStream
(
input
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
bmp
;
}
}
src/android/Receiver.java
View file @
3649f4bc
...
...
@@ -35,8 +35,6 @@ import android.app.PendingIntent;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
...
...
@@ -118,7 +116,6 @@ public class Receiver extends BroadcastReceiver {
*/
@SuppressLint
(
"NewApi"
)
private
Builder
buildNotification
()
{
Bitmap
icon
=
BitmapFactory
.
decodeResource
(
context
.
getResources
(),
options
.
getIcon
());
Uri
sound
=
options
.
getSound
();
Builder
notification
=
new
NotificationCompat
.
Builder
(
context
)
...
...
@@ -127,7 +124,7 @@ public class Receiver extends BroadcastReceiver {
.
setNumber
(
options
.
getBadge
())
.
setTicker
(
options
.
getMessage
())
.
setSmallIcon
(
options
.
getSmallIcon
())
.
setLargeIcon
(
icon
)
.
setLargeIcon
(
options
.
getIcon
()
)
.
setAutoCancel
(
options
.
getAutoCancel
())
.
setOngoing
(
options
.
getOngoing
());
...
...
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