Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Krishna Vemulavada
/
vera_2.1_app
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
254ec802
authored
Nov 22, 2016
by
Kunj Gupta
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add Network change listener for start sync service.
parent
37ce0acf
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
0 deletions
app/src/main/AndroidManifest.xml
app/src/main/java/com/vsoft/uoflservicenow/receiver/NetworkChangeReceiver.java
app/src/main/java/com/vsoft/uoflservicenow/utils/NetworkUtil.java
app/src/main/AndroidManifest.xml
View file @
254ec802
...
...
@@ -85,6 +85,15 @@
<service
android:name=
".service.SyncService"
/>
<receiver
android:name=
".receiver.NetworkChangeReceiver"
android:label=
"NetworkChangeReceiver"
>
<intent-filter>
<action
android:name=
"android.net.conn.CONNECTIVITY_CHANGE"
/>
<action
android:name=
"android.net.wifi.WIFI_STATE_CHANGED"
/>
</intent-filter>
</receiver>
<meta-data
android:name=
"io.fabric.ApiKey"
android:value=
"2b0a6e9db28d607fbcf71b8b25f1a0795e3f5b22"
/>
...
...
app/src/main/java/com/vsoft/uoflservicenow/receiver/NetworkChangeReceiver.java
0 → 100644
View file @
254ec802
package
com
.
vsoft
.
uoflservicenow
.
receiver
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Handler
;
import
android.support.v4.content.LocalBroadcastManager
;
import
com.vsoft.uoflservicenow.utils.CatalogueLog
;
import
com.vsoft.uoflservicenow.utils.Constants
;
import
com.vsoft.uoflservicenow.utils.NetworkUtil
;
/**
*@author Kunj
* 22-11-2016 11:30
* */
public
class
NetworkChangeReceiver
extends
BroadcastReceiver
{
@Override
public
void
onReceive
(
final
Context
context
,
Intent
intent
)
{
CatalogueLog
.
d
(
"NetworkChangeReceiver : Received notification about network status"
);
Handler
handler
=
new
Handler
();
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
int
status
=
NetworkUtil
.
getConnectivityStatus
(
context
);
if
(
status
!=
NetworkUtil
.
TYPE_NOT_CONNECTED
)
{
Intent
intent
=
new
Intent
(
Constants
.
APPLICATION_BROADCAST_INTENT
);
intent
.
putExtra
(
Constants
.
APPLICATION_BROADCAST_DATA_ACTION
,
Constants
.
ACTION_SYNC
);
LocalBroadcastManager
.
getInstance
(
context
).
sendBroadcast
(
intent
);
}
}
},
10000
);
}
}
\ No newline at end of file
app/src/main/java/com/vsoft/uoflservicenow/utils/NetworkUtil.java
0 → 100644
View file @
254ec802
package
com
.
vsoft
.
uoflservicenow
.
utils
;
import
android.content.Context
;
import
android.net.ConnectivityManager
;
import
android.net.NetworkInfo
;
/**
* Created by chaukadev on 22/11/16.
*/
public
class
NetworkUtil
{
public
static
int
TYPE_WIFI
=
1
;
public
static
int
TYPE_MOBILE
=
2
;
public
static
int
TYPE_NOT_CONNECTED
=
0
;
public
static
int
getConnectivityStatus
(
Context
context
)
{
ConnectivityManager
cm
=
(
ConnectivityManager
)
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
NetworkInfo
activeNetwork
=
cm
.
getActiveNetworkInfo
();
if
(
null
!=
activeNetwork
)
{
if
(
activeNetwork
.
getType
()
==
ConnectivityManager
.
TYPE_WIFI
)
return
TYPE_WIFI
;
if
(
activeNetwork
.
getType
()
==
ConnectivityManager
.
TYPE_MOBILE
)
return
TYPE_MOBILE
;
}
return
TYPE_NOT_CONNECTED
;
}
public
static
String
getConnectivityStatusString
(
Context
context
)
{
int
conn
=
NetworkUtil
.
getConnectivityStatus
(
context
);
String
status
=
null
;
if
(
conn
==
NetworkUtil
.
TYPE_WIFI
)
{
status
=
"Wifi enabled"
;
}
else
if
(
conn
==
NetworkUtil
.
TYPE_MOBILE
)
{
status
=
"Mobile data enabled"
;
}
else
if
(
conn
==
NetworkUtil
.
TYPE_NOT_CONNECTED
)
{
status
=
"Not connected to Internet"
;
}
return
status
;
}
}
\ No newline at end of file
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