java - My url temperature widget not working -
i'm new javascript , android. pls me (i removed actual user , password) , ip work , code on bluej works no study on android.unable make widget work.
error log:
09-22 17:39:53.947 31620-31620/pi.blackoutwidget e/androidruntime: fatal exception: main process: pi.blackoutwidget, pid: 31620 java.lang.runtimeexception: unable start receiver pi.blackoutwidget.temperature: android.os.networkonmainthreadexception @ android.app.activitythread.handlereceiver(activitythread.java:2661) @ android.app.activitythread.access$1800(activitythread.java:154) @ android.app.activitythread$h.handlemessage(activitythread.java:1398) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5310) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:904) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:699) @ de.robv.android.xposed.xposedbridge.main(xposedbridge.java:102) caused by: android.os.networkonmainthreadexception @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1147) @ libcore.io.blockguardos.connect(blockguardos.java:110) @ libcore.io.iobridge.connecterrno(iobridge.java:137) @ libcore.io.iobridge.connect(iobridge.java:122) @ java.net.plainsocketimpl.connect(plainsocketimpl.java:183) @ java.net.plainsocketimpl.connect(plainsocketimpl.java:456) @ java.net.socket.connect(socket.java:882) @ com.android.okhttp.internal.platform.connectsocket(platform.java:174) @ com.android.okhttp.connection.connect(connection.java:152) @ com.android.okhttp.internal.http.httpengine.connect(httpengine.java:276) @ com.android.okhttp.internal.http.httpengine.sendrequest(httpengine.java:211) @ com.android.okhttp.internal.http.httpurlconnectionimpl.execute(httpurlconnectionimpl.java:382) @ com.android.okhttp.internal.http.httpurlconnectionimpl.getresponse(httpurlconnectionimpl.java:332) @ com.android.okhttp.internal.http.httpurlconnectionimpl.getinputstream(httpurlconnectionimpl.java:199) @ java.net.url.openstream(url.java:470) @ pi.blackoutwidget.temperature.updateappwidget(temperature.java:28) @ pi.blackoutwidget.temperature.onupdate(temperature.java:48) @ android.appwidget.appwidgetprovider.onreceive(appwidgetprovider.java:66) @ android.app.activitythread.handlereceiver(activitythread.java:2654) @ android.app.activitythread.access$1800(activitythread.java:154) @ android.app.activitythread$h.handlemessage(activitythread.java:1398) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5310) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:904) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:699) @ de.robv.android.xposed.xposedbridge.main(xposedbridge.java:102)
static void updateappwidget(context context, appwidgetmanager appwidgetmanager, int appwidgetid) { string temp = null, temps; try { url url = new url("http://192.168.0.50:8001/tmp/temperature.dat"); authenticator.setdefault(new authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication("user", "password".tochararray()); } }); bufferedreader btemp = new bufferedreader(new inputstreamreader(url.openstream())); temp = btemp.readline(); system.out.println(temp+"ciao"); } catch (malformedurlexception e) { } catch (ioexception e) { } temps = "temp: "+temp; string widgettext = temps; remoteviews views = new remoteviews(context.getpackagename(), r.layout.temperature); views.settextviewtext(r.id.tempview, widgettext); // instruct widget manager update widget appwidgetmanager.updateappwidget(appwidgetid, views); } @override public void onupdate(context context, appwidgetmanager appwidgetmanager, int[] appwidgetids) { // there may multiple widgets active, update of them (int appwidgetid : appwidgetids) { updateappwidget(context, appwidgetmanager, appwidgetid); } }
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="pi.blackoutwidget"> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.read_external_storage" /> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme"> <receiver android:name=".temperature"> <intent-filter> <action android:name="android.appwidget.action.appwidget_update" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/temperature_info" /> </receiver> <receiver android:name=".garage"> <intent-filter> <action android:name="android.appwidget.action.appwidget_update" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/garage_info" /> </receiver> </application> </manifest>
Comments
Post a Comment