mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-11 01:46:24 +00:00
Crashfix when data is not available
This commit is contained in:
parent
1a0e887179
commit
58b9ed61ff
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="fr.unix_experience.owncloud_sms"
|
||||
android:versionCode="22"
|
||||
android:versionName="0.17.3">
|
||||
android:versionCode="24"
|
||||
android:versionName="0.18.1">
|
||||
|
||||
<!-- From Android 4.0 to 5.1 -->
|
||||
<uses-sdk
|
||||
|
@ -33,6 +33,7 @@ import org.json.JSONArray;
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@ -43,6 +44,7 @@ import android.support.v4.view.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
import fr.unix_experience.owncloud_sms.R;
|
||||
import fr.unix_experience.owncloud_sms.engine.ASyncTask.SyncTask;
|
||||
import fr.unix_experience.owncloud_sms.engine.ConnectivityMonitor;
|
||||
@ -160,19 +162,23 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
|
||||
public void syncAllMessages(final View view) {
|
||||
final ConnectivityMonitor cMon = new ConnectivityMonitor(getApplicationContext());
|
||||
final Context ctx = getApplicationContext();
|
||||
final ConnectivityMonitor cMon = new ConnectivityMonitor(ctx);
|
||||
|
||||
if (cMon.isValid()) {
|
||||
// Now fetch messages since last stored date
|
||||
final JSONArray smsList = new SmsFetcher(getApplicationContext())
|
||||
final JSONArray smsList = new SmsFetcher(ctx)
|
||||
.bufferizeMessagesSinceDate((long) 0);
|
||||
|
||||
if (smsList != null) {
|
||||
final OCSMSNotificationManager nMgr = new OCSMSNotificationManager(getApplicationContext());
|
||||
final OCSMSNotificationManager nMgr = new OCSMSNotificationManager(ctx);
|
||||
nMgr.setSyncProcessMsg();
|
||||
new SyncTask(getApplicationContext(), smsList).execute();
|
||||
}
|
||||
}
|
||||
else {
|
||||
Toast.makeText(ctx, ctx.getString(R.string.err_sync_no_connection_available), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void openGooglePlayStore(final View view) {
|
||||
|
@ -12,36 +12,39 @@ package fr.unix_experience.owncloud_sms.engine;
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
*/
|
||||
|
||||
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.telephony.TelephonyManager;
|
||||
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
|
||||
|
||||
public class ConnectivityMonitor {
|
||||
public ConnectivityMonitor(Context context) {
|
||||
public ConnectivityMonitor(final Context context) {
|
||||
_context = context;
|
||||
}
|
||||
|
||||
|
||||
// Valid connection = WiFi or Mobile data
|
||||
public boolean isValid() {
|
||||
if (_cMgr == null) {
|
||||
_cMgr = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final android.net.NetworkInfo niWiFi = _cMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
final android.net.NetworkInfo niMobile = _cMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||
|
||||
|
||||
if (niWiFi.isAvailable() || niMobile.isAvailable()) {
|
||||
// Load the connectivity manager to determine on which network we are connected
|
||||
NetworkInfo netInfo = _cMgr.getActiveNetworkInfo();
|
||||
|
||||
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context);
|
||||
|
||||
final NetworkInfo netInfo = _cMgr.getActiveNetworkInfo();
|
||||
if (netInfo == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context);
|
||||
|
||||
// Check
|
||||
switch (netInfo.getType()) {
|
||||
case ConnectivityManager.TYPE_WIFI:
|
||||
@ -58,7 +61,7 @@ public class ConnectivityMonitor {
|
||||
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
||||
case TelephonyManager.NETWORK_TYPE_UMTS:
|
||||
case TelephonyManager.NETWORK_TYPE_UMTS:
|
||||
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
||||
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
||||
@ -71,13 +74,11 @@ public class ConnectivityMonitor {
|
||||
default:
|
||||
return prefs.syncInOtherModes();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private ConnectivityManager _cMgr;
|
||||
private Context _context;
|
||||
private final Context _context;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user