I have an app that works fine with Android 6, but freezes on Android 7. All I have is added ConnectSDK by LG (http://www.svlconnectsdk.com/docs/1-6-0/android/). The app freezes as soon as I call start on DiscoveryManager's object. And I get the following stacktrace:
10-26 13:32:51.678: W/System(7569): ClassLoader referenced unknown path: /data/app/com.testconnectsdk.test-1/lib/arm64
10-26 13:32:51.774: W/System.err(7569): java.net.SocketException: Socket closed
10-26 13:32:51.774: W/System.err(7569): at java.net.PlainDatagramSocketImpl.receive0(Native Method)
10-26 13:32:51.774: W/System.err(7569): at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:147)
10-26 13:32:51.774: W/System.err(7569): at java.net.DatagramSocket.receive(DatagramSocket.java:808)
10-26 13:32:51.774: W/System.err(7569): at com.connectsdk.discovery.provider.ssdp.SSDPClient.multicastReceive(SSDPClient.java:109)
10-26 13:32:51.774: W/System.err(7569): at com.connectsdk.discovery.provider.SSDPDiscoveryProvider$2.run(SSDPDiscoveryProvider.java:271)
10-26 13:32:51.774: W/System.err(7569): at java.lang.Thread.run(Thread.java:761)
The code is very simple :
public class MainActivity extends Activity implements DiscoveryManagerListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DiscoveryManager.init(getApplicationContext(), null);
final DiscoveryManager dm = DiscoveryManager.getInstance();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
dm.addListener(MainActivity.this);
}
}, 2000);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
dm.start();
}
}, 4000);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(MainActivity.this, OtherActivity.class);
startActivity(i);
}
}, 6000);
}
private static final String TAG = MainActivity.class.getName();
#Override
public void onDeviceAdded(DiscoveryManager manager, ConnectableDevice device) {
// TODO Auto-generated method stub
Log.d(TAG, "onDeviceAdded");
}
#Override
public void onDeviceUpdated(DiscoveryManager manager, ConnectableDevice device) {
// TODO Auto-generated method stub
Log.d(TAG, "onDeviceUpdated");
}
#Override
public void onDeviceRemoved(DiscoveryManager manager, ConnectableDevice device) {
// TODO Auto-generated method stub
Log.d(TAG, "onDeviceRemoved");
}
#Override
public void onDiscoveryFailed(DiscoveryManager manager, ServiceCommandError error) {
// TODO Auto-generated method stub
Log.d(TAG, "onDiscoveryFailed");
}
}
Any idea why is it crashing? Pasting my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testconnectsdk.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="OtherActivity"></activity>
</application>
</manifest>
Kindly please help. Badly need it. Thanks
Related
I am working on an application for collecting crash reports in application, so that I have created class which extends Application for handling uncaught exception and created service class for communicate with server.
I made a simple divide by zero exception in a button click and it produce exception but my service class does not called. I am sure have registered the service class in manifest file.
my question is Will Service concept work even if application is crashed (force close) in Android?
code:
public class MyApp extends Application {
public void onCreate() {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
#Override
public void uncaughtException(Thread thread, Throwable e) {
handleUncaughtException(thread, e);
}
});
}
public void handleUncaughtException(Thread thread, Throwable e) {
e.printStackTrace();
Intent i = new Intent(MyApp.this, ServiceClass.class);
startService(i);
}
}
Service class:
public class ServiceClass extends Service {
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onDestroy() {
super.onDestroy();
}
#Override
public void onLowMemory() {
super.onLowMemory();
}
#Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e("onStartCommand", "onStartCommand called");
// server communication code.
return Service.START_STICKY;
}
}
Manifest xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ex.errorhandle"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="com.ex.errorhandle.MyApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.ex.errorhandle.ServiceClass" />
</application>
</manifest>
When i tried to create a websocket connection in android for implementing wamp using Autobahn, the connection is created and closed immediatley.
why this happening ....?
How to solve..........?
Part of my code is given below
private void start() {
// TODO Auto-generated method stub
final String wsuri = "ws://192.168.0.102:8080/ws";
if (!connection.isConnected()) {
Log.d("tag", "Not Connected");
}
connection.connect(wsuri, new ConnectionHandler() {
#Override
public void onOpen() {
// TODO Auto-generated method stub
Log.d("tag", "Connected to " + wsuri);
testPubSub();
}
#Override
public void onClose(int code, String reason) {
// TODO Auto-generated method stub
Log.d("tag", "disconnected");
}
});
}
protected void testPubSub() {
// TODO Auto-generated method stub
connection.subscribe(TOPIC, String.class, new EventHandler() {
#Override
public void onEvent(String topicUri, Object event) {
// TODO Auto-generated method stub
Log.d("tag", "Event Recieved");
}
});
}
Sorry for not posting the manifest file earlier. Its given below..
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.testwamp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Most probably you didn't put INTERNET permission to the manifest.xml
<uses-permission android:name="android.permission.INTERNET" />
im trying to make basic beacon application in android studio. I just want to scan beacons and list them into the screen. Here are my codes. I took them from somewhere.
public class MainActivity extends ActionBarActivity {
private static final String ESTIMOTE_PROXIMITY_UUID = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";
private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId", null, null, null);
private BeaconManager beaconManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
#Override public void onBeaconsDiscovered(Region region, List<Beacon> beacons) {
Log.d("TAG", "Ranged beacons: " + beacons);
}
});
}
#Override
protected void onStart() {
super.onStart();
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
#Override public void onServiceReady() {
try {
beaconManager.startRanging(ALL_ESTIMOTE_BEACONS);
} catch (RemoteException e) {
Log.e("TAG","Cannot start ranging", e);
}
}
});
}
#Override
protected void onStop() {
super.onStop();
try {
beaconManager.stopRanging(ALL_ESTIMOTE_BEACONS);
} catch (RemoteException e) {
Log.e("TAG", "Cannot stop but it does not matter now", e);
}
}
#Override
protected void onDestroy() {
super.onDestroy();
beaconManager.disconnect();
}
}
Here is my manifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.oem.estimote_ibeacon_app" >
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="com.estimote.sdk.service.BeaconService"
android:exported="false"/>
</application>
</manifest>
When i opened application it says "stopped" please help. I have beacons for test. Where is my mistake? Thank you.
it seems that ALL_ESTIMOTE_BEACONS in
beaconManager.startRanging(ALL_ESTIMOTE_BEACONS);
is null.
enter a valid regionid instead of "regionid" in
private static final Region ALL_ESTIMOTE_BEACONS = new Region("regionId", null, null, null);
hy..i have a task to make my kitkat-nexus to act as a tag. I have ACS 122U as reader. i have read the program example in this site http://blog.opendatalab.de/hack/2013/11/07/android-host-card-emulation-with-acr122/. then i tryed the code on my own eclipse.
main activity :
public class MainActivity extends Activity implements OnMessageReceived, ReaderCallback {
private NfcAdapter nfcAdapter;
private ListView listView;
private IsoDepAdapter isoDepAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView)findViewById(R.id.listView);
isoDepAdapter = new IsoDepAdapter(getLayoutInflater());
listView.setAdapter(isoDepAdapter);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
Log.i("end of onCreate-----","onCreate HCE");
}
#Override
public void onResume() {
super.onResume();
//nfcAdapter.enableReaderMode(this, this, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
// null);
//nfcAdapter.disableReaderMode(this); //tambahan poipo
Log.i("onResume---", "onResume");
}
#Override
public void onPause() {
super.onPause();
nfcAdapter.disableReaderMode(this);
Log.i("onPause---", "onPause");
}
#Override
public void onTagDiscovered(Tag tag) {
IsoDep isoDep = IsoDep.get(tag);
IsoDepTransceiver transceiver = new IsoDepTransceiver(isoDep, this);
Thread thread = new Thread(transceiver);
Log.i("dibawah thread", "ontagdiscovered");
thread.start();
}
#Override
public void onMessage(final byte[] message) {
runOnUiThread(new Runnable() {
#Override
public void run() {
isoDepAdapter.addMessage(new String(message));
Log.i("didlmrun---", "onMessage");
}
});
Log.i("diluarrun---", "onMessage");
}
#Override
public void onError(Exception exception) {
onMessage(exception.getMessage().getBytes());
}
}
hostapduservice :
...
...
...
#Override
public byte[] processCommandApdu(byte[] apdu, Bundle extras) {
if (selectAidApdu(apdu)) {
Log.i("HCEDEMO====", "Application selected====");
return getWelcomeMessage();
}
else {
Log.i("HCEDEMO======", "Received: =====" + new String(apdu));
return getNextMessage();
}
}
...
...
...
then in the manifest file :
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="FEATURE_NFC_HOST_CARD_EMULATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<service
android:name=".MyHostApduService"
android:exported="true"
android:permission="android.permission.BIND_NFC_SERVICE" >
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
</intent-filter>
<meta-data
android:name="android.nfc.cardemulation.host_apdu_service"
android:resource="#xml/apduservice" />
</service>
<activity
android:name="de.grundid.hcedemo.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
ok,,when i ran the above source code,, i saw my acs122u blinking continously when i tapped my nexus near to it. but i didn't see the log.i(....) from hostapdu service. In the eclipse log cat, there were just some log.i from main activity. what should i do to bind that hostapdu service to main activity, so my nexus can act as a tag...???
thanks in advance... :-)
I'm trying to use this very simple Service and BroadcastReceiver but I'm getting a
ClassNotFound exception. If I don't use startService things are fine so the problem it's with the receiver. I have registered it in the android manifest file so why do I get the ClassNotFound exception?
I will be using this method of communication for polling a php file and updating a ListView. Is this the appropriate way of communicating (broadcast intent)?
public class MessengerServiceActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startService(new Intent(this,MessengerService.class));
}
class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Bundle b=intent.getExtras();
if(b==null)
return;
String msg=b.getString("message");
TextView tv=(TextView) findViewById(R.id.textView1);
tv.setText(msg);
}
}
}
public class MessengerService extends Service {
HttpClient hc;
HttpPost hp;
String s[]={"pratik","harsha","dayal","hritika"};
public MessengerService() {
// TODO Auto-generated constructor stub
}
#Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
hc=new DefaultHttpClient();
}
#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Thread t=new Thread(new Runnable(){
public void run()
{
int k=0;
while(true)
{
Intent i=new Intent("com.pdd.messenger.MyAction");
i.putExtra("message",s[k]);
sendBroadcast(i);
try
{
Thread.sleep(3000);
}
catch (InterruptedException e)
{
Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_LONG)
.show();
}
k=(k+1)%4;
}
}
});
t.start();
return super.onStartCommand(intent, flags, startId);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pdd.messenger"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MessengerServiceActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MyReceiver" android:enabled="true">
<intent-filter>
<action android:name="com.pdd.messenger.MyAction"/>
</intent-filter>
</receiver>
<service android:name=".MessengerService"></service>
</application>
</manifest>