Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid app. works in emulator but not working in android device
    text
    copied!<p>I have written a simple application to fetch the network details where i have used an AlarmManager to continuously run a piece of code in the background(IntentServiceImpl class)..</p> <p>I am invoking the AlarmManager class from the BroadcastReceiver, and i have registered the BroadcastReceiver(BroadcastReceiverImpl class) for BOOT_COMPLETE event... it is working properly in the android emulator but it is not working in Android Device(i have checked it in Samsung Galaxy s2 and Samsung Galaxy Tab) Here is the source code.. </p> <p>BroadcastReceiverImpl.java</p> <pre><code>public class BroadcastReceiverImpl extends BroadcastReceiver { private static final String LOG_TAG = BroadcastReceiverImpl.class.getSimpleName(); @Override public void onReceive(Context context, Intent intent) { Log.d(LOG_TAG, "Inside the BroadcastReceiver Class"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.SECOND,QOSConstants.TIME_DELAY_IN_SECONDS); Intent serviceIntent = new Intent(context, IntentServiceImpl.class); serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getService(context, QOSConstants.REQUEST_CODE,serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); //After after 60 seconds alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), QOSConstants.MILLISECONDS * QOSConstants.TIME_DELAY_IN_SECONDS, pendingIntent); Log.d(LOG_TAG, "Exiting the QOSBroadcastReceiver Class"); } } </code></pre> <p>IntentServiceImpl.java</p> <pre><code>public class IntentServiceImpl extends IntentService implements LocationListener { private String strNetworkInfo; private LocationManager locationManager; private QOSDatabaseHelper qosDatabaseHelper; private NetworkDetailsVO networkDetailsVO ; private static final String LOG_TAG = QOSIntentService.class.getName(); private QOSServlet qosServlet; private QOSPhoneStateListner qosPhoneStateListner; public QOSIntentService() { super(LOG_TAG); Log.d(LOG_TAG , ": Inside NetworkInfoService() constructor"); } @Override public void onCreate() { super.onCreate(); qosServlet = new QOSServlet(); networkDetailsVO = new NetworkDetailsVO(); qosPhoneStateListner = new QOSPhoneStateListner(); qosDatabaseHelper = new QOSDatabaseHelper(getApplicationContext()); } @Override protected void onHandleIntent(Intent intent) { Log.i("LOG_TAG: ", "Inside onHandleIntent(Intent) method Fetching Network Details "); ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if(networkInfo!=null &amp;&amp; networkInfo.isConnected()){ String networkState = getNetworkStateString(networkInfo.getState()); String stateString = networkInfo.toString().replace(',', '\n'); strNetworkInfo = String.format(QOSConstants.NETWORK_STATE_DISPLAY_FORMAT, networkInfo.getTypeName(),networkState,stateString); networkDetailsVO.setNetworkState(networkState); networkDetailsVO.setNetworkType(networkInfo.getTypeName()); networkDetailsVO.setRoaming(String.valueOf(networkInfo.isRoaming())); networkDetailsVO.setReason(networkInfo.getReason()); networkDetailsVO.setFailOver(String.valueOf(networkInfo.isFailover())); networkDetailsVO.setNetworkAvailable(String.valueOf(networkInfo.isAvailable())); networkDetailsVO.setNetworkConnectivity(String.valueOf(networkInfo.isConnected())); if(networkInfo.getExtraInfo()!=null) networkDetailsVO.setExtraNetworkInfo(networkInfo.getExtraInfo()); else networkDetailsVO.setExtraNetworkInfo(QOSConstants.NETWORK_EXTRA_INFO_NOT_AVAILABLE); } locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, QOSConstants.MINIMUM_TIME, QOSConstants.MINIMUM_DISTANCE, this); Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(new Criteria(), false)); if(location!=null){ onLocationChanged(location); QOSGeocoder qosGeocoder = new QOSGeocoder(); networkDetailsVO.setLocationAddress(qosGeocoder.getLocationAddress(getApplicationContext(), location)); }else{ networkDetailsVO.setLatitude(0.0); networkDetailsVO.setLongitude(0.0); } // Identify the connectivity type. WI-FI/MOBILE. if(networkInfo.getType() == ConnectivityManager.TYPE_WIFI){ WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); networkDetailsVO.setSignalStrength(wifiManager.getConnectionInfo().getLinkSpeed()); }else if(networkInfo.getType() == ConnectivityManager.TYPE_MOBILE){ telephonyManager.listen(qosPhoneStateListner, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); networkDetailsVO.setSignalStrength(qosPhoneStateListner.getStrSignalStrength()); } networkDetailsVO.setNetworkInfo(strNetworkInfo); networkDetailsVO.setSimSerialNumber(telephonyManager.getSimSerialNumber()); networkDetailsVO.setOperatorName(telephonyManager.getNetworkOperatorName()); networkDetailsVO.setDateTime(new Date().toString()); Log.i(LOG_TAG , "Network Details :- " + "\t" + networkInfo.toString()); //qosDatabaseHelper = new QOSDatabaseHelper(getApplicationContext()); qosDatabaseHelper.saveRecord(networkDetailsVO); qosServlet.invokeServlet(networkDetailsVO); Log.i(LOG_TAG , " Network details are saved to the Database,exiting onHandleIntent(Intent) method "); } @Override public void onLocationChanged(Location location) { Log.i(LOG_TAG, " : Inside onLocationChanged(Location) method "); networkDetailsVO.setLatitude(location.getLatitude()); networkDetailsVO.setLongitude(location.getLongitude()); Log.i(LOG_TAG, " : Exiting onLocationChanged(Location) method "); } @Override public void onProviderEnabled(String provider) { Log.i(LOG_TAG, ": Provider is Enabled !! "); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, QOSConstants.MINIMUM_TIME, QOSConstants.SECOND_MINIMUM_DISTANCE, this); } @Override public void onProviderDisabled(String string) { Log.i(LOG_TAG, ": Provider is Disabled !! "); } @Override public void onStatusChanged(String strStatus, int arg1, Bundle bundle) { Log.i(LOG_TAG, " : Inside onStatusChanged(String,int,Bundle) method "); } private String getNetworkStateString(NetworkInfo.State state){ Log.i(LOG_TAG, ": Inside getNetworkStateString(NetworkInfo.State)"); String stateString = QOSConstants.NETWORK_STATE_UNKNOWN; switch(state) { case CONNECTED: stateString = QOSConstants.NETWORK_STATE_CONNECTED; break; case CONNECTING: stateString = QOSConstants.NETWORK_STATE_CONNECTING; break; case DISCONNECTED: stateString = QOSConstants.NETWORK_STATE_DISCONNECTED; break; case DISCONNECTING: stateString = QOSConstants.NETWORK_STATE_DISCONNECTING; break; case SUSPENDED: stateString = QOSConstants.NETWORK_STATE_SUSPENDED; break; default: stateString = QOSConstants.NETWORK_STATE_UNKNOWN; break; } return stateString; } @Override public void onDestroy() { super.onDestroy(); if(qosDatabaseHelper!=null){ qosDatabaseHelper.closeDatabase(); } } } @Override public void onProviderDisabled(String string) { Log.i(LOG_TAG, ": Provider is Disabled !! "); } /*@Override public IBinder onBind(Intent intent) { Log.i("LOG_TAG: ", "Inside onBind(Intent) method"); return null; } */ @Override public void onStatusChanged(String strStatus, int arg1, Bundle bundle) { Log.i(LOG_TAG, " : Inside onStatusChanged(String,int,Bundle) method "); } private class SignalStrengthDetector extends PhoneStateListener{ @Override public void onSignalStrengthsChanged(SignalStrength signalStrength) { super.onSignalStrengthsChanged(signalStrength); networkDetailsVO.setSignalStrength(signalStrength.getGsmSignalStrength()); Log.i(LOG_TAG, "Signal Strength :-" + String.valueOf(signalStrength.getGsmSignalStrength())); } } private String getNetworkStateString(NetworkInfo.State state){ Log.i(LOG_TAG, ": Inside getNetworkStateString(NetworkInfo.State)"); String stateString = NetworkInfoConstants.NETWORK_STATE_UNKNOWN; switch(state) { case CONNECTED: stateString = NetworkInfoConstants.NETWORK_STATE_CONNECTED; break; case CONNECTING: stateString = NetworkInfoConstants.NETWORK_STATE_CONNECTING; break; case DISCONNECTED: stateString = NetworkInfoConstants.NETWORK_STATE_DISCONNECTED; break; case DISCONNECTING: stateString = NetworkInfoConstants.NETWORK_STATE_DISCONNECTING; break; case SUSPENDED: stateString = NetworkInfoConstants.NETWORK_STATE_SUSPENDED; break; default: stateString = NetworkInfoConstants.NETWORK_STATE_UNKNOWN; break; } return stateString; } </code></pre> <p>AndroidManifest.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.pervazive.qualityofservice_v01" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.pervazive.qualityofservice_v01.activity.QOSActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name" android:theme="@style/FullscreenTheme" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;service android:name="com.pervazive.qualityofservice_v01.intentservice.&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.pervazive.qualityofservice_v01" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.pervazive.qualityofservice_v01.activity.QOSActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name" android:theme="@style/FullscreenTheme" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;service android:name="com.pervazive.qualityofservice_v01.intentservice.IntentServiceImpl" android:enabled="true" &gt; &lt;/service&gt; &lt;receiver android:name="com.pervazive.qualityofservice_v01.broadcastreceiver.BroadcastReceiverImpl" &gt; &lt;intent-filter &gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>Please let know what is the error...please let me know where can i find the log file in Android device... (because it is running on the Android Emulator but not running i=on the Android device...) Thanks in Advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload