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
e071e96a
Commit
e071e96a
authored
Jan 15, 2015
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update example
parent
f0c90580
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
3874 additions
and
192 deletions
+3874
-192
index.html
platforms/android/assets/www/index.html
+115
-35
Asset.java
...id/src/de/appplant/cordova/plugin/notification/Asset.java
+310
-0
Manager.java
.../src/de/appplant/cordova/plugin/notification/Manager.java
+440
-0
NotificationBuilder.java
...lant/cordova/plugin/notification/NotificationBuilder.java
+114
-0
NotificationWrapper.java
...lant/cordova/plugin/notification/NotificationWrapper.java
+365
-0
Options.java
.../src/de/appplant/cordova/plugin/notification/Options.java
+347
-0
project.pbxproj
platforms/ios/NotificationExample.xcodeproj/project.pbxproj
+20
-21
UserInterfaceState.xcuserstate
...data/sebastian.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
APPLocalNotification.h
....cordova.plugin.local-notification/APPLocalNotification.h
+19
-8
APPLocalNotification.m
....cordova.plugin.local-notification/APPLocalNotification.m
+79
-2
UIApplication+APPLocalNotification.h
...n.local-notification/UIApplication+APPLocalNotification.h
+20
-7
UIApplication+APPLocalNotification.m
...n.local-notification/UIApplication+APPLocalNotification.m
+140
-31
UILocalNotification+APPLocalNotification.h
...l-notification/UILocalNotification+APPLocalNotification.h
+2
-0
UILocalNotification+APPLocalNotification.m
...l-notification/UILocalNotification+APPLocalNotification.m
+34
-25
index.html
platforms/ios/www/index.html
+99
-29
local-notification.js
...rdova.plugin.local-notification/www/local-notification.js
+91
-5
Asset.java
...in.local-notification/src/android/notification/Asset.java
+310
-0
Manager.java
....local-notification/src/android/notification/Manager.java
+440
-0
NotificationBuilder.java
...ication/src/android/notification/NotificationBuilder.java
+114
-0
NotificationWrapper.java
...ication/src/android/notification/NotificationWrapper.java
+365
-0
Options.java
....local-notification/src/android/notification/Options.java
+347
-0
index.html
www/index.html
+103
-29
No files found.
platforms/android/assets/www/index.html
View file @
e071e96a
...
...
@@ -91,63 +91,77 @@
<a
href=
"#"
class=
"button"
onclick=
"hasPermission()"
>
Has permission?
<br/><span
class=
"hint"
>
notification.local.hasPermission()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"registerPermission()"
>
Register permission
<br/><span
class=
"hint"
>
notification.local.registerPermission()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"schedule()"
>
Schedule now
<br/><span
class=
"hint"
>
notification.local.add()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"scheduleMultiple()"
>
Schedule multiple
<br/><span
class=
"hint"
>
notification.local.add()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"scheduleDelayed()"
>
Schedule in 5 sec
<br/><span
class=
"hint"
>
notification.local.add([])
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"scheduleMinutely()"
>
Schedule every min
<br/><span
class=
"hint"
>
notification.local.add()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"update()"
>
Update
<br/><span
class=
"hint"
>
notification.local.update()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"cancel()"
>
Cancel
<br/><span
class=
"hint"
>
notification.local.cancel()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"cancelMultiple()"
>
Cancel multiple
<br/><span
class=
"hint"
>
notification.local.cancel([])
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"cancelAll()"
>
Cancel all
<br/><span
class=
"hint"
>
notification.local.cancelAll()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"clear()"
>
Cancel
<br/><span
class=
"hint"
>
notification.local.clear()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"clearMultiple()"
>
Cancel multiple
<br/><span
class=
"hint"
>
notification.local.clear([])
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"clearAll()"
>
Cancel all
<br/><span
class=
"hint"
>
notification.local.clearAll()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getIds()"
>
All IDs
<br/><span
class=
"hint"
>
notification.local.getIds()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getScheduledIds()"
>
Scheduled IDs
<br/><span
class=
"hint"
>
notification.local.getScheduledIds()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isScheduled()"
>
Is scheduled?
<br/><span
class=
"hint"
>
notification.local.isScheduled()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getTriggeredIds()"
>
Triggered IDs
<br/><span
class=
"hint"
>
notification.local.getTriggeredIds()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isTriggered()"
>
Is triggered?
<br/><span
class=
"hint"
>
notification.local.isTriggered()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"exists()"
>
Exists?
<br/><span
class=
"hint"
>
notification.local.exists()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isScheduled()"
>
Scheduled?
<br/><span
class=
"hint"
>
notification.local.isScheduled()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isTriggered()"
>
Triggered?
<br/><span
class=
"hint"
>
notification.local.isTriggered()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getAll()"
>
All Notifications
<br/><span
class=
"hint"
>
notification.local.get()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getScheduled()"
>
Scheduled Notifications
<br/><span
class=
"hint"
>
notification.local.getScheduled()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getTriggered()"
>
Triggered Notifications
<br/><span
class=
"hint"
>
notification.local.getTriggered()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"setDefaultTitle()"
>
Change default title
<br/><span
class=
"hint"
>
notification.local.setDefaults()
</span></a>
</div>
</div>
<script
type=
"text/javascript"
src=
"cordova.js"
></script>
<script
type=
"text/javascript"
src=
"js/index.js"
></script>
<script
type=
"text/javascript"
>
var
counter
=
1
,
id
=
12
;
var
counter
=
0
,
id
=
1
;
var
callback
=
function
()
{
alert
(
'finished or canceled'
);
getIds
(
);
};
hasPermission
=
function
()
{
plugin
.
notification
.
local
.
hasPermission
(
function
(
granted
)
{
cordova
.
plugins
.
notification
.
local
.
hasPermission
(
function
(
granted
)
{
alert
(
granted
);
});
};
registerPermission
=
function
()
{
plugin
.
notification
.
local
.
registerPermission
(
function
(
granted
)
{
cordova
.
plugins
.
notification
.
local
.
registerPermission
(
function
(
granted
)
{
alert
(
granted
);
});
};
schedule
=
function
()
{
plugin
.
notification
.
local
.
add
({
cordova
.
plugins
.
notification
.
local
.
add
({
id
:
id
,
message
:
'Test Message '
+
(
++
counter
),
json
:
{
test
:
id
}
json
:
{
test
:
id
}
});
};
scheduleMultiple
=
function
()
{
plugin
.
notification
.
local
.
add
([{
cordova
.
plugins
.
notification
.
local
.
add
([{
id
:
id
,
message
:
'Test Message '
+
(
++
counter
),
json
:
{
test
:
id
}
message
:
'Multi Message '
+
(
++
counter
)
},{
id
:
id
+
1
,
message
:
'Test Message '
+
(
++
counter
),
json
:
{
test
:
id
+
1
}
message
:
'Multi Message '
+
(
++
counter
)
},{
id
:
id
+
2
,
message
:
'Test Message '
+
(
++
counter
),
json
:
{
test
:
id
+
2
}
message
:
'Multi Message '
+
(
++
counter
)
}]);
};
...
...
@@ -155,7 +169,7 @@
var
now
=
new
Date
().
getTime
(),
_5_sec_from_now
=
new
Date
(
now
+
5
*
1000
);
plugin
.
notification
.
local
.
add
({
cordova
.
plugins
.
notification
.
local
.
add
({
id
:
id
,
title
:
'Scheduled with delay'
,
message
:
'Test Message '
+
(
++
counter
),
...
...
@@ -165,7 +179,7 @@
};
scheduleMinutely
=
function
()
{
plugin
.
notification
.
local
.
add
({
cordova
.
plugins
.
notification
.
local
.
add
({
id
:
id
,
message
:
'Scheduled every minute'
,
repeat
:
'minutely'
,
...
...
@@ -173,68 +187,134 @@
});
};
update
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
update
({
id
:
id
,
message
:
'Updated Message '
+
(
counter
),
json
:
{
updated
:
true
}
});
};
cancel
=
function
()
{
counter
=
0
;
plugin
.
notification
.
local
.
cancel
(
id
,
callback
);
cordova
.
plugins
.
notification
.
local
.
cancel
(
id
,
callback
);
};
cancelMultiple
=
function
()
{
counter
=
0
;
plugin
.
notification
.
local
.
cancel
([
id
,
id
+
1
],
callback
);
cordova
.
plugins
.
notification
.
local
.
cancel
([
id
,
id
+
1
],
callback
);
};
cancelAll
=
function
()
{
counter
=
0
;
plugin
.
notification
.
local
.
cancelAll
(
callback
);
cordova
.
plugins
.
notification
.
local
.
cancelAll
(
callback
);
};
getScheduledIds
=
function
()
{
plugin
.
notification
.
local
.
getScheduledIds
(
function
(
ids
)
{
alert
(
'Scheduled IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
clear
=
function
()
{
counter
=
0
;
cordova
.
plugins
.
notification
.
local
.
clear
(
id
,
callback
);
};
clearMultiple
=
function
()
{
counter
=
0
;
cordova
.
plugins
.
notification
.
local
.
clear
([
id
,
id
+
1
],
callback
);
};
clearAll
=
function
()
{
counter
=
0
;
cordova
.
plugins
.
notification
.
local
.
clearAll
(
callback
);
};
setDefaultTitle
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
setDefaults
({
title
:
'New Default Title'
});
};
</script>
<!-- getters bool -->
<script
type=
"text/javascript"
>
exists
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
exists
(
id
,
function
(
exists
)
{
alert
(
'Notification with ID '
+
id
+
' exists:
\
n'
+
exists
);
});
};
isScheduled
=
function
()
{
plugin
.
notification
.
local
.
isScheduled
(
id
,
function
(
isScheduled
)
{
cordova
.
plugins
.
notification
.
local
.
isScheduled
(
id
,
function
(
isScheduled
)
{
alert
(
'Notification with ID '
+
id
+
' is scheduled:
\
n'
+
isScheduled
);
});
};
isTriggered
=
function
()
{
plugin
.
notification
.
local
.
isTriggered
(
id
,
function
(
isTriggered
)
{
cordova
.
plugins
.
notification
.
local
.
isTriggered
(
id
,
function
(
isTriggered
)
{
alert
(
'Notification with ID '
+
id
+
' is triggered:
\
n'
+
isTriggered
);
});
};
</script>
<!-- getters ID -->
<script
type=
"text/javascript"
>
getIds
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getIds
(
function
(
ids
)
{
alert
(
'IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
});
};
getScheduledIds
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getScheduledIds
(
function
(
ids
)
{
alert
(
'Scheduled IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
});
};
getTriggeredIds
=
function
()
{
plugin
.
notification
.
local
.
getTriggeredIds
(
function
(
ids
)
{
cordova
.
plugins
.
notification
.
local
.
getTriggeredIds
(
function
(
ids
)
{
alert
(
'Triggered IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
});
};
</script>
setDefaultTitle
=
function
()
{
plugin
.
notification
.
local
.
setDefaults
({
title
:
'Default Title'
,
<!-- getters object -->
<script
type=
"text/javascript"
>
getAll
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getAll
(
function
(
data
)
{
alert
(
'Notifications:
\
n['
+
data
.
join
(
' ,'
)
+
']'
);
});
};
</script>
getScheduled
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getScheduled
(
function
(
data
)
{
alert
(
'Scheduled Notifications:
\
n['
+
data
.
join
(
' ,'
)
+
']'
);
});
};
getTriggered
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getTriggered
(
function
(
data
)
{
alert
(
'Triggered Notifications:
\
n['
+
data
.
join
(
' ,'
)
+
']'
);
});
};
</script>
<!-- callbacks -->
<script
type=
"text/javascript"
>
document
.
addEventListener
(
'sdeviceready'
,
function
()
{
plugin
.
notification
.
local
.
onadd
=
function
(
id
,
state
,
json
)
{
cordova
.
plugins
.
notification
.
local
.
onadd
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on add
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
plugin
.
notification
.
local
.
ontrigger
=
function
(
id
,
state
,
json
)
{
cordova
.
plugins
.
notification
.
local
.
ontrigger
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on trigger
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
plugin
.
notification
.
local
.
onclick
=
function
(
id
,
state
,
json
)
{
cordova
.
plugins
.
notification
.
local
.
onclick
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on click
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
plugin
.
notification
.
local
.
oncancel
=
function
(
id
,
state
,
json
)
{
cordova
.
plugins
.
notification
.
local
.
oncancel
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on cancel
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
},
false
);
...
...
platforms/android/src/de/appplant/cordova/plugin/notification/Asset.java
0 → 100644
View file @
e071e96a
/*
Copyright 2013-2014 appPlant UG
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.app.Activity
;
import
android.content.res.AssetManager
;
import
android.content.res.Resources
;
import
android.media.RingtoneManager
;
import
android.net.Uri
;
import
android.os.StrictMode
;
import
android.util.Log
;
public
class
Asset
{
private
Activity
activity
;
protected
final
String
STORAGE_FOLDER
;
/**
* Constructor of Asset Class. Takes Applications Activity and a foldername for temporary saving.
*
*@param activity Applications Activity
*@param storageFolder foldername for temporary saving.
*/
public
Asset
(
Activity
activity
,
String
storageFolder
){
this
.
activity
=
activity
;
this
.
STORAGE_FOLDER
=
storageFolder
;
}
/**
* Parse given PathStrings to Uris
* @param notification Notifications JSONObject
* @return new Notification JSONObject with additional iconUri and soundUri
*/
public
JSONObject
parseURIs
(
JSONObject
notification
){
//sound
String
sound
=
notification
.
optString
(
"sound"
,
null
);
Uri
soundUri
=
null
;
if
(
sound
!=
null
)
{
try
{
int
soundId
=
(
Integer
)
RingtoneManager
.
class
.
getDeclaredField
(
sound
).
get
(
Integer
.
class
);
soundUri
=
RingtoneManager
.
getDefaultUri
(
soundId
);
}
catch
(
Exception
e
)
{
soundUri
=
getURIfromPath
(
sound
);
}
}
if
(
soundUri
!=
null
&&
soundUri
!=
Uri
.
EMPTY
){
try
{
notification
.
put
(
"soundUri"
,
soundUri
.
toString
());
}
catch
(
JSONException
jse
){
jse
.
printStackTrace
();
}
}
//image
String
icon
=
notification
.
optString
(
"icon"
,
"icon"
);
Uri
iconUri
=
null
;
iconUri
=
getURIfromPath
(
icon
);
if
(
iconUri
!=
Uri
.
EMPTY
&&
iconUri
!=
null
){
try
{
notification
.
put
(
"iconUri"
,
iconUri
.
toString
());
}
catch
(
JSONException
jse
){
jse
.
printStackTrace
();
}
}
return
notification
;
}
/**
* The URI for a path.
*
* @param path The given path
*
* @return The URI pointing to the given path
*/
public
Uri
getURIfromPath
(
String
path
){
if
(
path
.
startsWith
(
"res:"
))
{
return
getUriForResourcePath
(
path
);
}
else
if
(
path
.
startsWith
(
"file:///"
))
{
return
getUriForAbsolutePath
(
path
);
}
else
if
(
path
.
startsWith
(
"file://"
))
{
return
getUriForAssetPath
(
path
);
}
else
if
(
path
.
startsWith
(
"http"
)){
return
getUriForHTTP
(
path
);
}
return
Uri
.
parse
(
path
);
}
/**
* The URI for a file.
*
* @param path
* The given absolute path
*
* @return The URI pointing to the given path
*/
private
Uri
getUriForAbsolutePath
(
String
path
)
{
String
absPath
=
path
.
replaceFirst
(
"file://"
,
""
);
File
file
=
new
File
(
absPath
);
if
(!
file
.
exists
())
{
Log
.
e
(
"Asset"
,
"File not found: "
+
file
.
getAbsolutePath
());
return
Uri
.
EMPTY
;
}
return
Uri
.
fromFile
(
file
);
}
/**
* The URI for an asset.
*
* @param path
* The given asset path
*
* @return The URI pointing to the given path
*/
private
Uri
getUriForAssetPath
(
String
path
)
{
String
resPath
=
path
.
replaceFirst
(
"file:/"
,
"www"
);
String
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
File
dir
=
activity
.
getExternalCacheDir
();
if
(
dir
==
null
)
{
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
return
Uri
.
EMPTY
;
}
String
storage
=
dir
.
toString
()
+
STORAGE_FOLDER
;
File
file
=
new
File
(
storage
,
fileName
);
new
File
(
storage
).
mkdir
();
try
{
AssetManager
assets
=
activity
.
getAssets
();
FileOutputStream
outStream
=
new
FileOutputStream
(
file
);
InputStream
inputStream
=
assets
.
open
(
resPath
);
copyFile
(
inputStream
,
outStream
);
outStream
.
flush
();
outStream
.
close
();
return
Uri
.
fromFile
(
file
);
}
catch
(
Exception
e
)
{
Log
.
e
(
"Asset"
,
"File not found: assets/"
+
resPath
);
e
.
printStackTrace
();
}
return
Uri
.
EMPTY
;
}
/**
* The URI for a resource.
*
* @param path
* The given relative path
*
* @return The URI pointing to the given path
*/
private
Uri
getUriForResourcePath
(
String
path
)
{
String
resPath
=
path
.
replaceFirst
(
"res://"
,
""
);
String
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
String
resName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
'.'
));
String
extension
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'.'
));
File
dir
=
activity
.
getExternalCacheDir
();
if
(
dir
==
null
)
{
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
return
Uri
.
EMPTY
;
}
String
storage
=
dir
.
toString
()
+
STORAGE_FOLDER
;
int
resId
=
getResId
(
resPath
);
File
file
=
new
File
(
storage
,
resName
+
extension
);
if
(
resId
==
0
)
{
Log
.
e
(
"Asset"
,
"File not found: "
+
resPath
);
return
Uri
.
EMPTY
;
}
new
File
(
storage
).
mkdir
();
try
{
Resources
res
=
activity
.
getResources
();
FileOutputStream
outStream
=
new
FileOutputStream
(
file
);
InputStream
inputStream
=
res
.
openRawResource
(
resId
);
copyFile
(
inputStream
,
outStream
);
outStream
.
flush
();
outStream
.
close
();
return
Uri
.
fromFile
(
file
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
Uri
.
EMPTY
;
}
/**
*Get Uri for HTTP Content
* @param path HTTP adress
* @return Uri of the downloaded file
*/
private
Uri
getUriForHTTP
(
String
path
)
{
try
{
URL
url
=
new
URL
(
path
);
String
fileName
=
path
.
substring
(
path
.
lastIndexOf
(
'/'
)
+
1
);
String
resName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
'.'
));
String
extension
=
path
.
substring
(
path
.
lastIndexOf
(
'.'
));
File
dir
=
activity
.
getExternalCacheDir
();
if
(
dir
==
null
)
{
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
return
Uri
.
EMPTY
;
}
String
storage
=
dir
.
toString
()
+
STORAGE_FOLDER
;
File
file
=
new
File
(
storage
,
resName
+
extension
);
new
File
(
storage
).
mkdir
();
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
();
FileOutputStream
outStream
=
new
FileOutputStream
(
file
);
copyFile
(
input
,
outStream
);
outStream
.
flush
();
outStream
.
close
();
return
Uri
.
fromFile
(
file
);
}
catch
(
MalformedURLException
e
)
{
Log
.
e
(
"Asset"
,
"Incorrect URL"
);
e
.
printStackTrace
();
}
catch
(
FileNotFoundException
e
)
{
Log
.
e
(
"Asset"
,
"Failed to create new File from HTTP Content"
);
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
Log
.
e
(
"Asset"
,
"No Input can be created from http Stream"
);
e
.
printStackTrace
();
}
return
Uri
.
EMPTY
;
}
/**
* Writes an InputStream to an OutputStream
*
* @param in
* The input stream
* @param out
* The output stream
*/
private
void
copyFile
(
InputStream
in
,
OutputStream
out
)
throws
IOException
{
byte
[]
buffer
=
new
byte
[
1024
];
int
read
;
while
((
read
=
in
.
read
(
buffer
))
!=
-
1
)
{
out
.
write
(
buffer
,
0
,
read
);
}
}
/**
* @return The resource ID for the given resource.
*/
private
int
getResId
(
String
resPath
)
{
Resources
res
=
activity
.
getResources
();
int
resId
;
String
pkgName
=
getPackageName
();
String
dirName
=
"drawable"
;
String
fileName
=
resPath
;
if
(
resPath
.
contains
(
"/"
))
{
dirName
=
resPath
.
substring
(
0
,
resPath
.
lastIndexOf
(
'/'
));
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
}
String
resName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
'.'
));
resId
=
res
.
getIdentifier
(
resName
,
dirName
,
pkgName
);
if
(
resId
==
0
)
{
resId
=
res
.
getIdentifier
(
resName
,
"drawable"
,
pkgName
);
}
return
resId
;
}
/**
* The name for the package.
*
* @return The package name
*/
private
String
getPackageName
()
{
return
activity
.
getPackageName
();
}
}
platforms/android/src/de/appplant/cordova/plugin/notification/Manager.java
0 → 100644
View file @
e071e96a
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
java.util.Date
;
import
java.util.Map
;
import
java.util.Set
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences.Editor
;
import
android.os.Build
;
public
class
Manager
{
//---------------Global Parameter------------------------------------------------------------
private
Context
context
;
private
final
String
PLUGIN_NAME
;
//---------------Constructor-----------------------------------------------------------------
/**
* Constructor of NotificationWrapper-Class
*/
public
Manager
(
Context
context
,
String
PluginName
){
this
.
context
=
context
;
this
.
PLUGIN_NAME
=
PluginName
;
}
//---------------Public Functions------------------------------------------------------------
/**
* Checks if a notification with an ID is scheduled.
*
* @param id
* The notification ID to be check.
* @return true if the notification is scheduled
*/
public
boolean
isScheduled
(
String
id
)
{
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
boolean
isScheduled
=
alarms
.
containsKey
(
id
);
boolean
isNotTriggered
=
false
;
if
(
isScheduled
)
{
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getDate
());
isNotTriggered
=
new
Date
().
before
(
fireDate
);
}
catch
(
JSONException
e
)
{
isNotTriggered
=
false
;
e
.
printStackTrace
();
}
}
return
(
isScheduled
&&
isNotTriggered
);
}
/**
* Checks if a notification with an ID was triggered.
*
* @param id
* The notification ID to be check.
* @return true if the notification is triggered
*/
public
boolean
isTriggered
(
String
id
)
{
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
boolean
isScheduled
=
alarms
.
containsKey
(
id
);
boolean
isTriggered
=
isScheduled
;
if
(
isScheduled
)
{
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getInitialDate
());
isTriggered
=
new
Date
().
after
(
fireDate
);
}
catch
(
JSONException
e
)
{
isTriggered
=
false
;
e
.
printStackTrace
();
}
}
return
isTriggered
;
}
/**
* Checks whether a notification with an ID exist.
*
* @param id
* The notification ID to check.
* @return true if the notification exist
*/
public
boolean
exist
(
String
id
){
boolean
exist
;
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
exist
=
alarms
.
containsKey
(
id
);
return
exist
;
}
/**
* Retrieves a list with all currently pending notification Ids.
*
* @return JSONArray with all Id-Strings
*/
public
JSONArray
getScheduledIds
()
{
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
scheduledIds
=
new
JSONArray
();
for
(
String
id
:
alarmIds
)
{
boolean
isScheduled
;
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getDate
());
isScheduled
=
new
Date
().
before
(
fireDate
);
}
catch
(
JSONException
e
)
{
isScheduled
=
false
;
e
.
printStackTrace
();
}
if
(
isScheduled
){
scheduledIds
.
put
(
id
);
}
}
return
scheduledIds
;
}
/**
* Retrieves a list with all currently triggered notification Ids.
*
* @return JSONArray with all Id-Strings
*/
public
JSONArray
getTriggeredIds
()
{
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
triggeredIds
=
new
JSONArray
();
Date
now
=
new
Date
();
for
(
String
id
:
alarmIds
)
{
boolean
isTriggered
;
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getInitialDate
());
isTriggered
=
now
.
after
(
fireDate
);
}
catch
(
ClassCastException
cce
)
{
cce
.
printStackTrace
();
isTriggered
=
false
;
}
catch
(
JSONException
jse
)
{
jse
.
printStackTrace
();
isTriggered
=
false
;
}
if
(
isTriggered
==
true
)
{
triggeredIds
.
put
(
id
);
}
}
return
triggeredIds
;
}
/**
* Retrieves a list with all currently triggered or scheduled notification-Ids.
* @return JSONArray with all Id-Strings
*/
public
JSONArray
getAllIds
(){
JSONArray
allIds
=
new
JSONArray
();
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
for
(
String
id
:
alarmIds
)
{
allIds
.
put
(
id
);
}
return
allIds
;
}
/**
* Retrieves a list with all currently pending notification JSONObject.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getAll
(){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
all
=
new
JSONArray
();
for
(
String
id
:
alarmIds
)
{
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
all
.
put
(
arguments
);
}
catch
(
JSONException
jse
)
{
jse
.
printStackTrace
();
}
}
return
all
;
}
/**
* Retrieves a list with all currently scheduled notification-JSONObjects.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getScheduled
(){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
scheduled
=
new
JSONArray
();
for
(
String
id
:
alarmIds
)
{
boolean
isScheduled
;
JSONObject
arguments
=
null
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getDate
());
isScheduled
=
new
Date
().
before
(
fireDate
);
}
catch
(
JSONException
e
)
{
isScheduled
=
false
;
e
.
printStackTrace
();
}
if
(
isScheduled
){
scheduled
.
put
(
arguments
);
}
}
return
scheduled
;
}
/**
* Retrieves a list with all currently triggered notification-JSONObjects.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getTriggered
(){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
triggered
=
new
JSONArray
();
Date
now
=
new
Date
();
for
(
String
id
:
alarmIds
)
{
boolean
isTriggered
;
JSONObject
arguments
=
null
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getInitialDate
());
isTriggered
=
now
.
after
(
fireDate
);
}
catch
(
ClassCastException
cce
)
{
cce
.
printStackTrace
();
isTriggered
=
false
;
}
catch
(
JSONException
jse
)
{
jse
.
printStackTrace
();
isTriggered
=
false
;
}
if
(
isTriggered
==
true
)
{
triggered
.
put
(
arguments
);
}
}
return
triggered
;
}
/**
* Retrieves a list with all currently pending notification JSONObject.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getAll
(
JSONArray
ids
){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
all
=
new
JSONArray
();
for
(
String
id
:
alarmIds
)
{
for
(
int
i
=
0
;
i
<
ids
.
length
();
i
++){
if
(
ids
.
optString
(
i
).
equals
(
id
)){
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
all
.
put
(
arguments
);
}
catch
(
JSONException
jse
)
{
jse
.
printStackTrace
();
}
}
}
}
return
all
;
}
/**
* Retrieves a list with all currently scheduled notification-JSONObjects.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getScheduled
(
JSONArray
ids
){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
scheduled
=
new
JSONArray
();
boolean
isScheduled
;
for
(
String
id
:
alarmIds
)
{
for
(
int
i
=
0
;
i
<
ids
.
length
();
i
++){
if
(
ids
.
optString
(
i
).
equals
(
id
)){
JSONObject
arguments
=
null
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getDate
());
isScheduled
=
new
Date
().
before
(
fireDate
);
}
catch
(
JSONException
e
)
{
isScheduled
=
false
;
e
.
printStackTrace
();
}
if
(
isScheduled
){
scheduled
.
put
(
arguments
);
}
}
}
}
return
scheduled
;
}
/**
* Retrieves a list with all currently triggered notification-JSONObjects.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getTriggered
(
JSONArray
ids
){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
triggered
=
new
JSONArray
();
Date
now
=
new
Date
();
for
(
String
id
:
alarmIds
)
{
for
(
int
i
=
0
;
i
<
ids
.
length
();
i
++){
if
(
ids
.
optString
(
i
).
equals
(
id
)){
boolean
isTriggered
;
JSONObject
arguments
=
null
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getInitialDate
());
isTriggered
=
now
.
after
(
fireDate
);
}
catch
(
ClassCastException
cce
)
{
cce
.
printStackTrace
();
isTriggered
=
false
;
}
catch
(
JSONException
jse
)
{
jse
.
printStackTrace
();
isTriggered
=
false
;
}
if
(
isTriggered
==
true
)
{
triggered
.
put
(
arguments
);
}
}
}
}
return
triggered
;
}
//---------------Manage Shared Preferences---------------------------------------------------
/**
* The Local storage for the application.
*/
private
SharedPreferences
getSharedPreferences
()
{
return
context
.
getSharedPreferences
(
PLUGIN_NAME
,
Context
.
MODE_PRIVATE
);
}
/**
* Persist the information of this alarm to the Android Shared Preferences.
* This will allow the application to restore the alarm upon device reboot.
* Also this is used by the cancelAll method.
*
* @param alarmId
* The Id of the notification that must be persisted.
* @param args
* The assumption is that parse has been called already.
*/
public
void
persist
(
String
alarmId
,
JSONObject
args
)
{
Editor
editor
=
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
putString
(
alarmId
,
args
.
toString
());
if
(
Build
.
VERSION
.
SDK_INT
<
9
)
{
editor
.
commit
();
}
else
{
editor
.
apply
();
}
}
}
/**
* Remove a specific alarm from the Android shared Preferences.
*
* @param alarmId
* The Id of the notification that must be removed.
*/
public
void
unpersist
(
String
alarmId
)
{
Editor
editor
=
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
remove
(
alarmId
);
if
(
Build
.
VERSION
.
SDK_INT
<
9
)
{
editor
.
commit
();
}
else
{
editor
.
apply
();
}
}
}
}
platforms/android/src/de/appplant/cordova/plugin/notification/NotificationBuilder.java
0 → 100644
View file @
e071e96a
/*
Copyright 2013-2014 appPlant UG
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
java.util.Random
;
import
android.annotation.SuppressLint
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationCompat.Builder
;
public
class
NotificationBuilder
{
private
Options
options
;
private
Context
context
;
private
Builder
notification
;
private
final
String
OPTIONS
;
private
Class
<?>
deleteIntentReceiver
;
private
Class
<?>
receiverActivity
;
/**
* Constructor of NotificationBuilder
* @param options
* @param context
* @param OPTIONS
* @param deleteIntentReceiver
* @param receiverActivity
*/
public
NotificationBuilder
(
Options
options
,
Context
context
,
String
OPTIONS
,
Class
<?>
deleteIntentReceiver
,
Class
<?>
receiverActivity
){
this
.
options
=
options
;
this
.
context
=
context
;
this
.
OPTIONS
=
OPTIONS
;
this
.
deleteIntentReceiver
=
deleteIntentReceiver
;
this
.
receiverActivity
=
receiverActivity
;
}
/**
* Creates the notification.
*/
@SuppressLint
(
"NewApi"
)
public
Builder
buildNotification
()
{
Uri
sound
=
options
.
getSound
();
//DeleteIntent is called when the user clears a notification manually
Intent
deleteIntent
=
new
Intent
(
context
,
deleteIntentReceiver
)
.
setAction
(
""
+
options
.
getId
())
.
putExtra
(
OPTIONS
,
options
.
getJSONObject
().
toString
());
PendingIntent
dpi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
deleteIntent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
notification
=
new
NotificationCompat
.
Builder
(
context
)
.
setDefaults
(
0
)
// Do not inherit any defaults
.
setContentTitle
(
options
.
getTitle
())
.
setContentText
(
options
.
getMessage
())
.
setNumber
(
options
.
getBadge
())
.
setTicker
(
options
.
getMessage
())
.
setSmallIcon
(
options
.
getSmallIcon
())
.
setLargeIcon
(
options
.
getIcon
())
.
setAutoCancel
(
options
.
getAutoCancel
())
.
setOngoing
(
options
.
getOngoing
())
.
setLights
(
options
.
getColor
(),
500
,
500
)
.
setDeleteIntent
(
dpi
);
if
(
sound
!=
null
)
{
notification
.
setSound
(
sound
);
}
if
(
Build
.
VERSION
.
SDK_INT
>
16
)
{
notification
.
setStyle
(
new
NotificationCompat
.
BigTextStyle
()
.
bigText
(
options
.
getMessage
()));
}
setClickEvent
(
notification
);
return
notification
;
}
/**
* Adds an onclick handler to the notification
*/
private
Builder
setClickEvent
(
Builder
notification
)
{
Intent
intent
=
new
Intent
(
context
,
receiverActivity
)
.
putExtra
(
OPTIONS
,
options
.
getJSONObject
().
toString
())
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NO_HISTORY
);
int
requestCode
=
new
Random
().
nextInt
();
PendingIntent
contentIntent
=
PendingIntent
.
getActivity
(
context
,
requestCode
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
return
notification
.
setContentIntent
(
contentIntent
);
}
}
platforms/android/src/de/appplant/cordova/plugin/notification/NotificationWrapper.java
0 → 100644
View file @
e071e96a
/*
Copyright 2013-2014 appPlant UG
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
java.util.Date
;
import
java.util.Map
;
import
java.util.Set
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.app.AlarmManager
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences.Editor
;
import
android.os.Build
;
import
android.support.v4.app.NotificationCompat.Builder
;
import
android.widget.Toast
;
/**
* Wrapper class to schedule, cancel, clear, and update notifications.
*
*/
public
class
NotificationWrapper
{
//---------------Global Parameter------------------------------------------------------------
private
Context
context
;
private
Class
<?>
receiver
;
private
final
String
PLUGIN_NAME
;
private
final
String
OPTIONS
;
//---------------Constructor-----------------------------------------------------------------
/**
* Constructor of NotificationWrapper-Class
*/
public
NotificationWrapper
(
Context
context
,
Class
<?>
receiver
,
String
PluginName
,
String
OPTIONS
){
this
.
context
=
context
;
this
.
receiver
=
receiver
;
this
.
PLUGIN_NAME
=
PluginName
;
this
.
OPTIONS
=
OPTIONS
;
}
//---------------public functions------------------------------------------------------------
/**
* Schedule new notification
*/
public
void
schedule
(
Options
options
){
long
triggerTime
=
options
.
getDate
();
persist
(
options
.
getId
(),
options
.
getJSONObject
());
//Intent is called when the Notification gets fired
Intent
intent
=
new
Intent
(
context
,
receiver
)
.
setAction
(
""
+
options
.
getId
())
.
putExtra
(
OPTIONS
,
options
.
getJSONObject
().
toString
());
AlarmManager
am
=
getAlarmManager
();
PendingIntent
pi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
am
.
set
(
AlarmManager
.
RTC_WAKEUP
,
triggerTime
,
pi
);
}
/**
* Cancel existing notification
*/
public
void
cancel
(
String
notificationId
){
/*
* Create an intent that looks similar, to the one that was registered
* using add. Making sure the notification id in the action is the same.
* Now we can search for such an intent using the 'getService' method
* and cancel it.
*/
Intent
intent
=
new
Intent
(
context
,
receiver
)
.
setAction
(
""
+
notificationId
);
PendingIntent
pi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
0
);
AlarmManager
am
=
getAlarmManager
();
NotificationManager
nc
=
getNotificationManager
();
am
.
cancel
(
pi
);
try
{
nc
.
cancel
(
Integer
.
parseInt
(
notificationId
));
}
catch
(
Exception
e
)
{}
unpersist
(
notificationId
);
}
/**
* Cancel all notifications that were created by this plugin.
*
* Android can only unregister a specific alarm. There is no such thing
* as cancelAll. Therefore we rely on the Shared Preferences which holds
* all our alarms to loop through these alarms and unregister them one
* by one.
*/
public
void
cancelAll
()
{
SharedPreferences
settings
=
getSharedPreferences
();
NotificationManager
nc
=
getNotificationManager
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
for
(
String
alarmId
:
alarmIds
)
{
cancel
(
alarmId
);
}
nc
.
cancelAll
();
}
/**
* Update an existing notification
*
* @param updates JSONObject with update-content
*/
public
void
update
(
JSONObject
updates
){
String
id
=
updates
.
optString
(
"id"
,
"0"
);
// update shared preferences
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
return
;
}
arguments
=
updateArguments
(
arguments
,
updates
);
// cancel existing alarm
Intent
intent
=
new
Intent
(
context
,
receiver
)
.
setAction
(
""
+
id
);
PendingIntent
pi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
0
);
AlarmManager
am
=
getAlarmManager
();
am
.
cancel
(
pi
);
//add new alarm
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
schedule
(
options
);
}
/**
* Clear a specific notification without canceling repeating alarms
*
* @param notificationID
* The original ID of the notification that was used when it was
* registered using add()
*/
public
void
clear
(
String
notificationId
){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
NotificationManager
nc
=
getNotificationManager
();
try
{
nc
.
cancel
(
Integer
.
parseInt
(
notificationId
));
}
catch
(
Exception
e
)
{}
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
notificationId
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
now
=
new
Date
();
if
((
options
.
getInterval
()!=
0
)){
persist
(
notificationId
,
setInitDate
(
arguments
));
}
else
if
((
new
Date
(
options
.
getDate
()).
before
(
now
))){
unpersist
(
notificationId
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
return
;
}
}
/**
* Clear all notifications without canceling repeating alarms
*/
public
void
clearAll
(){
SharedPreferences
settings
=
getSharedPreferences
();
NotificationManager
nc
=
getNotificationManager
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
for
(
String
alarmId
:
alarmIds
)
{
clear
(
alarmId
);
}
nc
.
cancelAll
();
}
/**
* Shows the notification
*/
@SuppressWarnings
(
"deprecation"
)
public
void
showNotification
(
Builder
notification
,
Options
options
)
{
NotificationManager
mgr
=
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
int
id
=
0
;
try
{
id
=
Integer
.
parseInt
(
options
.
getId
());
}
catch
(
Exception
e
)
{}
if
(
Build
.
VERSION
.
SDK_INT
<
16
)
{
// build notification for HoneyComb to ICS
mgr
.
notify
(
id
,
notification
.
getNotification
());
}
else
if
(
Build
.
VERSION
.
SDK_INT
>
15
)
{
// Notification for Jellybean and above
mgr
.
notify
(
id
,
notification
.
build
());
}
}
/**
* Show a notification as a Toast when App is runing in foreground
* @param title Title of the notification
* @param notification Notification to show
*/
public
void
showNotificationToast
(
Options
options
){
String
title
=
options
.
getTitle
();
String
message
=
options
.
getMessage
();
int
duration
=
Toast
.
LENGTH_LONG
;
if
(
title
.
equals
(
""
)){
title
=
"Notification"
;
}
String
text
=
title
+
" \n "
+
message
;
Toast
notificationToast
=
Toast
.
makeText
(
context
,
text
,
duration
);
notificationToast
.
show
();
}
//---------------Manage Shared Preferences---------------------------------------------------
/**
* The Local storage for the application.
*/
private
SharedPreferences
getSharedPreferences
()
{
return
context
.
getSharedPreferences
(
PLUGIN_NAME
,
Context
.
MODE_PRIVATE
);
}
/**
* Persist the information of this alarm to the Android Shared Preferences.
* This will allow the application to restore the alarm upon device reboot.
* Also this is used by the cancelAll method.
*
* @param alarmId
* The Id of the notification that must be persisted.
* @param args
* The assumption is that parse has been called already.
*/
public
void
persist
(
String
alarmId
,
JSONObject
args
)
{
Editor
editor
=
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
putString
(
alarmId
,
args
.
toString
());
if
(
Build
.
VERSION
.
SDK_INT
<
9
)
{
editor
.
commit
();
}
else
{
editor
.
apply
();
}
}
}
/**
* Remove a specific alarm from the Android shared Preferences.
*
* @param alarmId
* The Id of the notification that must be removed.
*/
public
void
unpersist
(
String
alarmId
)
{
Editor
editor
=
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
remove
(
alarmId
);
if
(
Build
.
VERSION
.
SDK_INT
<
9
)
{
editor
.
commit
();
}
else
{
editor
.
apply
();
}
}
}
//---------------private functions-----------------------------------------------------------
/**
* The alarm manager for the application.
*/
private
AlarmManager
getAlarmManager
()
{
return
(
AlarmManager
)
context
.
getSystemService
(
Context
.
ALARM_SERVICE
);
}
/**
* The notification manager for the application.
*/
private
NotificationManager
getNotificationManager
()
{
return
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
}
/**
* Update the Arguments Input with content from updates-input
*
* @param arguments The notifications optionArray
* @param updates The content you like to change
*
* @return The updated value
*/
private
JSONObject
updateArguments
(
JSONObject
arguments
,
JSONObject
updates
){
try
{
if
(!
updates
.
isNull
(
"message"
)){
arguments
.
put
(
"message"
,
updates
.
get
(
"message"
));
}
if
(!
updates
.
isNull
(
"title"
)){
arguments
.
put
(
"title"
,
updates
.
get
(
"title"
));
}
if
(!
updates
.
isNull
(
"badge"
)){
arguments
.
put
(
"badge"
,
updates
.
get
(
"badge"
));
}
if
(!
updates
.
isNull
(
"sound"
)){
arguments
.
put
(
"sound"
,
updates
.
get
(
"sound"
));
}
if
(!
updates
.
isNull
(
"icon"
)){
arguments
.
put
(
"icon"
,
updates
.
get
(
"icon"
));
}
}
catch
(
JSONException
jse
){
jse
.
printStackTrace
();
}
return
arguments
;
}
/**
* Function to set the value of "initialDate" in the JSONArray
* @param args The given JSONArray
* @return A new JSONArray with the parameter "initialDate" set.
*/
private
JSONObject
setInitDate
(
JSONObject
arguments
){
long
initialDate
=
arguments
.
optLong
(
"date"
,
0
)
*
1000
;
try
{
arguments
.
put
(
"initialDate"
,
initialDate
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
arguments
;
}
}
platforms/android/src/de/appplant/cordova/plugin/notification/Options.java
0 → 100644
View file @
e071e96a
/*
Copyright 2013-2014 appPlant UG
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Calendar
;
import
java.util.Date
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.app.AlarmManager
;
import
android.content.Context
;
import
android.content.res.Resources
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.net.Uri
;
/**
* Class that helps to store the options that can be specified per alarm.
*/
public
class
Options
{
private
JSONObject
options
=
new
JSONObject
();
private
String
packageName
=
null
;
private
long
interval
=
0
;
private
Context
context
;
public
Options
(
Context
context
){
this
.
context
=
context
;
this
.
packageName
=
context
.
getPackageName
();
}
/**
* Parses the given properties
*/
public
Options
parse
(
JSONObject
options
)
{
String
repeat
=
options
.
optString
(
"repeat"
);
this
.
options
=
options
;
if
(
repeat
.
equalsIgnoreCase
(
"secondly"
))
{
interval
=
1000
;
}
if
(
repeat
.
equalsIgnoreCase
(
"minutely"
))
{
interval
=
AlarmManager
.
INTERVAL_FIFTEEN_MINUTES
/
15
;
}
if
(
repeat
.
equalsIgnoreCase
(
"hourly"
))
{
interval
=
AlarmManager
.
INTERVAL_HOUR
;
}
if
(
repeat
.
equalsIgnoreCase
(
"daily"
))
{
interval
=
AlarmManager
.
INTERVAL_DAY
;
}
else
if
(
repeat
.
equalsIgnoreCase
(
"weekly"
))
{
interval
=
AlarmManager
.
INTERVAL_DAY
*
7
;
}
else
if
(
repeat
.
equalsIgnoreCase
(
"monthly"
))
{
interval
=
AlarmManager
.
INTERVAL_DAY
*
31
;
// 31 days
}
else
if
(
repeat
.
equalsIgnoreCase
(
"yearly"
))
{
interval
=
AlarmManager
.
INTERVAL_DAY
*
365
;
}
else
{
try
{
interval
=
Integer
.
parseInt
(
repeat
)
*
60000
;
}
catch
(
Exception
e
)
{};
}
return
this
;
}
/**
* Set new time according to interval
*/
public
Options
moveDate
()
{
try
{
options
.
put
(
"date"
,
(
getDate
()
+
interval
)
/
1000
);
}
catch
(
JSONException
e
)
{}
return
this
;
}
/**
* Returns options as JSON object
*/
public
JSONObject
getJSONObject
()
{
return
options
;
}
/**
* Returns time in milliseconds when notification is scheduled to fire
*/
public
long
getDate
()
{
return
options
.
optLong
(
"date"
,
0
)
*
1000
;
}
/**
* Returns time in milliseconds when the notification was scheduled first
*/
public
long
getInitialDate
()
{
return
options
.
optLong
(
"initialDate"
,
0
);
}
/**
* Returns time as calender
*/
public
Calendar
getCalendar
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
new
Date
(
getDate
()));
return
calendar
;
}
/**
* Returns the notification's message
*/
public
String
getMessage
()
{
return
options
.
optString
(
"message"
,
""
);
}
/**
* Returns the notification's title
*/
public
String
getTitle
()
{
return
options
.
optString
(
"title"
,
""
);
}
/**
* Returns the path of the notification's sound file
*/
public
Uri
getSound
()
{
Uri
soundUri
=
null
;
try
{
soundUri
=
Uri
.
parse
(
options
.
optString
(
"soundUri"
));
return
soundUri
;
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
null
;
}
/**
* Returns the icon's ID
*/
public
Bitmap
getIcon
()
{
String
icon
=
options
.
optString
(
"icon"
,
"icon"
);
Bitmap
bmp
=
null
;
Uri
iconUri
=
null
;
try
{
iconUri
=
Uri
.
parse
(
options
.
optString
(
"iconUri"
));
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
if
(
iconUri
!=
null
)
{
bmp
=
getIconFromUri
(
iconUri
);
}
if
(
bmp
==
null
)
{
bmp
=
getIconFromRes
(
icon
);
}
return
bmp
;
}
/**
* Returns the small icon's ID
*/
public
int
getSmallIcon
()
{
int
resId
=
0
;
String
iconName
=
options
.
optString
(
"smallIcon"
,
""
);
resId
=
getIconValue
(
packageName
,
iconName
);
if
(
resId
==
0
)
{
resId
=
getIconValue
(
"android"
,
iconName
);
}
if
(
resId
==
0
)
{
resId
=
getIconValue
(
packageName
,
"icon"
);
}
return
options
.
optInt
(
"smallIcon"
,
resId
);
}
/**
* Returns notification repetition interval (daily, weekly, monthly, yearly)
*/
public
long
getInterval
()
{
return
interval
;
}
/**
* Returns notification badge number
*/
public
int
getBadge
()
{
return
options
.
optInt
(
"badge"
,
0
);
}
/**
* Returns PluginResults' callback ID
*/
public
String
getId
()
{
return
options
.
optString
(
"id"
,
"0"
);
}
/**
* Returns whether notification is cancelled automatically when clicked.
*/
public
Boolean
getAutoCancel
()
{
return
options
.
optBoolean
(
"autoCancel"
,
false
);
}
/**
* Returns whether the notification is ongoing (uncancellable). Android only.
*/
public
Boolean
getOngoing
()
{
return
options
.
optBoolean
(
"ongoing"
,
false
);
}
/**
* Returns additional data as string
*/
public
String
getJSON
()
{
return
options
.
optString
(
"json"
,
""
);
}
/**
* @return
* The notification color for LED
*/
public
int
getColor
()
{
String
hexColor
=
options
.
optString
(
"led"
,
"000000"
);
int
aRGB
=
Integer
.
parseInt
(
hexColor
,
16
);
aRGB
+=
0xFF000000
;
return
aRGB
;
}
/**
* Shows the behavior of notifications when the application is in foreground
*
*/
public
boolean
getForegroundMode
(){
return
options
.
optBoolean
(
"foregroundMode"
,
false
);
}
/**
* Returns numerical icon Value
*
* @param {String} className
* @param {String} iconName
*/
private
int
getIconValue
(
String
className
,
String
iconName
)
{
int
icon
=
0
;
try
{
Class
<?>
klass
=
Class
.
forName
(
className
+
".R$drawable"
);
icon
=
(
Integer
)
klass
.
getDeclaredField
(
iconName
).
get
(
Integer
.
class
);
}
catch
(
Exception
e
)
{}
return
icon
;
}
/**
* Converts an resource to Bitmap.
*
* @param icon
* The resource name
* @return
* The corresponding bitmap
*/
private
Bitmap
getIconFromRes
(
String
icon
)
{
Resources
res
=
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 URI to Bitmap.
*
* @param src
* The internal image URI
* @return
* The corresponding bitmap
*/
private
Bitmap
getIconFromUri
(
Uri
uri
)
{
Bitmap
bmp
=
null
;
try
{
InputStream
input
=
context
.
getContentResolver
().
openInputStream
(
uri
);
bmp
=
BitmapFactory
.
decodeStream
(
input
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
bmp
;
}
/**
* Function to set the value of "initialDate" in the JSONArray
* @param args The given JSONArray
* @return A new JSONArray with the parameter "initialDate" set.
*/
public
void
setInitDate
(){
long
initialDate
=
options
.
optLong
(
"date"
,
0
)
*
1000
;
try
{
options
.
put
(
"initialDate"
,
initialDate
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
}
platforms/ios/NotificationExample.xcodeproj/project.pbxproj
View file @
e071e96a
...
...
@@ -5,10 +5,12 @@
};
objectVersion
=
46
;
objects
=
{
/* Begin PBXBuildFile section */
0B33C5FC1B224A91B96FDE79
/* CDVDevice.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
212EBD1D7BCB4409838CD818
/* CDVDevice.m */
;
};
1D3623260D0F684500981E51
/* AppDelegate.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
1D3623250D0F684500981E51
/* AppDelegate.m */
;
};
1D60589B0D05DD56006BFB54
/* main.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
29B97316FDCFA39411CA2CEA
/* main.m */
;
};
244C5454167242FABDACC376
/* AppDelegate+APPLocalNotification.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
028AC353A09C4EA79A266646
/* AppDelegate+APPLocalNotification.m */
;
};
288765FD0DF74451002DB57D
/* CoreGraphics.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
288765FC0DF74451002DB57D
/* CoreGraphics.framework */
;
};
301BF552109A68D80062928A
/* libCordova.a in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
301BF535109A57CC0062928A
/* libCordova.a */
;
};
302D95F114D2391D003F00A1
/* MainViewController.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
302D95EF14D2391D003F00A1
/* MainViewController.m */
;
};
...
...
@@ -41,14 +43,13 @@
7E7966E51810823500FA85AD
/* icon-76@2x.png in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
7E7966DB1810823500FA85AD
/* icon-76@2x.png */
;
};
7E7966E61810823500FA85AD
/* icon-small.png in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
7E7966DC1810823500FA85AD
/* icon-small.png */
;
};
7E7966E71810823500FA85AD
/* icon-small@2x.png in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
7E7966DD1810823500FA85AD
/* icon-small@2x.png */
;
};
90D59C90545F4506982554E8
/* APPLocalNotification.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
EE4654C98F394A8DBDE0AC57
/* APPLocalNotification.m */
;
};
9E1A68381A55FA1B00FBCA66
/* beep.caf in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9E1A68371A55FA1B00FBCA66
/* beep.caf */
;
};
9E5A62291A52DE07002E41A3
/* (null) in Sources */
=
{
isa
=
PBXBuildFile
;
};
D4A0D8761607E02300AEF8BB
/* Default-568h@2x~iphone.png in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
D4A0D8751607E02300AEF8BB
/* Default-568h@2x~iphone.png */
;
};
90D59C90545F4506982554E8
/* APPLocalNotification.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
EE4654C98F394A8DBDE0AC57
/* APPLocalNotification.m */
;
};
BD757B0D44BE440083918077
/* APPLocalNotificationOptions.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
37095E752E9D455C853BE373
/* APPLocalNotificationOptions.m */
;
};
244C5454167242FABDACC376
/* AppDelegate+APPLocalNotification.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
028AC353A09C4EA79A266646
/* AppDelegate+APPLocalNotification.m */
;
};
F809B57D91144ACBA4D15DE6
/* UIApplication+APPLocalNotification.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4C4288BC92A44887AE839CAE
/* UIApplication+APPLocalNotification.m */
;
};
D4A0D8761607E02300AEF8BB
/* Default-568h@2x~iphone.png in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
D4A0D8751607E02300AEF8BB
/* Default-568h@2x~iphone.png */
;
};
F378B9146F0E46C2BD460ED2
/* UILocalNotification+APPLocalNotification.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
5E55360F8342488798514532
/* UILocalNotification+APPLocalNotification.m */
;
};
F809B57D91144ACBA4D15DE6
/* UIApplication+APPLocalNotification.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
4C4288BC92A44887AE839CAE
/* UIApplication+APPLocalNotification.m */
;
};
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
...
...
@@ -69,12 +70,14 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
028AC353A09C4EA79A266646
/* AppDelegate+APPLocalNotification.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
"AppDelegate+APPLocalNotification.m"
;
path
=
"de.appplant.cordova.plugin.local-notification/AppDelegate+APPLocalNotification.m"
;
sourceTree
=
"<group>"
;
};
1D3623240D0F684500981E51
/* AppDelegate.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
AppDelegate.h
;
sourceTree
=
"<group>"
;
};
1D3623250D0F684500981E51
/* AppDelegate.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
AppDelegate.m
;
sourceTree
=
"<group>"
;
};
1D6058910D05DD3D006BFB54
/* NotificationExample.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
NotificationExample.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
212EBD1D7BCB4409838CD818
/* CDVDevice.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
CDVDevice.m
;
path
=
org.apache.cordova.device/CDVDevice.m
;
sourceTree
=
"<group>"
;
};
288765FC0DF74451002DB57D
/* CoreGraphics.framework */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
wrapper.framework
;
name
=
CoreGraphics.framework
;
path
=
System/Library/Frameworks/CoreGraphics.framework
;
sourceTree
=
SDKROOT
;
};
29B97316FDCFA39411CA2CEA
/* main.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
main.m
;
sourceTree
=
"<group>"
;
};
2C2F7D7BF58F46B4ADDA1E7E
/* AppDelegate+APPLocalNotification.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
"AppDelegate+APPLocalNotification.h"
;
path
=
"de.appplant.cordova.plugin.local-notification/AppDelegate+APPLocalNotification.h"
;
sourceTree
=
"<group>"
;
};
301BF52D109A57CC0062928A
/* CordovaLib.xcodeproj */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
"wrapper.pb-project"
;
name
=
CordovaLib.xcodeproj
;
path
=
CordovaLib/CordovaLib.xcodeproj
;
sourceTree
=
"<group>"
;
};
301BF56E109A69640062928A
/* www */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
folder
;
path
=
www
;
sourceTree
=
SOURCE_ROOT
;
};
302D95EE14D2391D003F00A1
/* MainViewController.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
MainViewController.h
;
sourceTree
=
"<group>"
;
};
...
...
@@ -96,8 +99,11 @@
30C1856519D5FC0A00212699
/* icon-60@3x.png */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.png
;
path
=
"icon-60@3x.png"
;
sourceTree
=
"<group>"
;
};
30FC414816E50CA1004E6F35
/* icon-72@2x.png */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.png
;
path
=
"icon-72@2x.png"
;
sourceTree
=
"<group>"
;
};
32CA4F630368D1EE00C91783
/* NotificationExample-Prefix.pch */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
"NotificationExample-Prefix.pch"
;
sourceTree
=
"<group>"
;
};
37095E752E9D455C853BE373
/* APPLocalNotificationOptions.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
APPLocalNotificationOptions.m
;
path
=
"de.appplant.cordova.plugin.local-notification/APPLocalNotificationOptions.m"
;
sourceTree
=
"<group>"
;
};
3C888438876C480D8B36E11A
/* APPBackgroundMode.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
APPBackgroundMode.h
;
path
=
"de.appplant.cordova.plugin.background-mode/APPBackgroundMode.h"
;
sourceTree
=
"<group>"
;
};
4C4288BC92A44887AE839CAE
/* UIApplication+APPLocalNotification.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
"UIApplication+APPLocalNotification.m"
;
path
=
"de.appplant.cordova.plugin.local-notification/UIApplication+APPLocalNotification.m"
;
sourceTree
=
"<group>"
;
};
5B1594DC16A7569C00FEF299
/* AssetsLibrary.framework */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
wrapper.framework
;
name
=
AssetsLibrary.framework
;
path
=
System/Library/Frameworks/AssetsLibrary.framework
;
sourceTree
=
SDKROOT
;
};
5E55360F8342488798514532
/* UILocalNotification+APPLocalNotification.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
"UILocalNotification+APPLocalNotification.m"
;
path
=
"de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.m"
;
sourceTree
=
"<group>"
;
};
7E7966D41810823500FA85AD
/* icon-40.png */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.png
;
path
=
"icon-40.png"
;
sourceTree
=
"<group>"
;
};
7E7966D51810823500FA85AD
/* icon-40@2x.png */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.png
;
path
=
"icon-40@2x.png"
;
sourceTree
=
"<group>"
;
};
7E7966D61810823500FA85AD
/* icon-50.png */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.png
;
path
=
"icon-50.png"
;
sourceTree
=
"<group>"
;
};
...
...
@@ -110,23 +116,18 @@
7E7966DD1810823500FA85AD
/* icon-small@2x.png */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.png
;
path
=
"icon-small@2x.png"
;
sourceTree
=
"<group>"
;
};
8D1107310486CEB800E47090
/* NotificationExample-Info.plist */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
text.plist.xml
;
name
=
"NotificationExample-Info.plist"
;
path
=
"../NotificationExample-Info.plist"
;
plistStructureDefinitionIdentifier
=
"com.apple.xcode.plist.structure-definition.iphone.info-plist"
;
sourceTree
=
"<group>"
;
};
9E1A68371A55FA1B00FBCA66
/* beep.caf */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
file
;
path
=
beep.caf
;
sourceTree
=
"<group>"
;
};
B22193F3CC42466498BF03A8
/* APPLocalNotificationOptions.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
APPLocalNotificationOptions.h
;
path
=
"de.appplant.cordova.plugin.local-notification/APPLocalNotificationOptions.h"
;
sourceTree
=
"<group>"
;
};
C37D37FB86E04E16BA8047EE
/* APPLocalNotification.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
APPLocalNotification.h
;
path
=
"de.appplant.cordova.plugin.local-notification/APPLocalNotification.h"
;
sourceTree
=
"<group>"
;
};
CAD9B6E7C8424F74AF0AA068
/* UILocalNotification+APPLocalNotification.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
"UILocalNotification+APPLocalNotification.h"
;
path
=
"de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.h"
;
sourceTree
=
"<group>"
;
};
D4A0D8751607E02300AEF8BB
/* Default-568h@2x~iphone.png */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
image.png
;
path
=
"Default-568h@2x~iphone.png"
;
sourceTree
=
"<group>"
;
};
DDDFCE9D76CA4692A1F4A984
/* APPBackgroundMode.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
APPBackgroundMode.m
;
path
=
"de.appplant.cordova.plugin.background-mode/APPBackgroundMode.m"
;
sourceTree
=
"<group>"
;
};
E02030E711134A5D8215D2F0
/* appbeep.wav */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
unknown
;
path
=
appbeep.wav
;
sourceTree
=
"<group>"
;
};
EB87FDF31871DA8E0020F90C
/* www */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
folder
;
name
=
www
;
path
=
../../www
;
sourceTree
=
"<group>"
;
};
EB87FDF41871DAF40020F90C
/* config.xml */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.xml
;
name
=
config.xml
;
path
=
../../config.xml
;
sourceTree
=
"<group>"
;
};
EE4654C98F394A8DBDE0AC57
/* APPLocalNotification.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
APPLocalNotification.m
;
path
=
"de.appplant.cordova.plugin.local-notification/APPLocalNotification.m"
;
sourceTree
=
"<group>"
;
};
EF7CC58EF6424BB183C2CE58
/* UIApplication+APPLocalNotification.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
"UIApplication+APPLocalNotification.h"
;
path
=
"de.appplant.cordova.plugin.local-notification/UIApplication+APPLocalNotification.h"
;
sourceTree
=
"<group>"
;
};
F042F1C3B49D4E2699FF5E1D
/* CDVDevice.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
CDVDevice.h
;
path
=
org.apache.cordova.device/CDVDevice.h
;
sourceTree
=
"<group>"
;
};
F840E1F0165FE0F500CFE078
/* config.xml */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text.xml
;
name
=
config.xml
;
path
=
NotificationExample/config.xml
;
sourceTree
=
"<group>"
;
};
EE4654C98F394A8DBDE0AC57
/* APPLocalNotification.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
"APPLocalNotification.m"
;
path
=
"de.appplant.cordova.plugin.local-notification/APPLocalNotification.m"
;
sourceTree
=
"<group>"
;
fileEncoding
=
4
;
};
37095E752E9D455C853BE373
/* APPLocalNotificationOptions.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
"APPLocalNotificationOptions.m"
;
path
=
"de.appplant.cordova.plugin.local-notification/APPLocalNotificationOptions.m"
;
sourceTree
=
"<group>"
;
fileEncoding
=
4
;
};
028AC353A09C4EA79A266646
/* AppDelegate+APPLocalNotification.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
"AppDelegate+APPLocalNotification.m"
;
path
=
"de.appplant.cordova.plugin.local-notification/AppDelegate+APPLocalNotification.m"
;
sourceTree
=
"<group>"
;
fileEncoding
=
4
;
};
4C4288BC92A44887AE839CAE
/* UIApplication+APPLocalNotification.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
"UIApplication+APPLocalNotification.m"
;
path
=
"de.appplant.cordova.plugin.local-notification/UIApplication+APPLocalNotification.m"
;
sourceTree
=
"<group>"
;
fileEncoding
=
4
;
};
5E55360F8342488798514532
/* UILocalNotification+APPLocalNotification.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
name
=
"UILocalNotification+APPLocalNotification.m"
;
path
=
"de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.m"
;
sourceTree
=
"<group>"
;
fileEncoding
=
4
;
};
C37D37FB86E04E16BA8047EE
/* APPLocalNotification.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
"APPLocalNotification.h"
;
path
=
"de.appplant.cordova.plugin.local-notification/APPLocalNotification.h"
;
sourceTree
=
"<group>"
;
fileEncoding
=
4
;
};
B22193F3CC42466498BF03A8
/* APPLocalNotificationOptions.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
"APPLocalNotificationOptions.h"
;
path
=
"de.appplant.cordova.plugin.local-notification/APPLocalNotificationOptions.h"
;
sourceTree
=
"<group>"
;
fileEncoding
=
4
;
};
2C2F7D7BF58F46B4ADDA1E7E
/* AppDelegate+APPLocalNotification.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
"AppDelegate+APPLocalNotification.h"
;
path
=
"de.appplant.cordova.plugin.local-notification/AppDelegate+APPLocalNotification.h"
;
sourceTree
=
"<group>"
;
fileEncoding
=
4
;
};
EF7CC58EF6424BB183C2CE58
/* UIApplication+APPLocalNotification.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
"UIApplication+APPLocalNotification.h"
;
path
=
"de.appplant.cordova.plugin.local-notification/UIApplication+APPLocalNotification.h"
;
sourceTree
=
"<group>"
;
fileEncoding
=
4
;
};
CAD9B6E7C8424F74AF0AA068
/* UILocalNotification+APPLocalNotification.h */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.h
;
name
=
"UILocalNotification+APPLocalNotification.h"
;
path
=
"de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.h"
;
sourceTree
=
"<group>"
;
fileEncoding
=
4
;
};
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
...
...
@@ -230,16 +231,16 @@
212EBD1D7BCB4409838CD818
/* CDVDevice.m */
,
3C888438876C480D8B36E11A
/* APPBackgroundMode.h */
,
DDDFCE9D76CA4692A1F4A984
/* APPBackgroundMode.m */
,
C37D37FB86E04E16BA8047EE
/* APPLocalNotification.h */
,
EE4654C98F394A8DBDE0AC57
/* APPLocalNotification.m */
,
B22193F3CC42466498BF03A8
/* APPLocalNotificationOptions.h */
,
37095E752E9D455C853BE373
/* APPLocalNotificationOptions.m */
,
2C2F7D7BF58F46B4ADDA1E7E
/* AppDelegate+APPLocalNotification.h */
,
028AC353A09C4EA79A266646
/* AppDelegate+APPLocalNotification.m */
,
4C4288BC92A44887AE839CAE
/* UIApplication+APPLocalNotification.m
*/
,
CAD9B6E7C8424F74AF0AA068
/* UILocalNotification+APPLocalNotification.h
*/
,
5E55360F8342488798514532
/* UILocalNotification+APPLocalNotification.m */
,
C37D37FB86E04E16BA8047EE
/* APPLocalNotification.h */
,
B22193F3CC42466498BF03A8
/* APPLocalNotificationOptions.h */
,
2C2F7D7BF58F46B4ADDA1E7E
/* AppDelegate+APPLocalNotification.h */
,
EF7CC58EF6424BB183C2CE58
/* UIApplication+APPLocalNotification.h */
,
CAD9B6E7C8424F74AF0AA068
/* UILocalNotification+APPLocalNotification.h
*/
,
4C4288BC92A44887AE839CAE
/* UIApplication+APPLocalNotification.m
*/
,
);
name
=
Plugins
;
path
=
NotificationExample/Plugins
;
...
...
@@ -429,8 +430,6 @@
9E5A62291A52DE07002E41A3
/* (null) in Sources */
,
0B33C5FC1B224A91B96FDE79
/* CDVDevice.m in Sources */
,
3DBE1CCC022B412AA9E356AF
/* APPBackgroundMode.m in Sources */
,
0FFC7382D3B74FADB62619F0
/* UIApplication+APPLocalNotification.h in Sources */
,
210AC435FA28427D89EF30B0
/* AppDelegate+APPLocalNotification.m in Sources */
,
90D59C90545F4506982554E8
/* APPLocalNotification.m in Sources */
,
BD757B0D44BE440083918077
/* APPLocalNotificationOptions.m in Sources */
,
244C5454167242FABDACC376
/* AppDelegate+APPLocalNotification.m in Sources */
,
...
...
platforms/ios/NotificationExample.xcodeproj/project.xcworkspace/xcuserdata/sebastian.xcuserdatad/UserInterfaceState.xcuserstate
View file @
e071e96a
No preview for this file type
platforms/ios/NotificationExample/Plugins/de.appplant.cordova.plugin.local-notification/APPLocalNotification.h
View file @
e071e96a
...
...
@@ -26,6 +26,12 @@
// Execute all queued events
-
(
void
)
deviceready
:(
CDVInvokedUrlCommand
*
)
command
;
// Inform if the app has the permission to show notifications
-
(
void
)
hasPermission
:(
CDVInvokedUrlCommand
*
)
command
;
// Register permission to show notifications
-
(
void
)
registerPermission
:(
CDVInvokedUrlCommand
*
)
command
;
// Schedule a new notification
-
(
void
)
add
:(
CDVInvokedUrlCommand
*
)
command
;
// Update a notification
...
...
@@ -34,21 +40,26 @@
-
(
void
)
cancel
:(
CDVInvokedUrlCommand
*
)
command
;
// Cancel all currently scheduled notifications
-
(
void
)
cancelAll
:(
CDVInvokedUrlCommand
*
)
command
;
// Check if a notification with an ID is scheduled
// If a notification with an ID exists
-
(
void
)
exist
:(
CDVInvokedUrlCommand
*
)
command
;
// If a notification with an ID was scheduled
-
(
void
)
isScheduled
:(
CDVInvokedUrlCommand
*
)
command
;
//
Check i
f a notification with an ID was triggered
//
I
f a notification with an ID was triggered
-
(
void
)
isTriggered
:(
CDVInvokedUrlCommand
*
)
command
;
// List all ids from all local notifications
-
(
void
)
getAllIds
:(
CDVInvokedUrlCommand
*
)
command
;
// List all ids from all pending notifications
-
(
void
)
getScheduledIds
:(
CDVInvokedUrlCommand
*
)
command
;
// List all ids from all triggered notifications
-
(
void
)
getTriggeredIds
:(
CDVInvokedUrlCommand
*
)
command
;
// List all properties for given scheduled notifications
// Property list for given local notifications
-
(
void
)
getAll
:(
CDVInvokedUrlCommand
*
)
command
;
// Property list for given scheduled notifications
-
(
void
)
getScheduled
:(
CDVInvokedUrlCommand
*
)
command
;
//
List all properties
for given triggered notifications
//
Property list
for given triggered notifications
-
(
void
)
getTriggered
:(
CDVInvokedUrlCommand
*
)
command
;
// Inform if the app has the permission to show notifications
-
(
void
)
hasPermission
:(
CDVInvokedUrlCommand
*
)
command
;
// Register permission to show notifications
-
(
void
)
registerPermission
:(
CDVInvokedUrlCommand
*
)
command
;
@end
platforms/ios/NotificationExample/Plugins/de.appplant.cordova.plugin.local-notification/APPLocalNotification.m
View file @
e071e96a
...
...
@@ -162,6 +162,34 @@
}
/**
* If a notification by ID exists.
*
* @param id
* The ID of the notification
*/
-
(
void
)
exist
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
.
commandDelegate
runInBackground
:
^
{
NSString
*
id
=
[[
command
arguments
]
objectAtIndex
:
0
];
CDVPluginResult
*
result
;
UILocalNotification
*
notification
;
notification
=
[[
UIApplication
sharedApplication
]
localNotificationWithId
:
id
];
bool
exists
=
notification
!=
NULL
;
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsBool
:
exists
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
}];
}
/**
* If a notification by ID is scheduled.
*
* @param id
...
...
@@ -218,6 +246,26 @@
}
/**
* List all ids from all local notifications.
*/
-
(
void
)
getAllIds
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
.
commandDelegate
runInBackground
:
^
{
CDVPluginResult
*
result
;
NSArray
*
notIds
;
notIds
=
[[
UIApplication
sharedApplication
]
localNotificationIds
];
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsArray
:
notIds
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
}];
}
/**
* List all ids from all pending notifications.
*/
-
(
void
)
getScheduledIds
:(
CDVInvokedUrlCommand
*
)
command
...
...
@@ -258,7 +306,36 @@
}
/**
* List all properties for given scheduled notifications.
* Property list for given local notifications.
*
* @param ids
* The IDs of the notifications
*/
-
(
void
)
getAll
:(
CDVInvokedUrlCommand
*
)
command
{
[
self
.
commandDelegate
runInBackground
:
^
{
NSArray
*
ids
=
command
.
arguments
;
NSArray
*
notifications
;
CDVPluginResult
*
result
;
if
(
ids
.
count
==
0
)
{
notifications
=
[[
UIApplication
sharedApplication
]
localNotificationOptions
];
}
else
{
notifications
=
[[
UIApplication
sharedApplication
]
localNotificationOptions
:
ids
];
}
result
=
[
CDVPluginResult
resultWithStatus
:
CDVCommandStatus_OK
messageAsArray
:
notifications
];
[
self
.
commandDelegate
sendPluginResult
:
result
callbackId
:
command
.
callbackId
];
}];
}
/**
* Property list for given scheduled notifications.
*
* @param ids
* The IDs of the notifications
...
...
@@ -287,7 +364,7 @@
}
/**
*
List all properties
for given triggered notifications.
*
Property list
for given triggered notifications.
*
* @param ids
* The IDs of the notifications
...
...
platforms/ios/NotificationExample/Plugins/de.appplant.cordova.plugin.local-notification/UIApplication+APPLocalNotification.h
View file @
e071e96a
...
...
@@ -21,7 +21,11 @@
@interface
UIApplication
(
APPLocalNotification
)
@property
(
readonly
,
getter
=
localNotifications
)
NSArray
*
localNotifications
;
@property
(
readonly
,
getter
=
scheduledLocalNotifications2
)
NSArray
*
triggeredLocalNotifications2
;
@property
(
readonly
,
getter
=
triggeredLocalNotifications
)
NSArray
*
triggeredLocalNotifications
;
@property
(
readonly
,
getter
=
localNotificationIds
)
NSArray
*
localNotificationIds
;
@property
(
readonly
,
getter
=
triggeredLocalNotificationIds
)
NSArray
*
triggeredLocalNotificationIds
;
@property
(
readonly
,
getter
=
scheduledLocalNotificationIds
)
NSArray
*
scheduledLocalNotificationIds
;
...
...
@@ -29,17 +33,26 @@
-
(
BOOL
)
hasPermissionToScheduleLocalNotifications
;
// Ask for permission to schedule local notifications
-
(
void
)
registerPermissionToScheduleLocalNotifications
;
// Get the scheduled local notification by ID
// Get local notification by ID
-
(
UILocalNotification
*
)
localNotificationWithId
:(
NSString
*
)
id
;
// Get scheduled local notification by ID
-
(
UILocalNotification
*
)
scheduledLocalNotificationWithId
:(
NSString
*
)
id
;
// Get t
he t
riggered local notification by ID
// Get triggered local notification by ID
-
(
UILocalNotification
*
)
triggeredLocalNotificationWithId
:(
NSString
*
)
id
;
// List of properties from all scheduled notifications
// Property list from all local notifications
-
(
NSArray
*
)
localNotificationOptions
;
// Property list from all scheduled notifications
-
(
NSArray
*
)
scheduledLocalNotificationOptions
;
// List of properties from given scheduled notifications
-
(
NSArray
*
)
scheduledLocalNotificationOptions
:(
NSArray
*
)
ids
;
// List of properties from all triggered notifications
// Property list from all triggered notifications
-
(
NSArray
*
)
triggeredLocalNotificationOptions
;
// List of properties from given triggered notifications
// Property list from given local notifications
-
(
NSArray
*
)
localNotificationOptions
:(
NSArray
*
)
ids
;
// Property list from given scheduled notifications
-
(
NSArray
*
)
scheduledLocalNotificationOptions
:(
NSArray
*
)
ids
;
// Property list from given triggered notifications
-
(
NSArray
*
)
triggeredLocalNotificationOptions
:(
NSArray
*
)
ids
;
@end
platforms/ios/NotificationExample/Plugins/de.appplant.cordova.plugin.local-notification/UIApplication+APPLocalNotification.m
View file @
e071e96a
...
...
@@ -72,18 +72,55 @@
#pragma mark LocalNotifications
/**
* List of all local notifications which have been added
* but not yet removed from the notification center.
*/
-
(
NSArray
*
)
localNotifications
{
NSArray
*
scheduledNotifications
=
self
.
scheduledLocalNotifications
;
NSMutableArray
*
notifications
=
[[
NSMutableArray
alloc
]
init
];
for
(
UILocalNotification
*
notification
in
scheduledNotifications
)
{
if
(
notification
)
{
[
notifications
addObject
:
notification
];
}
}
return
notifications
;
}
/**
* List of all local notifications which have been scheduled
* and not yet removed from the notification center.
*/
-
(
NSArray
*
)
scheduledLocalNotifications2
{
NSArray
*
scheduledNotifications
=
self
.
scheduledLocalNotifications
;
NSMutableArray
*
notifications
=
[[
NSMutableArray
alloc
]
init
];
for
(
UILocalNotification
*
notification
in
scheduledNotifications
)
{
if
(
notification
&&
[
notification
wasScheduled
])
{
[
notifications
addObject
:
notification
];
}
}
return
notifications
;
}
/**
* List of all triggered local notifications which have been scheduled
* and not yet removed the notification center.
*/
-
(
NSArray
*
)
triggeredLocalNotifications
{
NSArray
*
scheduledNotifications
=
self
.
scheduledL
ocalNotifications
;
NSArray
*
notifications
=
self
.
l
ocalNotifications
;
NSMutableArray
*
triggeredNotifications
=
[[
NSMutableArray
alloc
]
init
];
for
(
UILocalNotification
*
notification
in
scheduledN
otifications
)
for
(
UILocalNotification
*
notification
in
n
otifications
)
{
if
(
notification
&&
[
notification
wasTriggered
])
{
if
([
notification
wasTriggered
])
{
[
triggeredNotifications
addObject
:
notification
];
}
}
...
...
@@ -93,18 +130,35 @@
/**
* List of all triggered local notifications IDs which have been scheduled
* and not yet removed the notification center.
* and not yet removed from the notification center.
*/
-
(
NSArray
*
)
localNotificationIds
{
NSArray
*
notifications
=
self
.
localNotifications
;
NSMutableArray
*
ids
=
[[
NSMutableArray
alloc
]
init
];
for
(
UILocalNotification
*
notification
in
notifications
)
{
[
ids
addObject
:
notification
.
options
.
id
];
}
return
ids
;
}
/**
* List of all added local notifications IDs which have been scheduled
* and not yet removed from the notification center.
*/
-
(
NSArray
*
)
triggeredLocalNotificationIds
{
NSArray
*
notifications
=
self
.
triggeredLocalNotifications
;
NSMutableArray
*
ids
=
[[
NSMutableArray
alloc
]
init
];
for
(
UILocalNotification
*
notification
in
notifications
)
{
[
ids
addObject
:
notification
.
options
.
id
];
}
return
ids
;
}
...
...
@@ -113,32 +167,50 @@
*/
-
(
NSArray
*
)
scheduledLocalNotificationIds
{
NSArray
*
notifications
=
self
.
scheduledLocalNotifications
;
NSArray
*
notifications
=
self
.
scheduledLocalNotifications
2
;
NSMutableArray
*
ids
=
[[
NSMutableArray
alloc
]
init
];
for
(
UILocalNotification
*
notification
in
notifications
)
{
if
(
notification
)
{
[
ids
addObject
:
notification
.
options
.
id
];
}
[
ids
addObject
:
notification
.
options
.
id
];
}
return
ids
;
}
/**
* Get the scheduled local notification by ID.
* Get local notification by ID.
*
* @param id
* Notification ID
*/
-
(
UILocalNotification
*
)
localNotificationWithId
:
(
NSString
*
)
id
{
NSArray
*
notifications
=
self
.
localNotifications
;
for
(
UILocalNotification
*
notification
in
notifications
)
{
if
([
notification
.
options
.
id
isEqualToString
:
id
])
{
return
notification
;
}
}
return
NULL
;
}
/**
* Get scheduled local notification by ID.
*
* @param id
* Notification ID
*/
-
(
UILocalNotification
*
)
scheduledLocalNotificationWithId
:
(
NSString
*
)
id
{
NSArray
*
notifications
=
self
.
scheduledLocalNotifications
;
NSArray
*
notifications
=
self
.
scheduledLocalNotifications
2
;
for
(
UILocalNotification
*
notification
in
notifications
)
{
if
(
notification
&&
[
notification
.
options
.
id
isEqualToString
:
id
])
{
if
([
notification
.
options
.
id
isEqualToString
:
id
])
{
return
notification
;
}
}
...
...
@@ -147,14 +219,14 @@
}
/**
* Get t
he t
riggered local notification by ID.
* Get triggered local notification by ID.
*
* @param id
* Notification ID
*/
-
(
UILocalNotification
*
)
triggeredLocalNotificationWithId
:
(
NSString
*
)
id
{
UILocalNotification
*
notification
=
[
self
scheduledL
ocalNotificationWithId
:
id
];
UILocalNotification
*
notification
=
[
self
l
ocalNotificationWithId
:
id
];
if
(
notification
&&
[
notification
wasTriggered
])
{
return
notification
;
...
...
@@ -164,57 +236,94 @@
}
/**
* List of properties from all notifications.
*/
-
(
NSArray
*
)
localNotificationOptions
{
NSArray
*
notifications
=
self
.
localNotifications
;
NSMutableArray
*
options
=
[[
NSMutableArray
alloc
]
init
];
for
(
UILocalNotification
*
notification
in
notifications
)
{
[
options
addObject
:
notification
.
userInfo
];
}
return
options
;
}
/**
* List of properties from all scheduled notifications.
*/
-
(
NSArray
*
)
scheduledLocalNotificationOptions
{
NSArray
*
notifications
=
self
.
scheduledLocalNotifications
;
NSArray
*
notifications
=
[
self
scheduledLocalNotifications2
]
;
NSMutableArray
*
options
=
[[
NSMutableArray
alloc
]
init
];
for
(
UILocalNotification
*
notification
in
notifications
)
{
if
(
notification
)
{
[
options
addObject
:
notification
.
userInfo
];
}
[
options
addObject
:
notification
.
userInfo
];
}
return
options
;
}
/**
* List of properties from given scheduled notifications.
* List of properties from all triggered notifications.
*/
-
(
NSArray
*
)
triggeredLocalNotificationOptions
{
NSArray
*
notifications
=
self
.
triggeredLocalNotifications
;
NSMutableArray
*
options
=
[[
NSMutableArray
alloc
]
init
];
for
(
UILocalNotification
*
notification
in
notifications
)
{
[
options
addObject
:
notification
.
userInfo
];
}
return
options
;
}
/**
* List of properties from given local notifications.
*
* @param ids
* Notification IDs
*/
-
(
NSArray
*
)
scheduledL
ocalNotificationOptions
:
(
NSArray
*
)
ids
-
(
NSArray
*
)
l
ocalNotificationOptions
:
(
NSArray
*
)
ids
{
UILocalNotification
*
notification
;
NSMutableArray
*
options
=
[[
NSMutableArray
alloc
]
init
];
for
(
NSString
*
id
in
ids
)
{
notification
=
[
self
scheduledL
ocalNotificationWithId
:
id
];
notification
=
[
self
l
ocalNotificationWithId
:
id
];
if
(
notification
)
{
[
options
addObject
:
notification
.
userInfo
];
}
}
return
options
;
}
/**
* List of properties from all triggered notifications.
* List of properties from given scheduled notifications.
*
* @param ids
* Notification IDs
*/
-
(
NSArray
*
)
triggeredLocalNotificationOption
s
-
(
NSArray
*
)
scheduledLocalNotificationOptions
:
(
NSArray
*
)
id
s
{
NSArray
*
notifications
=
self
.
triggeredLocalNotifications
;
UILocalNotification
*
notification
;
NSMutableArray
*
options
=
[[
NSMutableArray
alloc
]
init
];
for
(
UILocalNotification
*
notification
in
notification
s
)
for
(
NSString
*
id
in
id
s
)
{
[
options
addObject
:
notification
.
userInfo
];
notification
=
[
self
scheduledLocalNotificationWithId
:
id
];
if
(
notification
)
{
[
options
addObject
:
notification
.
userInfo
];
}
}
return
options
;
...
...
platforms/ios/NotificationExample/Plugins/de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.h
View file @
e071e96a
...
...
@@ -31,6 +31,8 @@
-
(
double
)
timeIntervalSinceFireDate
;
// If the fire date was in the past
-
(
BOOL
)
wasInThePast
;
// If the notification was already scheduled
-
(
BOOL
)
wasScheduled
;
// If the notification was already triggered
-
(
BOOL
)
wasTriggered
;
// If the notification was updated
...
...
platforms/ios/NotificationExample/Plugins/de.appplant.cordova.plugin.local-notification/UILocalNotification+APPLocalNotification.m
View file @
e071e96a
...
...
@@ -143,6 +143,32 @@ static char optionsKey;
}
/**
* Encode the user info dict to JSON.
*/
-
(
NSString
*
)
encodeToJSON
{
NSString
*
json
;
NSData
*
data
;
NSMutableDictionary
*
obj
=
[
self
.
userInfo
mutableCopy
];
[
obj
removeObjectForKey
:
@"json"
];
[
obj
removeObjectForKey
:
@"updatedAt"
];
data
=
[
NSJSONSerialization
dataWithJSONObject
:
obj
options
:
NSJSONWritingPrettyPrinted
error
:
Nil
];
json
=
[[
NSString
alloc
]
initWithData
:
data
encoding
:
NSUTF8StringEncoding
];
return
[
json
stringByReplacingOccurrencesOfString
:
@"
\n
"
withString
:
@""
];
}
#pragma mark -
#pragma mark State
/**
* If the fire date was in the past.
*/
-
(
BOOL
)
wasInThePast
...
...
@@ -150,6 +176,12 @@ static char optionsKey;
return
[
self
timeIntervalSinceFireDate
]
>
0
;
}
// If the notification was already scheduled
-
(
BOOL
)
wasScheduled
{
return
[
self
isRepeating
]
||
!
[
self
wasInThePast
];
}
/**
* If the notification was already triggered.
*/
...
...
@@ -158,9 +190,9 @@ static char optionsKey;
NSDate
*
now
=
[
NSDate
date
];
NSDate
*
fireDate
=
self
.
fireDate
;
bool
isLaterThan
OrEqualTo
=
!
([
now
compare
:
fireDate
]
==
NSOrderedAscending
);
bool
isLaterThan
FireDate
=
!
([
now
compare
:
fireDate
]
==
NSOrderedAscending
);
return
isLaterThan
OrEqualTo
;
return
isLaterThan
FireDate
;
}
/**
...
...
@@ -187,27 +219,4 @@ static char optionsKey;
return
[
self
.
options
isRepeating
];
}
/**
* Encode the user info dict to JSON.
*/
-
(
NSString
*
)
encodeToJSON
{
NSString
*
json
;
NSData
*
data
;
NSMutableDictionary
*
obj
=
[
self
.
userInfo
mutableCopy
];
[
obj
removeObjectForKey
:
@"json"
];
[
obj
removeObjectForKey
:
@"updatedAt"
];
data
=
[
NSJSONSerialization
dataWithJSONObject
:
obj
options
:
NSJSONWritingPrettyPrinted
error
:
Nil
];
json
=
[[
NSString
alloc
]
initWithData
:
data
encoding
:
NSUTF8StringEncoding
];
return
[
json
stringByReplacingOccurrencesOfString
:
@"
\n
"
withString
:
@""
];
}
@end
platforms/ios/www/index.html
View file @
e071e96a
...
...
@@ -91,21 +91,37 @@
<a
href=
"#"
class=
"button"
onclick=
"hasPermission()"
>
Has permission?
<br/><span
class=
"hint"
>
notification.local.hasPermission()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"registerPermission()"
>
Register permission
<br/><span
class=
"hint"
>
notification.local.registerPermission()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"schedule()"
>
Schedule now
<br/><span
class=
"hint"
>
notification.local.add()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"scheduleMultiple()"
>
Schedule multiple
<br/><span
class=
"hint"
>
notification.local.add()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"scheduleDelayed()"
>
Schedule in 5 sec
<br/><span
class=
"hint"
>
notification.local.add([])
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"scheduleMinutely()"
>
Schedule every min
<br/><span
class=
"hint"
>
notification.local.add()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"update()"
>
Update
<br/><span
class=
"hint"
>
notification.local.update()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"cancel()"
>
Cancel
<br/><span
class=
"hint"
>
notification.local.cancel()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"cancelMultiple()"
>
Cancel multiple
<br/><span
class=
"hint"
>
notification.local.cancel([])
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"cancelAll()"
>
Cancel all
<br/><span
class=
"hint"
>
notification.local.cancelAll()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"clear()"
>
Cancel
<br/><span
class=
"hint"
>
notification.local.clear()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"clearMultiple()"
>
Cancel multiple
<br/><span
class=
"hint"
>
notification.local.clear([])
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"clearAll()"
>
Cancel all
<br/><span
class=
"hint"
>
notification.local.clearAll()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getIds()"
>
All IDs
<br/><span
class=
"hint"
>
notification.local.getIds()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getScheduledIds()"
>
Scheduled IDs
<br/><span
class=
"hint"
>
notification.local.getScheduledIds()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isScheduled()"
>
Is scheduled?
<br/><span
class=
"hint"
>
notification.local.isScheduled()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getTriggeredIds()"
>
Triggered IDs
<br/><span
class=
"hint"
>
notification.local.getTriggeredIds()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isTriggered()"
>
Is triggered?
<br/><span
class=
"hint"
>
notification.local.isTriggered()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"exists()"
>
Exists?
<br/><span
class=
"hint"
>
notification.local.exists()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isScheduled()"
>
Scheduled?
<br/><span
class=
"hint"
>
notification.local.isScheduled()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isTriggered()"
>
Triggered?
<br/><span
class=
"hint"
>
notification.local.isTriggered()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getAll()"
>
All Notifications
<br/><span
class=
"hint"
>
notification.local.get()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getScheduled()"
>
Scheduled Notifications
<br/><span
class=
"hint"
>
notification.local.getScheduled()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getTriggered()"
>
Triggered Notifications
<br/><span
class=
"hint"
>
notification.local.getTriggered()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"setDefaultTitle()"
>
Change default title
<br/><span
class=
"hint"
>
notification.local.setDefaults()
</span></a>
</div>
</div>
<script
type=
"text/javascript"
src=
"cordova.js"
></script>
<script
type=
"text/javascript"
src=
"js/index.js"
></script>
...
...
@@ -113,23 +129,23 @@
var
counter
=
0
,
id
=
1
;
var
callback
=
function
()
{
get
Scheduled
Ids
();
getIds
();
};
hasPermission
=
function
()
{
plugin
.
notification
.
local
.
hasPermission
(
function
(
granted
)
{
cordova
.
plugins
.
notification
.
local
.
hasPermission
(
function
(
granted
)
{
alert
(
granted
);
});
};
registerPermission
=
function
()
{
plugin
.
notification
.
local
.
registerPermission
(
function
(
granted
)
{
cordova
.
plugins
.
notification
.
local
.
registerPermission
(
function
(
granted
)
{
alert
(
granted
);
});
};
schedule
=
function
()
{
plugin
.
notification
.
local
.
add
({
cordova
.
plugins
.
notification
.
local
.
add
({
id
:
id
,
message
:
'Test Message '
+
(
++
counter
),
json
:
{
test
:
id
}
...
...
@@ -137,7 +153,7 @@
};
scheduleMultiple
=
function
()
{
plugin
.
notification
.
local
.
add
([{
cordova
.
plugins
.
notification
.
local
.
add
([{
id
:
id
,
message
:
'Multi Message '
+
(
++
counter
)
},{
...
...
@@ -153,7 +169,7 @@
var
now
=
new
Date
().
getTime
(),
_5_sec_from_now
=
new
Date
(
now
+
5
*
1000
);
plugin
.
notification
.
local
.
add
({
cordova
.
plugins
.
notification
.
local
.
add
({
id
:
id
,
title
:
'Scheduled with delay'
,
message
:
'Test Message '
+
(
++
counter
),
...
...
@@ -163,7 +179,7 @@
};
scheduleMinutely
=
function
()
{
plugin
.
notification
.
local
.
add
({
cordova
.
plugins
.
notification
.
local
.
add
({
id
:
id
,
message
:
'Scheduled every minute'
,
repeat
:
'minutely'
,
...
...
@@ -172,7 +188,7 @@
};
update
=
function
()
{
plugin
.
notification
.
local
.
update
({
cordova
.
plugins
.
notification
.
local
.
update
({
id
:
id
,
message
:
'Updated Message '
+
(
counter
),
json
:
{
updated
:
true
}
...
...
@@ -181,69 +197,123 @@
cancel
=
function
()
{
counter
=
0
;
plugin
.
notification
.
local
.
cancel
(
id
,
callback
);
cordova
.
plugins
.
notification
.
local
.
cancel
(
id
,
callback
);
};
cancelMultiple
=
function
()
{
counter
=
0
;
plugin
.
notification
.
local
.
cancel
([
id
,
id
+
1
],
callback
);
cordova
.
plugins
.
notification
.
local
.
cancel
([
id
,
id
+
1
],
callback
);
};
cancelAll
=
function
()
{
counter
=
0
;
plugin
.
notification
.
local
.
cancelAll
(
callback
);
cordova
.
plugins
.
notification
.
local
.
cancelAll
(
callback
);
};
getScheduledIds
=
function
()
{
plugin
.
notification
.
local
.
getScheduledIds
(
function
(
ids
)
{
alert
(
'Scheduled IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
clear
=
function
()
{
counter
=
0
;
cordova
.
plugins
.
notification
.
local
.
clear
(
id
,
callback
);
};
clearMultiple
=
function
()
{
counter
=
0
;
cordova
.
plugins
.
notification
.
local
.
clear
([
id
,
id
+
1
],
callback
);
};
clearAll
=
function
()
{
counter
=
0
;
cordova
.
plugins
.
notification
.
local
.
clearAll
(
callback
);
};
setDefaultTitle
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
setDefaults
({
title
:
'New Default Title'
});
};
</script>
<!-- getters bool -->
<script
type=
"text/javascript"
>
exists
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
exists
(
id
,
function
(
exists
)
{
alert
(
'Notification with ID '
+
id
+
' exists:
\
n'
+
exists
);
});
};
isScheduled
=
function
()
{
plugin
.
notification
.
local
.
isScheduled
(
id
,
function
(
isScheduled
)
{
cordova
.
plugins
.
notification
.
local
.
isScheduled
(
id
,
function
(
isScheduled
)
{
alert
(
'Notification with ID '
+
id
+
' is scheduled:
\
n'
+
isScheduled
);
});
};
isTriggered
=
function
()
{
plugin
.
notification
.
local
.
isTriggered
(
id
,
function
(
isTriggered
)
{
cordova
.
plugins
.
notification
.
local
.
isTriggered
(
id
,
function
(
isTriggered
)
{
alert
(
'Notification with ID '
+
id
+
' is triggered:
\
n'
+
isTriggered
);
});
};
</script>
<!-- getters ID -->
<script
type=
"text/javascript"
>
getIds
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getIds
(
function
(
ids
)
{
alert
(
'IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
});
};
getScheduledIds
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getScheduledIds
(
function
(
ids
)
{
alert
(
'Scheduled IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
});
};
getTriggeredIds
=
function
()
{
plugin
.
notification
.
local
.
getTriggeredIds
(
function
(
ids
)
{
cordova
.
plugins
.
notification
.
local
.
getTriggeredIds
(
function
(
ids
)
{
alert
(
'Triggered IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
});
};
</script>
setDefaultTitle
=
function
()
{
plugin
.
notification
.
local
.
setDefaults
({
title
:
'New Default Title'
,
<!-- getters object -->
<script
type=
"text/javascript"
>
getAll
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getAll
(
function
(
data
)
{
alert
(
'Notifications:
\
n['
+
data
.
join
(
' ,'
)
+
']'
);
});
};
</script>
getScheduled
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getScheduled
(
function
(
data
)
{
alert
(
'Scheduled Notifications:
\
n['
+
data
.
join
(
' ,'
)
+
']'
);
});
};
getTriggered
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getTriggered
(
function
(
data
)
{
alert
(
'Triggered Notifications:
\
n['
+
data
.
join
(
' ,'
)
+
']'
);
});
};
</script>
<!-- callbacks -->
<script
type=
"text/javascript"
>
document
.
addEventListener
(
'deviceready'
,
function
()
{
plugin
.
notification
.
local
.
onadd
=
function
(
id
,
state
,
json
)
{
document
.
addEventListener
(
'
s
deviceready'
,
function
()
{
cordova
.
plugins
.
notification
.
local
.
onadd
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on add
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
plugin
.
notification
.
local
.
ontrigger
=
function
(
id
,
state
,
json
)
{
cordova
.
plugins
.
notification
.
local
.
ontrigger
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on trigger
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
plugin
.
notification
.
local
.
onclick
=
function
(
id
,
state
,
json
)
{
cordova
.
plugins
.
notification
.
local
.
onclick
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on click
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
plugin
.
notification
.
local
.
oncancel
=
function
(
id
,
state
,
json
)
{
cordova
.
plugins
.
notification
.
local
.
oncancel
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on cancel
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
...
...
platforms/ios/www/plugins/de.appplant.cordova.plugin.local-notification/www/local-notification.js
View file @
e071e96a
...
...
@@ -67,7 +67,8 @@ exports._defaults = {
badge
:
-
1
,
id
:
'0'
,
json
:
''
,
repeat
:
''
repeat
:
''
,
date
:
undefined
};
...
...
@@ -208,6 +209,29 @@ exports.cancelAll = function (callback, scope) {
};
/**
* Check if a notification with an ID exists.
*
* @param {String} id
* The ID of the notification
* @param {Function} callback
* A callback function to be called with the list
* @param {Object?} scope
* The scope for the callback function
*/
exports
.
exist
=
function
(
id
,
callback
,
scope
)
{
var
notId
=
(
id
||
'0'
).
toString
();
this
.
exec
(
'exist'
,
notId
,
callback
,
scope
);
};
/**
* Alias for `exist`.
*/
exports
.
exists
=
function
()
{
this
.
exist
.
apply
(
this
,
arguments
);
};
/**
* Check if a notification with an ID is scheduled.
*
* @param {String} id
...
...
@@ -240,7 +264,26 @@ exports.isTriggered = function (id, callback, scope) {
};
/**
* List all currently pending notifications.
* List all local notification IDs.
*
* @param {Function} callback
* A callback function to be called with the list
* @param {Object?} scope
* The scope for the callback function
*/
exports
.
getAllIds
=
function
(
callback
,
scope
)
{
this
.
exec
(
'getAllIds'
,
null
,
callback
,
scope
);
};
/**
* Alias for `getAllIds`.
*/
exports
.
getIds
=
function
()
{
this
.
getAllIds
.
apply
(
this
,
arguments
);
};
/**
* List all scheduled notification IDs.
*
* @param {Function} callback
* A callback function to be called with the list
...
...
@@ -252,7 +295,7 @@ exports.getScheduledIds = function (callback, scope) {
};
/**
* List all triggered notifications.
* List all triggered notification
ID
s.
*
* @param {Function} callback
* A callback function to be called with the list
...
...
@@ -264,7 +307,50 @@ exports.getTriggeredIds = function (callback, scope) {
};
/**
* List all properties for given scheduled notifications.
* Property list for given local notifications.
* If called without IDs, all notification will be returned.
*
* @param {Number[]?} ids
* Set of notification IDs
* @param {Function} callback
* A callback function to be called with the list
* @param {Object?} scope
* The scope for the callback function
*/
exports
.
get
=
function
()
{
var
args
=
Array
.
apply
(
null
,
arguments
);
if
(
typeof
args
[
0
]
==
'function'
)
{
args
.
unshift
([]);
}
var
ids
=
args
[
0
],
callback
=
args
[
1
],
scope
=
args
[
2
];
if
(
!
Array
.
isArray
(
ids
))
{
ids
=
[
ids
];
}
ids
=
this
.
convertIds
(
ids
);
this
.
exec
(
'getAll'
,
ids
,
callback
,
scope
);
};
/**
* Property list for all local notifications.
*
* @param {Function} callback
* A callback function to be called with the list
* @param {Object?} scope
* The scope for the callback function
*/
exports
.
getAll
=
function
(
callback
,
scope
)
{
this
.
exec
(
'getAll'
,
null
,
callback
,
scope
);
};
/**
* Property list for given scheduled notifications.
* If called without IDs, all notification will be returned.
*
* @param {Number[]?} ids
...
...
@@ -307,7 +393,7 @@ exports.getAllScheduled = function (callback, scope) {
};
/**
*
List all properties
for given triggered notifications.
*
Property list
for given triggered notifications.
* If called without IDs, all notification will be returned.
*
* @param {Number[]?} ids
...
...
plugins/de.appplant.cordova.plugin.local-notification/src/android/notification/Asset.java
0 → 100644
View file @
e071e96a
/*
Copyright 2013-2014 appPlant UG
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.app.Activity
;
import
android.content.res.AssetManager
;
import
android.content.res.Resources
;
import
android.media.RingtoneManager
;
import
android.net.Uri
;
import
android.os.StrictMode
;
import
android.util.Log
;
public
class
Asset
{
private
Activity
activity
;
protected
final
String
STORAGE_FOLDER
;
/**
* Constructor of Asset Class. Takes Applications Activity and a foldername for temporary saving.
*
*@param activity Applications Activity
*@param storageFolder foldername for temporary saving.
*/
public
Asset
(
Activity
activity
,
String
storageFolder
){
this
.
activity
=
activity
;
this
.
STORAGE_FOLDER
=
storageFolder
;
}
/**
* Parse given PathStrings to Uris
* @param notification Notifications JSONObject
* @return new Notification JSONObject with additional iconUri and soundUri
*/
public
JSONObject
parseURIs
(
JSONObject
notification
){
//sound
String
sound
=
notification
.
optString
(
"sound"
,
null
);
Uri
soundUri
=
null
;
if
(
sound
!=
null
)
{
try
{
int
soundId
=
(
Integer
)
RingtoneManager
.
class
.
getDeclaredField
(
sound
).
get
(
Integer
.
class
);
soundUri
=
RingtoneManager
.
getDefaultUri
(
soundId
);
}
catch
(
Exception
e
)
{
soundUri
=
getURIfromPath
(
sound
);
}
}
if
(
soundUri
!=
null
&&
soundUri
!=
Uri
.
EMPTY
){
try
{
notification
.
put
(
"soundUri"
,
soundUri
.
toString
());
}
catch
(
JSONException
jse
){
jse
.
printStackTrace
();
}
}
//image
String
icon
=
notification
.
optString
(
"icon"
,
"icon"
);
Uri
iconUri
=
null
;
iconUri
=
getURIfromPath
(
icon
);
if
(
iconUri
!=
Uri
.
EMPTY
&&
iconUri
!=
null
){
try
{
notification
.
put
(
"iconUri"
,
iconUri
.
toString
());
}
catch
(
JSONException
jse
){
jse
.
printStackTrace
();
}
}
return
notification
;
}
/**
* The URI for a path.
*
* @param path The given path
*
* @return The URI pointing to the given path
*/
public
Uri
getURIfromPath
(
String
path
){
if
(
path
.
startsWith
(
"res:"
))
{
return
getUriForResourcePath
(
path
);
}
else
if
(
path
.
startsWith
(
"file:///"
))
{
return
getUriForAbsolutePath
(
path
);
}
else
if
(
path
.
startsWith
(
"file://"
))
{
return
getUriForAssetPath
(
path
);
}
else
if
(
path
.
startsWith
(
"http"
)){
return
getUriForHTTP
(
path
);
}
return
Uri
.
parse
(
path
);
}
/**
* The URI for a file.
*
* @param path
* The given absolute path
*
* @return The URI pointing to the given path
*/
private
Uri
getUriForAbsolutePath
(
String
path
)
{
String
absPath
=
path
.
replaceFirst
(
"file://"
,
""
);
File
file
=
new
File
(
absPath
);
if
(!
file
.
exists
())
{
Log
.
e
(
"Asset"
,
"File not found: "
+
file
.
getAbsolutePath
());
return
Uri
.
EMPTY
;
}
return
Uri
.
fromFile
(
file
);
}
/**
* The URI for an asset.
*
* @param path
* The given asset path
*
* @return The URI pointing to the given path
*/
private
Uri
getUriForAssetPath
(
String
path
)
{
String
resPath
=
path
.
replaceFirst
(
"file:/"
,
"www"
);
String
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
File
dir
=
activity
.
getExternalCacheDir
();
if
(
dir
==
null
)
{
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
return
Uri
.
EMPTY
;
}
String
storage
=
dir
.
toString
()
+
STORAGE_FOLDER
;
File
file
=
new
File
(
storage
,
fileName
);
new
File
(
storage
).
mkdir
();
try
{
AssetManager
assets
=
activity
.
getAssets
();
FileOutputStream
outStream
=
new
FileOutputStream
(
file
);
InputStream
inputStream
=
assets
.
open
(
resPath
);
copyFile
(
inputStream
,
outStream
);
outStream
.
flush
();
outStream
.
close
();
return
Uri
.
fromFile
(
file
);
}
catch
(
Exception
e
)
{
Log
.
e
(
"Asset"
,
"File not found: assets/"
+
resPath
);
e
.
printStackTrace
();
}
return
Uri
.
EMPTY
;
}
/**
* The URI for a resource.
*
* @param path
* The given relative path
*
* @return The URI pointing to the given path
*/
private
Uri
getUriForResourcePath
(
String
path
)
{
String
resPath
=
path
.
replaceFirst
(
"res://"
,
""
);
String
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
String
resName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
'.'
));
String
extension
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'.'
));
File
dir
=
activity
.
getExternalCacheDir
();
if
(
dir
==
null
)
{
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
return
Uri
.
EMPTY
;
}
String
storage
=
dir
.
toString
()
+
STORAGE_FOLDER
;
int
resId
=
getResId
(
resPath
);
File
file
=
new
File
(
storage
,
resName
+
extension
);
if
(
resId
==
0
)
{
Log
.
e
(
"Asset"
,
"File not found: "
+
resPath
);
return
Uri
.
EMPTY
;
}
new
File
(
storage
).
mkdir
();
try
{
Resources
res
=
activity
.
getResources
();
FileOutputStream
outStream
=
new
FileOutputStream
(
file
);
InputStream
inputStream
=
res
.
openRawResource
(
resId
);
copyFile
(
inputStream
,
outStream
);
outStream
.
flush
();
outStream
.
close
();
return
Uri
.
fromFile
(
file
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
Uri
.
EMPTY
;
}
/**
*Get Uri for HTTP Content
* @param path HTTP adress
* @return Uri of the downloaded file
*/
private
Uri
getUriForHTTP
(
String
path
)
{
try
{
URL
url
=
new
URL
(
path
);
String
fileName
=
path
.
substring
(
path
.
lastIndexOf
(
'/'
)
+
1
);
String
resName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
'.'
));
String
extension
=
path
.
substring
(
path
.
lastIndexOf
(
'.'
));
File
dir
=
activity
.
getExternalCacheDir
();
if
(
dir
==
null
)
{
Log
.
e
(
"Asset"
,
"Missing external cache dir"
);
return
Uri
.
EMPTY
;
}
String
storage
=
dir
.
toString
()
+
STORAGE_FOLDER
;
File
file
=
new
File
(
storage
,
resName
+
extension
);
new
File
(
storage
).
mkdir
();
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
();
FileOutputStream
outStream
=
new
FileOutputStream
(
file
);
copyFile
(
input
,
outStream
);
outStream
.
flush
();
outStream
.
close
();
return
Uri
.
fromFile
(
file
);
}
catch
(
MalformedURLException
e
)
{
Log
.
e
(
"Asset"
,
"Incorrect URL"
);
e
.
printStackTrace
();
}
catch
(
FileNotFoundException
e
)
{
Log
.
e
(
"Asset"
,
"Failed to create new File from HTTP Content"
);
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
Log
.
e
(
"Asset"
,
"No Input can be created from http Stream"
);
e
.
printStackTrace
();
}
return
Uri
.
EMPTY
;
}
/**
* Writes an InputStream to an OutputStream
*
* @param in
* The input stream
* @param out
* The output stream
*/
private
void
copyFile
(
InputStream
in
,
OutputStream
out
)
throws
IOException
{
byte
[]
buffer
=
new
byte
[
1024
];
int
read
;
while
((
read
=
in
.
read
(
buffer
))
!=
-
1
)
{
out
.
write
(
buffer
,
0
,
read
);
}
}
/**
* @return The resource ID for the given resource.
*/
private
int
getResId
(
String
resPath
)
{
Resources
res
=
activity
.
getResources
();
int
resId
;
String
pkgName
=
getPackageName
();
String
dirName
=
"drawable"
;
String
fileName
=
resPath
;
if
(
resPath
.
contains
(
"/"
))
{
dirName
=
resPath
.
substring
(
0
,
resPath
.
lastIndexOf
(
'/'
));
fileName
=
resPath
.
substring
(
resPath
.
lastIndexOf
(
'/'
)
+
1
);
}
String
resName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
'.'
));
resId
=
res
.
getIdentifier
(
resName
,
dirName
,
pkgName
);
if
(
resId
==
0
)
{
resId
=
res
.
getIdentifier
(
resName
,
"drawable"
,
pkgName
);
}
return
resId
;
}
/**
* The name for the package.
*
* @return The package name
*/
private
String
getPackageName
()
{
return
activity
.
getPackageName
();
}
}
plugins/de.appplant.cordova.plugin.local-notification/src/android/notification/Manager.java
0 → 100644
View file @
e071e96a
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
java.util.Date
;
import
java.util.Map
;
import
java.util.Set
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences.Editor
;
import
android.os.Build
;
public
class
Manager
{
//---------------Global Parameter------------------------------------------------------------
private
Context
context
;
private
final
String
PLUGIN_NAME
;
//---------------Constructor-----------------------------------------------------------------
/**
* Constructor of NotificationWrapper-Class
*/
public
Manager
(
Context
context
,
String
PluginName
){
this
.
context
=
context
;
this
.
PLUGIN_NAME
=
PluginName
;
}
//---------------Public Functions------------------------------------------------------------
/**
* Checks if a notification with an ID is scheduled.
*
* @param id
* The notification ID to be check.
* @return true if the notification is scheduled
*/
public
boolean
isScheduled
(
String
id
)
{
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
boolean
isScheduled
=
alarms
.
containsKey
(
id
);
boolean
isNotTriggered
=
false
;
if
(
isScheduled
)
{
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getDate
());
isNotTriggered
=
new
Date
().
before
(
fireDate
);
}
catch
(
JSONException
e
)
{
isNotTriggered
=
false
;
e
.
printStackTrace
();
}
}
return
(
isScheduled
&&
isNotTriggered
);
}
/**
* Checks if a notification with an ID was triggered.
*
* @param id
* The notification ID to be check.
* @return true if the notification is triggered
*/
public
boolean
isTriggered
(
String
id
)
{
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
boolean
isScheduled
=
alarms
.
containsKey
(
id
);
boolean
isTriggered
=
isScheduled
;
if
(
isScheduled
)
{
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getInitialDate
());
isTriggered
=
new
Date
().
after
(
fireDate
);
}
catch
(
JSONException
e
)
{
isTriggered
=
false
;
e
.
printStackTrace
();
}
}
return
isTriggered
;
}
/**
* Checks whether a notification with an ID exist.
*
* @param id
* The notification ID to check.
* @return true if the notification exist
*/
public
boolean
exist
(
String
id
){
boolean
exist
;
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
exist
=
alarms
.
containsKey
(
id
);
return
exist
;
}
/**
* Retrieves a list with all currently pending notification Ids.
*
* @return JSONArray with all Id-Strings
*/
public
JSONArray
getScheduledIds
()
{
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
scheduledIds
=
new
JSONArray
();
for
(
String
id
:
alarmIds
)
{
boolean
isScheduled
;
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getDate
());
isScheduled
=
new
Date
().
before
(
fireDate
);
}
catch
(
JSONException
e
)
{
isScheduled
=
false
;
e
.
printStackTrace
();
}
if
(
isScheduled
){
scheduledIds
.
put
(
id
);
}
}
return
scheduledIds
;
}
/**
* Retrieves a list with all currently triggered notification Ids.
*
* @return JSONArray with all Id-Strings
*/
public
JSONArray
getTriggeredIds
()
{
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
triggeredIds
=
new
JSONArray
();
Date
now
=
new
Date
();
for
(
String
id
:
alarmIds
)
{
boolean
isTriggered
;
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getInitialDate
());
isTriggered
=
now
.
after
(
fireDate
);
}
catch
(
ClassCastException
cce
)
{
cce
.
printStackTrace
();
isTriggered
=
false
;
}
catch
(
JSONException
jse
)
{
jse
.
printStackTrace
();
isTriggered
=
false
;
}
if
(
isTriggered
==
true
)
{
triggeredIds
.
put
(
id
);
}
}
return
triggeredIds
;
}
/**
* Retrieves a list with all currently triggered or scheduled notification-Ids.
* @return JSONArray with all Id-Strings
*/
public
JSONArray
getAllIds
(){
JSONArray
allIds
=
new
JSONArray
();
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
for
(
String
id
:
alarmIds
)
{
allIds
.
put
(
id
);
}
return
allIds
;
}
/**
* Retrieves a list with all currently pending notification JSONObject.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getAll
(){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
all
=
new
JSONArray
();
for
(
String
id
:
alarmIds
)
{
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
all
.
put
(
arguments
);
}
catch
(
JSONException
jse
)
{
jse
.
printStackTrace
();
}
}
return
all
;
}
/**
* Retrieves a list with all currently scheduled notification-JSONObjects.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getScheduled
(){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
scheduled
=
new
JSONArray
();
for
(
String
id
:
alarmIds
)
{
boolean
isScheduled
;
JSONObject
arguments
=
null
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getDate
());
isScheduled
=
new
Date
().
before
(
fireDate
);
}
catch
(
JSONException
e
)
{
isScheduled
=
false
;
e
.
printStackTrace
();
}
if
(
isScheduled
){
scheduled
.
put
(
arguments
);
}
}
return
scheduled
;
}
/**
* Retrieves a list with all currently triggered notification-JSONObjects.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getTriggered
(){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
triggered
=
new
JSONArray
();
Date
now
=
new
Date
();
for
(
String
id
:
alarmIds
)
{
boolean
isTriggered
;
JSONObject
arguments
=
null
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getInitialDate
());
isTriggered
=
now
.
after
(
fireDate
);
}
catch
(
ClassCastException
cce
)
{
cce
.
printStackTrace
();
isTriggered
=
false
;
}
catch
(
JSONException
jse
)
{
jse
.
printStackTrace
();
isTriggered
=
false
;
}
if
(
isTriggered
==
true
)
{
triggered
.
put
(
arguments
);
}
}
return
triggered
;
}
/**
* Retrieves a list with all currently pending notification JSONObject.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getAll
(
JSONArray
ids
){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
all
=
new
JSONArray
();
for
(
String
id
:
alarmIds
)
{
for
(
int
i
=
0
;
i
<
ids
.
length
();
i
++){
if
(
ids
.
optString
(
i
).
equals
(
id
)){
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
all
.
put
(
arguments
);
}
catch
(
JSONException
jse
)
{
jse
.
printStackTrace
();
}
}
}
}
return
all
;
}
/**
* Retrieves a list with all currently scheduled notification-JSONObjects.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getScheduled
(
JSONArray
ids
){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
scheduled
=
new
JSONArray
();
boolean
isScheduled
;
for
(
String
id
:
alarmIds
)
{
for
(
int
i
=
0
;
i
<
ids
.
length
();
i
++){
if
(
ids
.
optString
(
i
).
equals
(
id
)){
JSONObject
arguments
=
null
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getDate
());
isScheduled
=
new
Date
().
before
(
fireDate
);
}
catch
(
JSONException
e
)
{
isScheduled
=
false
;
e
.
printStackTrace
();
}
if
(
isScheduled
){
scheduled
.
put
(
arguments
);
}
}
}
}
return
scheduled
;
}
/**
* Retrieves a list with all currently triggered notification-JSONObjects.
*
* @return JSONArray with all notification-JSONObjects
*/
public
JSONArray
getTriggered
(
JSONArray
ids
){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
JSONArray
triggered
=
new
JSONArray
();
Date
now
=
new
Date
();
for
(
String
id
:
alarmIds
)
{
for
(
int
i
=
0
;
i
<
ids
.
length
();
i
++){
if
(
ids
.
optString
(
i
).
equals
(
id
)){
boolean
isTriggered
;
JSONObject
arguments
=
null
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
fireDate
=
new
Date
(
options
.
getInitialDate
());
isTriggered
=
now
.
after
(
fireDate
);
}
catch
(
ClassCastException
cce
)
{
cce
.
printStackTrace
();
isTriggered
=
false
;
}
catch
(
JSONException
jse
)
{
jse
.
printStackTrace
();
isTriggered
=
false
;
}
if
(
isTriggered
==
true
)
{
triggered
.
put
(
arguments
);
}
}
}
}
return
triggered
;
}
//---------------Manage Shared Preferences---------------------------------------------------
/**
* The Local storage for the application.
*/
private
SharedPreferences
getSharedPreferences
()
{
return
context
.
getSharedPreferences
(
PLUGIN_NAME
,
Context
.
MODE_PRIVATE
);
}
/**
* Persist the information of this alarm to the Android Shared Preferences.
* This will allow the application to restore the alarm upon device reboot.
* Also this is used by the cancelAll method.
*
* @param alarmId
* The Id of the notification that must be persisted.
* @param args
* The assumption is that parse has been called already.
*/
public
void
persist
(
String
alarmId
,
JSONObject
args
)
{
Editor
editor
=
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
putString
(
alarmId
,
args
.
toString
());
if
(
Build
.
VERSION
.
SDK_INT
<
9
)
{
editor
.
commit
();
}
else
{
editor
.
apply
();
}
}
}
/**
* Remove a specific alarm from the Android shared Preferences.
*
* @param alarmId
* The Id of the notification that must be removed.
*/
public
void
unpersist
(
String
alarmId
)
{
Editor
editor
=
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
remove
(
alarmId
);
if
(
Build
.
VERSION
.
SDK_INT
<
9
)
{
editor
.
commit
();
}
else
{
editor
.
apply
();
}
}
}
}
plugins/de.appplant.cordova.plugin.local-notification/src/android/notification/NotificationBuilder.java
0 → 100644
View file @
e071e96a
/*
Copyright 2013-2014 appPlant UG
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
java.util.Random
;
import
android.annotation.SuppressLint
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationCompat.Builder
;
public
class
NotificationBuilder
{
private
Options
options
;
private
Context
context
;
private
Builder
notification
;
private
final
String
OPTIONS
;
private
Class
<?>
deleteIntentReceiver
;
private
Class
<?>
receiverActivity
;
/**
* Constructor of NotificationBuilder
* @param options
* @param context
* @param OPTIONS
* @param deleteIntentReceiver
* @param receiverActivity
*/
public
NotificationBuilder
(
Options
options
,
Context
context
,
String
OPTIONS
,
Class
<?>
deleteIntentReceiver
,
Class
<?>
receiverActivity
){
this
.
options
=
options
;
this
.
context
=
context
;
this
.
OPTIONS
=
OPTIONS
;
this
.
deleteIntentReceiver
=
deleteIntentReceiver
;
this
.
receiverActivity
=
receiverActivity
;
}
/**
* Creates the notification.
*/
@SuppressLint
(
"NewApi"
)
public
Builder
buildNotification
()
{
Uri
sound
=
options
.
getSound
();
//DeleteIntent is called when the user clears a notification manually
Intent
deleteIntent
=
new
Intent
(
context
,
deleteIntentReceiver
)
.
setAction
(
""
+
options
.
getId
())
.
putExtra
(
OPTIONS
,
options
.
getJSONObject
().
toString
());
PendingIntent
dpi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
deleteIntent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
notification
=
new
NotificationCompat
.
Builder
(
context
)
.
setDefaults
(
0
)
// Do not inherit any defaults
.
setContentTitle
(
options
.
getTitle
())
.
setContentText
(
options
.
getMessage
())
.
setNumber
(
options
.
getBadge
())
.
setTicker
(
options
.
getMessage
())
.
setSmallIcon
(
options
.
getSmallIcon
())
.
setLargeIcon
(
options
.
getIcon
())
.
setAutoCancel
(
options
.
getAutoCancel
())
.
setOngoing
(
options
.
getOngoing
())
.
setLights
(
options
.
getColor
(),
500
,
500
)
.
setDeleteIntent
(
dpi
);
if
(
sound
!=
null
)
{
notification
.
setSound
(
sound
);
}
if
(
Build
.
VERSION
.
SDK_INT
>
16
)
{
notification
.
setStyle
(
new
NotificationCompat
.
BigTextStyle
()
.
bigText
(
options
.
getMessage
()));
}
setClickEvent
(
notification
);
return
notification
;
}
/**
* Adds an onclick handler to the notification
*/
private
Builder
setClickEvent
(
Builder
notification
)
{
Intent
intent
=
new
Intent
(
context
,
receiverActivity
)
.
putExtra
(
OPTIONS
,
options
.
getJSONObject
().
toString
())
.
setFlags
(
Intent
.
FLAG_ACTIVITY_NO_HISTORY
);
int
requestCode
=
new
Random
().
nextInt
();
PendingIntent
contentIntent
=
PendingIntent
.
getActivity
(
context
,
requestCode
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
return
notification
.
setContentIntent
(
contentIntent
);
}
}
plugins/de.appplant.cordova.plugin.local-notification/src/android/notification/NotificationWrapper.java
0 → 100644
View file @
e071e96a
/*
Copyright 2013-2014 appPlant UG
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
java.util.Date
;
import
java.util.Map
;
import
java.util.Set
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.app.AlarmManager
;
import
android.app.NotificationManager
;
import
android.app.PendingIntent
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences.Editor
;
import
android.os.Build
;
import
android.support.v4.app.NotificationCompat.Builder
;
import
android.widget.Toast
;
/**
* Wrapper class to schedule, cancel, clear, and update notifications.
*
*/
public
class
NotificationWrapper
{
//---------------Global Parameter------------------------------------------------------------
private
Context
context
;
private
Class
<?>
receiver
;
private
final
String
PLUGIN_NAME
;
private
final
String
OPTIONS
;
//---------------Constructor-----------------------------------------------------------------
/**
* Constructor of NotificationWrapper-Class
*/
public
NotificationWrapper
(
Context
context
,
Class
<?>
receiver
,
String
PluginName
,
String
OPTIONS
){
this
.
context
=
context
;
this
.
receiver
=
receiver
;
this
.
PLUGIN_NAME
=
PluginName
;
this
.
OPTIONS
=
OPTIONS
;
}
//---------------public functions------------------------------------------------------------
/**
* Schedule new notification
*/
public
void
schedule
(
Options
options
){
long
triggerTime
=
options
.
getDate
();
persist
(
options
.
getId
(),
options
.
getJSONObject
());
//Intent is called when the Notification gets fired
Intent
intent
=
new
Intent
(
context
,
receiver
)
.
setAction
(
""
+
options
.
getId
())
.
putExtra
(
OPTIONS
,
options
.
getJSONObject
().
toString
());
AlarmManager
am
=
getAlarmManager
();
PendingIntent
pi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
PendingIntent
.
FLAG_CANCEL_CURRENT
);
am
.
set
(
AlarmManager
.
RTC_WAKEUP
,
triggerTime
,
pi
);
}
/**
* Cancel existing notification
*/
public
void
cancel
(
String
notificationId
){
/*
* Create an intent that looks similar, to the one that was registered
* using add. Making sure the notification id in the action is the same.
* Now we can search for such an intent using the 'getService' method
* and cancel it.
*/
Intent
intent
=
new
Intent
(
context
,
receiver
)
.
setAction
(
""
+
notificationId
);
PendingIntent
pi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
0
);
AlarmManager
am
=
getAlarmManager
();
NotificationManager
nc
=
getNotificationManager
();
am
.
cancel
(
pi
);
try
{
nc
.
cancel
(
Integer
.
parseInt
(
notificationId
));
}
catch
(
Exception
e
)
{}
unpersist
(
notificationId
);
}
/**
* Cancel all notifications that were created by this plugin.
*
* Android can only unregister a specific alarm. There is no such thing
* as cancelAll. Therefore we rely on the Shared Preferences which holds
* all our alarms to loop through these alarms and unregister them one
* by one.
*/
public
void
cancelAll
()
{
SharedPreferences
settings
=
getSharedPreferences
();
NotificationManager
nc
=
getNotificationManager
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
for
(
String
alarmId
:
alarmIds
)
{
cancel
(
alarmId
);
}
nc
.
cancelAll
();
}
/**
* Update an existing notification
*
* @param updates JSONObject with update-content
*/
public
void
update
(
JSONObject
updates
){
String
id
=
updates
.
optString
(
"id"
,
"0"
);
// update shared preferences
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
id
).
toString
());
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
return
;
}
arguments
=
updateArguments
(
arguments
,
updates
);
// cancel existing alarm
Intent
intent
=
new
Intent
(
context
,
receiver
)
.
setAction
(
""
+
id
);
PendingIntent
pi
=
PendingIntent
.
getBroadcast
(
context
,
0
,
intent
,
0
);
AlarmManager
am
=
getAlarmManager
();
am
.
cancel
(
pi
);
//add new alarm
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
schedule
(
options
);
}
/**
* Clear a specific notification without canceling repeating alarms
*
* @param notificationID
* The original ID of the notification that was used when it was
* registered using add()
*/
public
void
clear
(
String
notificationId
){
SharedPreferences
settings
=
getSharedPreferences
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
NotificationManager
nc
=
getNotificationManager
();
try
{
nc
.
cancel
(
Integer
.
parseInt
(
notificationId
));
}
catch
(
Exception
e
)
{}
JSONObject
arguments
;
try
{
arguments
=
new
JSONObject
(
alarms
.
get
(
notificationId
).
toString
());
Options
options
=
new
Options
(
context
).
parse
(
arguments
);
Date
now
=
new
Date
();
if
((
options
.
getInterval
()!=
0
)){
persist
(
notificationId
,
setInitDate
(
arguments
));
}
else
if
((
new
Date
(
options
.
getDate
()).
before
(
now
))){
unpersist
(
notificationId
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
return
;
}
}
/**
* Clear all notifications without canceling repeating alarms
*/
public
void
clearAll
(){
SharedPreferences
settings
=
getSharedPreferences
();
NotificationManager
nc
=
getNotificationManager
();
Map
<
String
,
?>
alarms
=
settings
.
getAll
();
Set
<
String
>
alarmIds
=
alarms
.
keySet
();
for
(
String
alarmId
:
alarmIds
)
{
clear
(
alarmId
);
}
nc
.
cancelAll
();
}
/**
* Shows the notification
*/
@SuppressWarnings
(
"deprecation"
)
public
void
showNotification
(
Builder
notification
,
Options
options
)
{
NotificationManager
mgr
=
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
int
id
=
0
;
try
{
id
=
Integer
.
parseInt
(
options
.
getId
());
}
catch
(
Exception
e
)
{}
if
(
Build
.
VERSION
.
SDK_INT
<
16
)
{
// build notification for HoneyComb to ICS
mgr
.
notify
(
id
,
notification
.
getNotification
());
}
else
if
(
Build
.
VERSION
.
SDK_INT
>
15
)
{
// Notification for Jellybean and above
mgr
.
notify
(
id
,
notification
.
build
());
}
}
/**
* Show a notification as a Toast when App is runing in foreground
* @param title Title of the notification
* @param notification Notification to show
*/
public
void
showNotificationToast
(
Options
options
){
String
title
=
options
.
getTitle
();
String
message
=
options
.
getMessage
();
int
duration
=
Toast
.
LENGTH_LONG
;
if
(
title
.
equals
(
""
)){
title
=
"Notification"
;
}
String
text
=
title
+
" \n "
+
message
;
Toast
notificationToast
=
Toast
.
makeText
(
context
,
text
,
duration
);
notificationToast
.
show
();
}
//---------------Manage Shared Preferences---------------------------------------------------
/**
* The Local storage for the application.
*/
private
SharedPreferences
getSharedPreferences
()
{
return
context
.
getSharedPreferences
(
PLUGIN_NAME
,
Context
.
MODE_PRIVATE
);
}
/**
* Persist the information of this alarm to the Android Shared Preferences.
* This will allow the application to restore the alarm upon device reboot.
* Also this is used by the cancelAll method.
*
* @param alarmId
* The Id of the notification that must be persisted.
* @param args
* The assumption is that parse has been called already.
*/
public
void
persist
(
String
alarmId
,
JSONObject
args
)
{
Editor
editor
=
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
putString
(
alarmId
,
args
.
toString
());
if
(
Build
.
VERSION
.
SDK_INT
<
9
)
{
editor
.
commit
();
}
else
{
editor
.
apply
();
}
}
}
/**
* Remove a specific alarm from the Android shared Preferences.
*
* @param alarmId
* The Id of the notification that must be removed.
*/
public
void
unpersist
(
String
alarmId
)
{
Editor
editor
=
getSharedPreferences
().
edit
();
if
(
alarmId
!=
null
)
{
editor
.
remove
(
alarmId
);
if
(
Build
.
VERSION
.
SDK_INT
<
9
)
{
editor
.
commit
();
}
else
{
editor
.
apply
();
}
}
}
//---------------private functions-----------------------------------------------------------
/**
* The alarm manager for the application.
*/
private
AlarmManager
getAlarmManager
()
{
return
(
AlarmManager
)
context
.
getSystemService
(
Context
.
ALARM_SERVICE
);
}
/**
* The notification manager for the application.
*/
private
NotificationManager
getNotificationManager
()
{
return
(
NotificationManager
)
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
);
}
/**
* Update the Arguments Input with content from updates-input
*
* @param arguments The notifications optionArray
* @param updates The content you like to change
*
* @return The updated value
*/
private
JSONObject
updateArguments
(
JSONObject
arguments
,
JSONObject
updates
){
try
{
if
(!
updates
.
isNull
(
"message"
)){
arguments
.
put
(
"message"
,
updates
.
get
(
"message"
));
}
if
(!
updates
.
isNull
(
"title"
)){
arguments
.
put
(
"title"
,
updates
.
get
(
"title"
));
}
if
(!
updates
.
isNull
(
"badge"
)){
arguments
.
put
(
"badge"
,
updates
.
get
(
"badge"
));
}
if
(!
updates
.
isNull
(
"sound"
)){
arguments
.
put
(
"sound"
,
updates
.
get
(
"sound"
));
}
if
(!
updates
.
isNull
(
"icon"
)){
arguments
.
put
(
"icon"
,
updates
.
get
(
"icon"
));
}
}
catch
(
JSONException
jse
){
jse
.
printStackTrace
();
}
return
arguments
;
}
/**
* Function to set the value of "initialDate" in the JSONArray
* @param args The given JSONArray
* @return A new JSONArray with the parameter "initialDate" set.
*/
private
JSONObject
setInitDate
(
JSONObject
arguments
){
long
initialDate
=
arguments
.
optLong
(
"date"
,
0
)
*
1000
;
try
{
arguments
.
put
(
"initialDate"
,
initialDate
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
arguments
;
}
}
plugins/de.appplant.cordova.plugin.local-notification/src/android/notification/Options.java
0 → 100644
View file @
e071e96a
/*
Copyright 2013-2014 appPlant UG
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package
de
.
appplant
.
cordova
.
plugin
.
notification
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Calendar
;
import
java.util.Date
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.app.AlarmManager
;
import
android.content.Context
;
import
android.content.res.Resources
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.net.Uri
;
/**
* Class that helps to store the options that can be specified per alarm.
*/
public
class
Options
{
private
JSONObject
options
=
new
JSONObject
();
private
String
packageName
=
null
;
private
long
interval
=
0
;
private
Context
context
;
public
Options
(
Context
context
){
this
.
context
=
context
;
this
.
packageName
=
context
.
getPackageName
();
}
/**
* Parses the given properties
*/
public
Options
parse
(
JSONObject
options
)
{
String
repeat
=
options
.
optString
(
"repeat"
);
this
.
options
=
options
;
if
(
repeat
.
equalsIgnoreCase
(
"secondly"
))
{
interval
=
1000
;
}
if
(
repeat
.
equalsIgnoreCase
(
"minutely"
))
{
interval
=
AlarmManager
.
INTERVAL_FIFTEEN_MINUTES
/
15
;
}
if
(
repeat
.
equalsIgnoreCase
(
"hourly"
))
{
interval
=
AlarmManager
.
INTERVAL_HOUR
;
}
if
(
repeat
.
equalsIgnoreCase
(
"daily"
))
{
interval
=
AlarmManager
.
INTERVAL_DAY
;
}
else
if
(
repeat
.
equalsIgnoreCase
(
"weekly"
))
{
interval
=
AlarmManager
.
INTERVAL_DAY
*
7
;
}
else
if
(
repeat
.
equalsIgnoreCase
(
"monthly"
))
{
interval
=
AlarmManager
.
INTERVAL_DAY
*
31
;
// 31 days
}
else
if
(
repeat
.
equalsIgnoreCase
(
"yearly"
))
{
interval
=
AlarmManager
.
INTERVAL_DAY
*
365
;
}
else
{
try
{
interval
=
Integer
.
parseInt
(
repeat
)
*
60000
;
}
catch
(
Exception
e
)
{};
}
return
this
;
}
/**
* Set new time according to interval
*/
public
Options
moveDate
()
{
try
{
options
.
put
(
"date"
,
(
getDate
()
+
interval
)
/
1000
);
}
catch
(
JSONException
e
)
{}
return
this
;
}
/**
* Returns options as JSON object
*/
public
JSONObject
getJSONObject
()
{
return
options
;
}
/**
* Returns time in milliseconds when notification is scheduled to fire
*/
public
long
getDate
()
{
return
options
.
optLong
(
"date"
,
0
)
*
1000
;
}
/**
* Returns time in milliseconds when the notification was scheduled first
*/
public
long
getInitialDate
()
{
return
options
.
optLong
(
"initialDate"
,
0
);
}
/**
* Returns time as calender
*/
public
Calendar
getCalendar
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
new
Date
(
getDate
()));
return
calendar
;
}
/**
* Returns the notification's message
*/
public
String
getMessage
()
{
return
options
.
optString
(
"message"
,
""
);
}
/**
* Returns the notification's title
*/
public
String
getTitle
()
{
return
options
.
optString
(
"title"
,
""
);
}
/**
* Returns the path of the notification's sound file
*/
public
Uri
getSound
()
{
Uri
soundUri
=
null
;
try
{
soundUri
=
Uri
.
parse
(
options
.
optString
(
"soundUri"
));
return
soundUri
;
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
null
;
}
/**
* Returns the icon's ID
*/
public
Bitmap
getIcon
()
{
String
icon
=
options
.
optString
(
"icon"
,
"icon"
);
Bitmap
bmp
=
null
;
Uri
iconUri
=
null
;
try
{
iconUri
=
Uri
.
parse
(
options
.
optString
(
"iconUri"
));
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
if
(
iconUri
!=
null
)
{
bmp
=
getIconFromUri
(
iconUri
);
}
if
(
bmp
==
null
)
{
bmp
=
getIconFromRes
(
icon
);
}
return
bmp
;
}
/**
* Returns the small icon's ID
*/
public
int
getSmallIcon
()
{
int
resId
=
0
;
String
iconName
=
options
.
optString
(
"smallIcon"
,
""
);
resId
=
getIconValue
(
packageName
,
iconName
);
if
(
resId
==
0
)
{
resId
=
getIconValue
(
"android"
,
iconName
);
}
if
(
resId
==
0
)
{
resId
=
getIconValue
(
packageName
,
"icon"
);
}
return
options
.
optInt
(
"smallIcon"
,
resId
);
}
/**
* Returns notification repetition interval (daily, weekly, monthly, yearly)
*/
public
long
getInterval
()
{
return
interval
;
}
/**
* Returns notification badge number
*/
public
int
getBadge
()
{
return
options
.
optInt
(
"badge"
,
0
);
}
/**
* Returns PluginResults' callback ID
*/
public
String
getId
()
{
return
options
.
optString
(
"id"
,
"0"
);
}
/**
* Returns whether notification is cancelled automatically when clicked.
*/
public
Boolean
getAutoCancel
()
{
return
options
.
optBoolean
(
"autoCancel"
,
false
);
}
/**
* Returns whether the notification is ongoing (uncancellable). Android only.
*/
public
Boolean
getOngoing
()
{
return
options
.
optBoolean
(
"ongoing"
,
false
);
}
/**
* Returns additional data as string
*/
public
String
getJSON
()
{
return
options
.
optString
(
"json"
,
""
);
}
/**
* @return
* The notification color for LED
*/
public
int
getColor
()
{
String
hexColor
=
options
.
optString
(
"led"
,
"000000"
);
int
aRGB
=
Integer
.
parseInt
(
hexColor
,
16
);
aRGB
+=
0xFF000000
;
return
aRGB
;
}
/**
* Shows the behavior of notifications when the application is in foreground
*
*/
public
boolean
getForegroundMode
(){
return
options
.
optBoolean
(
"foregroundMode"
,
false
);
}
/**
* Returns numerical icon Value
*
* @param {String} className
* @param {String} iconName
*/
private
int
getIconValue
(
String
className
,
String
iconName
)
{
int
icon
=
0
;
try
{
Class
<?>
klass
=
Class
.
forName
(
className
+
".R$drawable"
);
icon
=
(
Integer
)
klass
.
getDeclaredField
(
iconName
).
get
(
Integer
.
class
);
}
catch
(
Exception
e
)
{}
return
icon
;
}
/**
* Converts an resource to Bitmap.
*
* @param icon
* The resource name
* @return
* The corresponding bitmap
*/
private
Bitmap
getIconFromRes
(
String
icon
)
{
Resources
res
=
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 URI to Bitmap.
*
* @param src
* The internal image URI
* @return
* The corresponding bitmap
*/
private
Bitmap
getIconFromUri
(
Uri
uri
)
{
Bitmap
bmp
=
null
;
try
{
InputStream
input
=
context
.
getContentResolver
().
openInputStream
(
uri
);
bmp
=
BitmapFactory
.
decodeStream
(
input
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
bmp
;
}
/**
* Function to set the value of "initialDate" in the JSONArray
* @param args The given JSONArray
* @return A new JSONArray with the parameter "initialDate" set.
*/
public
void
setInitDate
(){
long
initialDate
=
options
.
optLong
(
"date"
,
0
)
*
1000
;
try
{
options
.
put
(
"initialDate"
,
initialDate
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
}
www/index.html
View file @
e071e96a
...
...
@@ -91,21 +91,37 @@
<a
href=
"#"
class=
"button"
onclick=
"hasPermission()"
>
Has permission?
<br/><span
class=
"hint"
>
notification.local.hasPermission()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"registerPermission()"
>
Register permission
<br/><span
class=
"hint"
>
notification.local.registerPermission()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"schedule()"
>
Schedule now
<br/><span
class=
"hint"
>
notification.local.add()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"scheduleMultiple()"
>
Schedule multiple
<br/><span
class=
"hint"
>
notification.local.add()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"scheduleDelayed()"
>
Schedule in 5 sec
<br/><span
class=
"hint"
>
notification.local.add([])
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"scheduleMinutely()"
>
Schedule every min
<br/><span
class=
"hint"
>
notification.local.add()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"update()"
>
Update
<br/><span
class=
"hint"
>
notification.local.update()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"cancel()"
>
Cancel
<br/><span
class=
"hint"
>
notification.local.cancel()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"cancelMultiple()"
>
Cancel multiple
<br/><span
class=
"hint"
>
notification.local.cancel([])
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"cancelAll()"
>
Cancel all
<br/><span
class=
"hint"
>
notification.local.cancelAll()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"clear()"
>
Cancel
<br/><span
class=
"hint"
>
notification.local.clear()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"clearMultiple()"
>
Cancel multiple
<br/><span
class=
"hint"
>
notification.local.clear([])
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"clearAll()"
>
Cancel all
<br/><span
class=
"hint"
>
notification.local.clearAll()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getIds()"
>
All IDs
<br/><span
class=
"hint"
>
notification.local.getIds()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getScheduledIds()"
>
Scheduled IDs
<br/><span
class=
"hint"
>
notification.local.getScheduledIds()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isScheduled()"
>
Is scheduled?
<br/><span
class=
"hint"
>
notification.local.isScheduled()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getTriggeredIds()"
>
Triggered IDs
<br/><span
class=
"hint"
>
notification.local.getTriggeredIds()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isTriggered()"
>
Is triggered?
<br/><span
class=
"hint"
>
notification.local.isTriggered()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"exists()"
>
Exists?
<br/><span
class=
"hint"
>
notification.local.exists()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isScheduled()"
>
Scheduled?
<br/><span
class=
"hint"
>
notification.local.isScheduled()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"isTriggered()"
>
Triggered?
<br/><span
class=
"hint"
>
notification.local.isTriggered()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getAll()"
>
All Notifications
<br/><span
class=
"hint"
>
notification.local.get()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getScheduled()"
>
Scheduled Notifications
<br/><span
class=
"hint"
>
notification.local.getScheduled()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"getTriggered()"
>
Triggered Notifications
<br/><span
class=
"hint"
>
notification.local.getTriggered()
</span></a>
<a
href=
"#"
class=
"button"
onclick=
"setDefaultTitle()"
>
Change default title
<br/><span
class=
"hint"
>
notification.local.setDefaults()
</span></a>
</div>
</div>
<script
type=
"text/javascript"
src=
"cordova.js"
></script>
<script
type=
"text/javascript"
src=
"js/index.js"
></script>
...
...
@@ -113,23 +129,23 @@
var
counter
=
0
,
id
=
1
;
var
callback
=
function
()
{
get
Scheduled
Ids
();
getIds
();
};
hasPermission
=
function
()
{
plugin
.
notification
.
local
.
hasPermission
(
function
(
granted
)
{
cordova
.
plugins
.
notification
.
local
.
hasPermission
(
function
(
granted
)
{
alert
(
granted
);
});
};
registerPermission
=
function
()
{
plugin
.
notification
.
local
.
registerPermission
(
function
(
granted
)
{
cordova
.
plugins
.
notification
.
local
.
registerPermission
(
function
(
granted
)
{
alert
(
granted
);
});
};
schedule
=
function
()
{
plugin
.
notification
.
local
.
add
({
cordova
.
plugins
.
notification
.
local
.
add
({
id
:
id
,
message
:
'Test Message '
+
(
++
counter
),
json
:
{
test
:
id
}
...
...
@@ -137,7 +153,7 @@
};
scheduleMultiple
=
function
()
{
plugin
.
notification
.
local
.
add
([{
cordova
.
plugins
.
notification
.
local
.
add
([{
id
:
id
,
message
:
'Multi Message '
+
(
++
counter
)
},{
...
...
@@ -153,7 +169,7 @@
var
now
=
new
Date
().
getTime
(),
_5_sec_from_now
=
new
Date
(
now
+
5
*
1000
);
plugin
.
notification
.
local
.
add
({
cordova
.
plugins
.
notification
.
local
.
add
({
id
:
id
,
title
:
'Scheduled with delay'
,
message
:
'Test Message '
+
(
++
counter
),
...
...
@@ -163,7 +179,7 @@
};
scheduleMinutely
=
function
()
{
plugin
.
notification
.
local
.
add
({
cordova
.
plugins
.
notification
.
local
.
add
({
id
:
id
,
message
:
'Scheduled every minute'
,
repeat
:
'minutely'
,
...
...
@@ -172,7 +188,7 @@
};
update
=
function
()
{
plugin
.
notification
.
local
.
update
({
cordova
.
plugins
.
notification
.
local
.
update
({
id
:
id
,
message
:
'Updated Message '
+
(
counter
),
json
:
{
updated
:
true
}
...
...
@@ -181,66 +197,124 @@
cancel
=
function
()
{
counter
=
0
;
plugin
.
notification
.
local
.
cancel
(
id
,
callback
);
cordova
.
plugins
.
notification
.
local
.
cancel
(
id
,
callback
);
};
cancelMultiple
=
function
()
{
counter
=
0
;
plugin
.
notification
.
local
.
cancel
([
id
,
id
+
1
],
callback
);
cordova
.
plugins
.
notification
.
local
.
cancel
([
id
,
id
+
1
],
callback
);
};
cancelAll
=
function
()
{
counter
=
0
;
plugin
.
notification
.
local
.
cancelAll
(
callback
);
cordova
.
plugins
.
notification
.
local
.
cancelAll
(
callback
);
};
getScheduledIds
=
function
()
{
plugin
.
notification
.
local
.
getScheduledIds
(
function
(
ids
)
{
alert
(
'Scheduled IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
clear
=
function
()
{
counter
=
0
;
cordova
.
plugins
.
notification
.
local
.
clear
(
id
,
callback
);
};
clearMultiple
=
function
()
{
counter
=
0
;
cordova
.
plugins
.
notification
.
local
.
clear
([
id
,
id
+
1
],
callback
);
};
clearAll
=
function
()
{
counter
=
0
;
cordova
.
plugins
.
notification
.
local
.
clearAll
(
callback
);
};
setDefaultTitle
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
setDefaults
({
title
:
'New Default Title'
});
};
</script>
<!-- getters bool -->
<script
type=
"text/javascript"
>
exists
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
exists
(
id
,
function
(
exists
)
{
alert
(
'Notification with ID '
+
id
+
' exists:
\
n'
+
exists
);
});
};
isScheduled
=
function
()
{
plugin
.
notification
.
local
.
isScheduled
(
id
,
function
(
isScheduled
)
{
cordova
.
plugins
.
notification
.
local
.
isScheduled
(
id
,
function
(
isScheduled
)
{
alert
(
'Notification with ID '
+
id
+
' is scheduled:
\
n'
+
isScheduled
);
});
};
isTriggered
=
function
()
{
plugin
.
notification
.
local
.
isTriggered
(
id
,
function
(
isTriggered
)
{
cordova
.
plugins
.
notification
.
local
.
isTriggered
(
id
,
function
(
isTriggered
)
{
alert
(
'Notification with ID '
+
id
+
' is triggered:
\
n'
+
isTriggered
);
});
};
</script>
<!-- getters ID -->
<script
type=
"text/javascript"
>
getIds
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getIds
(
function
(
ids
)
{
alert
(
'IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
});
};
getScheduledIds
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getScheduledIds
(
function
(
ids
)
{
alert
(
'Scheduled IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
});
};
getTriggeredIds
=
function
()
{
plugin
.
notification
.
local
.
getTriggeredIds
(
function
(
ids
)
{
cordova
.
plugins
.
notification
.
local
.
getTriggeredIds
(
function
(
ids
)
{
alert
(
'Triggered IDs:
\
n['
+
ids
.
join
(
' ,'
)
+
']'
);
});
};
</script>
setDefaultTitle
=
function
()
{
plugin
.
notification
.
local
.
setDefaults
({
title
:
'New Default Title'
,
<!-- getters object -->
<script
type=
"text/javascript"
>
getAll
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getAll
(
function
(
data
)
{
alert
(
'Notifications:
\
n['
+
data
.
join
(
' ,'
)
+
']'
);
});
};
</script>
getScheduled
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getScheduled
(
function
(
data
)
{
alert
(
'Scheduled Notifications:
\
n['
+
data
.
join
(
' ,'
)
+
']'
);
});
};
getTriggered
=
function
()
{
cordova
.
plugins
.
notification
.
local
.
getTriggered
(
function
(
data
)
{
alert
(
'Triggered Notifications:
\
n['
+
data
.
join
(
' ,'
)
+
']'
);
});
};
</script>
<!-- callbacks -->
<script
type=
"text/javascript"
>
document
.
addEventListener
(
'deviceready'
,
function
()
{
plugin
.
notification
.
local
.
onadd
=
function
(
id
,
state
,
json
)
{
document
.
addEventListener
(
'sdeviceready'
,
function
()
{
cordova
.
plugins
.
notification
.
local
.
onadd
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on add
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
plugin
.
notification
.
local
.
ontrigger
=
function
(
id
,
state
,
json
)
{
cordova
.
plugins
.
notification
.
local
.
ontrigger
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on trigger
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
plugin
.
notification
.
local
.
onclick
=
function
(
id
,
state
,
json
)
{
cordova
.
plugins
.
notification
.
local
.
onclick
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on click
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
plugin
.
notification
.
local
.
oncancel
=
function
(
id
,
state
,
json
)
{
cordova
.
plugins
.
notification
.
local
.
oncancel
=
function
(
id
,
state
,
json
)
{
console
.
log
(
arguments
);
alert
(
'on cancel
\
n'
+
Array
.
apply
(
null
,
arguments
).
join
(
"
\
n"
));
};
},
false
);
...
...
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