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
3b97aa4a
Commit
3b97aa4a
authored
Oct 18, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix android.os.FileUriExposedException with Android 7 or newer
parent
69914bc6
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
108 additions
and
15 deletions
+108
-15
plugin.xml
plugin.xml
+18
-0
Builder.java
src/android/notification/Builder.java
+11
-2
Notification.java
src/android/notification/Notification.java
+10
-10
Options.java
src/android/notification/Options.java
+3
-0
AssetProvider.java
src/android/notification/util/AssetProvider.java
+27
-0
AssetUtil.java
src/android/notification/util/AssetUtil.java
+15
-3
localnotification_provider_paths.xml
src/android/xml/localnotification_provider_paths.xml
+24
-0
No files found.
plugin.xml
View file @
3b97aa4a
...
...
@@ -104,6 +104,16 @@
</config-file>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest/application"
>
<provider
android:name=
"de.appplant.cordova.plugin.notification.util.AssetProvider"
android:authorities=
"${applicationId}.provider"
android:exported=
"false"
android:grantUriPermissions=
"true"
>
<meta-data
android:name=
"android.support.FILE_PROVIDER_PATHS"
android:resource=
"@xml/localnotification_provider_paths"
/>
</provider>
<receiver
android:name=
"de.appplant.cordova.plugin.localnotification.TriggerReceiver"
android:exported=
"false"
/>
...
...
@@ -132,6 +142,10 @@
</config-file>
<source-file
src=
"src/android/xml/localnotification_provider_paths.xml"
target-dir=
"res/xml"
/>
<source-file
src=
"src/android/LocalNotification.java"
target-dir=
"src/de/appplant/cordova/plugin/localnotification"
/>
...
...
@@ -192,6 +206,10 @@
target-dir=
"src/de/appplant/cordova/plugin/notification/trigger"
/>
<source-file
src=
"src/android/notification/util/AssetProvider.java"
target-dir=
"src/de/appplant/cordova/plugin/notification/util"
/>
<source-file
src=
"src/android/notification/util/AssetUtil.java"
target-dir=
"src/de/appplant/cordova/plugin/notification/util"
/>
...
...
src/android/notification/Builder.java
View file @
3b97aa4a
...
...
@@ -25,6 +25,8 @@ import android.app.PendingIntent;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationCompat.MessagingStyle.Message
;
...
...
@@ -88,15 +90,22 @@ public final class Builder {
* @return The final notification to display.
*/
public
Notification
build
()
{
int
smallIcon
=
options
.
getSmallIcon
();
NotificationCompat
.
Builder
builder
;
if
(
options
.
isSilent
())
{
return
new
Notification
(
context
,
options
);
}
int
smallIcon
=
options
.
getSmallIcon
();
Uri
sound
=
options
.
getSound
();
Bundle
extras
=
new
Bundle
();
extras
.
putString
(
Options
.
EXTRA
,
options
.
toString
());
extras
.
putString
(
Options
.
SOUND_EXTRA
,
sound
.
toString
());
builder
=
new
NotificationCompat
.
Builder
(
context
,
Manager
.
CHANNEL_ID
)
.
setDefaults
(
options
.
getDefaults
())
.
setExtras
(
extras
)
.
setChannelId
(
options
.
getChannel
())
.
setContentTitle
(
options
.
getTitle
())
.
setContentText
(
options
.
getText
())
...
...
@@ -105,7 +114,7 @@ public final class Builder {
.
setAutoCancel
(
options
.
isAutoClear
())
.
setOngoing
(
options
.
isSticky
())
.
setColor
(
options
.
getColor
())
.
setSound
(
options
.
getSound
()
)
.
setSound
(
sound
)
.
setVisibility
(
options
.
getVisibility
())
.
setPriority
(
options
.
getPriority
())
.
setShowWhen
(
options
.
getShowWhen
())
...
...
src/android/notification/Notification.java
View file @
3b97aa4a
...
...
@@ -29,6 +29,7 @@ import android.app.PendingIntent;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.support.v4.app.NotificationCompat
;
...
...
@@ -189,17 +190,16 @@ public final class Notification {
* Present the local notification to user.
*/
public
void
show
()
{
// TODO Show dialog when in foreground
showNotification
();
}
if
(
builder
==
null
)
return
;
/**
* Show as local notification when in background.
*/
private
void
showNotification
()
{
if
(
builder
!=
null
)
{
getNotMgr
().
notify
(
getId
(),
builder
.
build
());
}
String
sound
=
builder
.
getExtras
().
getString
(
Options
.
SOUND_EXTRA
);
Uri
soundUri
=
Uri
.
parse
(
sound
);
context
.
grantUriPermission
(
"com.android.systemui"
,
soundUri
,
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
getNotMgr
().
notify
(
getId
(),
builder
.
build
());
}
// /**
...
...
src/android/notification/Options.java
View file @
3b97aa4a
...
...
@@ -56,6 +56,9 @@ public final class Options {
// Key name for bundled extras
public
static
final
String
EXTRA
=
"NOTIFICATION_OPTIONS"
;
// Key name for bundled sound extra
public
static
final
String
SOUND_EXTRA
=
"NOTIFICATION_SOUND"
;
// Default icon path
private
static
final
String
DEFAULT_ICON
=
"res://icon"
;
...
...
src/android/notification/util/AssetProvider.java
0 → 100644
View file @
3b97aa4a
/*
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
.
util
;
import
android.support.v4.content.FileProvider
;
public
class
AssetProvider
extends
FileProvider
{
// Nothing to do here
}
\ No newline at end of file
src/android/notification/util/AssetUtil.java
View file @
3b97aa4a
...
...
@@ -112,7 +112,7 @@ public final class AssetUtil {
return
Uri
.
EMPTY
;
}
return
Uri
.
f
romFile
(
file
);
return
getUriF
romFile
(
file
);
}
/**
...
...
@@ -142,7 +142,7 @@ public final class AssetUtil {
outStream
.
flush
();
outStream
.
close
();
return
Uri
.
f
romFile
(
file
);
return
getUriF
romFile
(
file
);
}
catch
(
Exception
e
)
{
Log
.
e
(
"Asset"
,
"File not found: assets/"
+
resPath
);
...
...
@@ -213,7 +213,7 @@ public final class AssetUtil {
outStream
.
flush
();
outStream
.
close
();
return
Uri
.
f
romFile
(
file
);
return
getUriF
romFile
(
file
);
}
catch
(
MalformedURLException
e
)
{
Log
.
e
(
"Asset"
,
"Incorrect URL"
);
...
...
@@ -347,6 +347,18 @@ public final class AssetUtil {
}
/**
* Get content URI for the specified file.
*
* @param file The file to get the URI.
*
* @return content://...
*/
private
Uri
getUriFromFile
(
File
file
)
{
String
authority
=
context
.
getPackageName
()
+
".provider"
;
return
AssetProvider
.
getUriForFile
(
context
,
authority
,
file
);
}
/**
* Package name specified by the resource bundle.
*/
private
String
getPkgName
(
Resources
res
)
{
...
...
src/android/xml/localnotification_provider_paths.xml
0 → 100644
View file @
3b97aa4a
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<paths
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<external-path
name=
"external_files"
path=
"."
/>
</paths>
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