How to start InputMethodService using Broadcastreceiver or Intent in android? - android

We have an 'InputMethodService' as a stand alone application now what we want to start this InputMethodService for a particular activity in another application.
We tried using broadcast receiver but it is giving following error:
Intent myService = new Intent(context, Cs_key.class);
context.startService(myService);
LOGCATE:
-
29 11:06:51.624: ERROR/AndroidRuntime(24087): FATAL EXCEPTION: main
09-29> 09 11:06:51.624: ERROR/AndroidRuntime(24087): java.lang.RuntimeException: Unable to start receiver com.ashwin.demo.keyboard.KeyboardReceiver: java.lang.SecurityException: Not allowed to start service Intent { cmp=com.ashwin.demo.keyboard/.Cs_key } without permission android.permission.BIND_INPUT_METHOD
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at android.app.ActivityThread.access$3200(ActivityThread.java:125)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at android.os.Looper.loop(Looper.java:123)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at java.lang.reflect.Method.invokeNative(Native Method)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at java.lang.reflect.Method.invoke(Method.java:521)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at dalvik.system.NativeStart.main(Native Method)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): Caused by: java.lang.SecurityException: Not allowed to start service Intent { cmp=com.ashwin.demo.keyboard/.Cs_key } without permission android.permission.BIND_INPUT_METHOD
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at android.app.ContextImpl.startService(ContextImpl.java:832)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at android.content.ContextWrapper.startService(ContextWrapper.java:336)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at android.content.ContextWrapper.startService(ContextWrapper.java:336)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at com.ashwin.demo.keyboard.KeyboardReceiver.onReceive(KeyboardReceiver.java:18)
09-29 11:06:51.624: ERROR/AndroidRuntime(24087): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
menifestfile
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="com.ashwin.demo.keyboard">
<uses-permission android:name="android.permission.BIND_INPUT_METHOD"/>
<application android:label="#string/app_name" >
<service android:name="Cs_key" android:exported="true"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>
<action android:name="android.view.InputMethod" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<meta-data android:name="android.view.im" android:resource="#xml/method" />
</service>
<receiver android:name=".KeyboardReceiver"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>
<action android:name="android.intent.action.TIME_SET"></action>
</intent-filter>
</receiver>
</application>
</manifest>

Related

GPStracker code crash concept

Good evening and good week. We run this script from tutorial but my crash concept does not make an error in the code. nor to the errors refer to a particular line code. Please for your help.
Tutorial: http://gabesechansoftware.com/location-tracking/
01-26 15:36:06.751: I/Process(10528): Sending signal. PID: 10528 SIG: 9
01-26 15:36:18.251: D/AndroidRuntime(10613): Shutting down VM
01-26 15:36:18.251: W/dalvikvm(10613): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
01-26 15:36:18.251: E/AndroidRuntime(10613): FATAL EXCEPTION: main
01-26 15:36:18.251: E/AndroidRuntime(10613): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pack/pack.MainActivity}: java.lang.ClassNotFoundException: pack.MainActivity
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.os.Handler.dispatchMessage(Handler.java:99)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.os.Looper.loop(Looper.java:137)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread.main(ActivityThread.java:4441)
01-26 15:36:18.251: E/AndroidRuntime(10613): at java.lang.reflect.Method.invokeNative(Native Method)
01-26 15:36:18.251: E/AndroidRuntime(10613): at java.lang.reflect.Method.invoke(Method.java:511)
01-26 15:36:18.251: E/AndroidRuntime(10613): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-26 15:36:18.251: E/AndroidRuntime(10613): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-26 15:36:18.251: E/AndroidRuntime(10613): at dalvik.system.NativeStart.main(Native Method)
01-26 15:36:18.251: E/AndroidRuntime(10613): Caused by: java.lang.ClassNotFoundException: pack.MainActivity
01-26 15:36:18.251: E/AndroidRuntime(10613): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-26 15:36:18.251: E/AndroidRuntime(10613): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-26 15:36:18.251: E/AndroidRuntime(10613): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
01-26 15:36:18.251: E/AndroidRuntime(10613): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
01-26 15:36:18.251: E/AndroidRuntime(10613): ... 11 more
01-26 15:41:18.281: I/Process(10613): Sending signal. PID: 10613 SIG: 9
Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.pack"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="24" />
<permission
android:name="my.pack.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="my.pack.permission.MAPS_RECEIVE"/>
<uses-permission android:name="permission_name"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="My api key"/>
<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>
</manifest>
You full activity name (package + class) is not the same in manifest and code. There's pack.MainActivity declared in manifest but it is not found in code.

Weird Android error

I'm trying to run my start my app, but i get a weird error. I've changed my OS but I've imported my projects in my Workspace. What can be wrong? Every thing is added to the maniferst file like is should, and this app was running nice before I change my OS.
12-13 18:48:10.578: W/dalvikvm(19830): Unable to resolve superclass of Lcom/darkovski/quran/Main; (56)
12-13 18:48:10.578: W/dalvikvm(19830): Link of class 'Lcom/darkovski/quran/Main;' failed
12-13 18:48:10.578: D/AndroidRuntime(19830): Shutting down VM
12-13 18:48:10.578: W/dalvikvm(19830): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
12-13 18:48:10.598: E/AndroidRuntime(19830): FATAL EXCEPTION: main
12-13 18:48:10.598: E/AndroidRuntime(19830): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.darkovski.quran/com.darkovski.quran.Main}: java.lang.ClassNotFoundException: com.darkovski.quran.Main
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.access$600(ActivityThread.java:127)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.os.Looper.loop(Looper.java:137)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.main(ActivityThread.java:4441)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.reflect.Method.invokeNative(Native Method)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.reflect.Method.invoke(Method.java:511)
12-13 18:48:10.598: E/AndroidRuntime(19830): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-13 18:48:10.598: E/AndroidRuntime(19830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-13 18:48:10.598: E/AndroidRuntime(19830): at dalvik.system.NativeStart.main(Native Method)
12-13 18:48:10.598: E/AndroidRuntime(19830): Caused by: java.lang.ClassNotFoundException: com.darkovski.quran.Main
12-13 18:48:10.598: E/AndroidRuntime(19830): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
12-13 18:48:10.598: E/AndroidRuntime(19830): ... 11 more
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.darkovski.quran"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.darkovski.quran.Main"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.darkovski.quran.Playlist"
android:screenOrientation="portrait" />
<activity
android:name="com.darkovski.quran.AlbumDetails"
android:screenOrientation="portrait" />
<service
android:name=".MediaPlayerService"
android:enabled="true" />
<activity
android:name="com.darkovski.quran.Favorites"
android:screenOrientation="portrait" />
<activity
android:name="com.darkovski.quran.DownloadManager"
android:screenOrientation="portrait" />
</application>
</manifest>
This has nothing to do with Manifest. It is because somehow the super class of your class com/darkovski/quran/Main is not getting loaded in the apk which leads to a class not found.
Try cleaning and rebuilding the project or restarting eclipse. Just check if all the libraries are present in the new workspace and are build properly.

Starting FragmentActivity from Activity with Intent

I'm getting a force close every time I try to start a FragmentActivity from an Activity using an Intent. Here's the code from the Activity:
Intent intent = new Intent(getApplicationContext(), OrgHome.class);
intent.putExtra("Username", organization_name.getText().toString());
startActivity(intent);
And here's the logcat:
08-01 16:52:45.823: E/AndroidRuntime(600): FATAL EXCEPTION: main
08-01 16:52:45.823: E/AndroidRuntime(600): java.lang.NoClassDefFoundError: com.project3.organizations.OrgHome
08-01 16:52:45.823: E/AndroidRuntime(600): at com.project3.organizations.MainActivity$1$1.mobDBResponse(MainActivity.java:76)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.mobdb.android.MobDBRequest.onPostExecute(MobDBRequest.java:78)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.mobdb.android.MobDBRequest.onPostExecute(MobDBRequest.java:1)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask.finish(AsyncTask.java:417)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask.access$300(AsyncTask.java:127)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.os.Looper.loop(Looper.java:123)
08-01 16:52:45.823: E/AndroidRuntime(600): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-01 16:52:45.823: E/AndroidRuntime(600): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 16:52:45.823: E/AndroidRuntime(600): at java.lang.reflect.Method.invoke(Method.java:507)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-01 16:52:45.823: E/AndroidRuntime(600): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-01 16:52:45.823: E/AndroidRuntime(600): at dalvik.system.NativeStart.main(Native Method)
08-01 16:52:48.053: I/Process(600): Sending signal. PID: 600 SIG: 9
OrgHome.class is defined in the manifest correctly. What's going on here?
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project3.organizations"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="OrgHome"></activity>
</application>
</manifest>
Change the manifest:
Use this if OrgHome is in the same place as MainActivity
<activity android:name=".OrgHome" />
Use this if it's in a sub-folder
<activity android:name=".sub.path.to.OrgHome" />
Or specify the whole path
<activity android:name="entire.path.to.OrgHome" />
for addressing the Fragment activities you should write (getactivity(),nameofOtherActivity.class); and you should be all right.

Application fails to bind service

I am trying to bind a service which is included in a Library project with the following lines:
Intent i = new Intent();
i.setClassName("de.ring0", "de.ring0.ToolkitService");
bindService(i, this, Context.BIND_AUTO_CREATE);
The binding process fails with the debug output below. According to the Android developer documentation the options in the two manifest files should be correct.
AndroidManifest.xml Library Project
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.ring0">
<uses-sdk android:minSdkVersion="8" />
<application android:debuggable="true">
<service android:name="de.ring0.ToolkitService" android:exported="true" android:enabled="true"/>
</application>
</manifest>
AndroidManifest.xml Main Project
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.ring0.example.tactilecompass"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true">
<activity android:name=".TactileCompassActivity"
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="de.ring0.ToolkitService" />
</application>
</manifest>
Debug Log from emulator
W/ActivityManager( 59): Permission denied: checkComponentPermission() reqUid=10036
W/ActivityManager( 59): Permission Denial: Accessing service ComponentInfo{de.ring0/de.ring0.ToolkitService} from pid=2994, uid=10037 requires null
W/dalvikvm( 2994): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 2994): FATAL EXCEPTION: main
E/AndroidRuntime( 2994): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.ring0.example.tactilecompass/de.ring0.example.tactilecompass.TactileCompassActivity}: java.lang.SecurityException: Not allowed to bind to service Intent { cmp=de.ring0/.ToolkitService }
E/AndroidRuntime( 2994): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime( 2994): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 2994): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 2994): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 2994): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2994): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2994): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 2994): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2994): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2994): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 2994): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 2994): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2994): Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { cmp=de.ring0/.ToolkitService }
E/AndroidRuntime( 2994): at android.app.ContextImpl.bindService(ContextImpl.java:874)
E/AndroidRuntime( 2994): at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
E/AndroidRuntime( 2994): at de.ring0.example.tactilecompass.TactileCompassActivity.onCreate(TactileCompassActivity.java:28)
E/AndroidRuntime( 2994): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 2994): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime( 2994): ... 11 more
W/ActivityManager( 59): Process de.ring0.example.tactilecompass has crashed too many times: killing!
W/ActivityManager( 59): Force finishing activity de.ring0.example.tactilecompass/.TactileCompassActivity
I/Process ( 59): Sending signal. PID: 2994 SIG: 9
Use:
new Intent(this, de.ring0.ToolkitService.class);

Unable to load webpage using WebView in Android

I have recently taken up Android Development and I was looking to using the WebView display webpages. I picked up from the sample that was given on Google site and for some reason the emulator kept saying page was not available. I searched in StackOverflow and found links relating to WebViewClient. I tried that also but no luck there, I have checked multiple times about the manifest entry for internet permission and its there. As a test I ran the browser available within the emulator and sure enough my firewall popped up a question on whether to allow it access or not. The pop up never came to me when I was running it from program. The code that I have is what is there Google pages
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
mWebView.setWebViewClient(new HelloWebViewClient());
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
I tried loading simple html directly using loadData and it worked fine. I am at loss as to what is happening and how this can be resolved. I would appreciate any help on this.
Adding the Android Manifest here
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellowebview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloWebView"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.INTERNET" />
</application>
</manifest>
To check if its just a WebView thingy, I tried accessing the internet using httpGet and httpResonse classes and got the same problem, the code was not able to connect to the given site. It failed stating the below
05-10 00:37:53.191: WARN/System.err(294): java.net.UnknownHostException: feeds.feedburner.com
05-10 00:37:53.230: WARN/System.err(294): at java.net.InetAddress.lookupHostByName(InetAddress.java:513)
05-10 00:37:53.230: WARN/System.err(294): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278)
05-10 00:37:53.230: WARN/System.err(294): at java.net.InetAddress.getAllByName(InetAddress.java:242)
05-10 00:37:53.250: WARN/System.err(294): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
05-10 00:37:53.250: WARN/System.err(294): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
05-10 00:37:53.250: WARN/System.err(294): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
05-10 00:37:53.271: WARN/System.err(294): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
05-10 00:37:53.271: WARN/System.err(294): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
05-10 00:37:53.280: WARN/System.err(294): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-10 00:37:53.291: WARN/System.err(294): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
05-10 00:37:53.301: WARN/System.err(294): at com.example.hellowebview.HelloWebView.onCreate(HelloWebView.java:43)
05-10 00:37:53.301: WARN/System.err(294): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 00:37:53.309: WARN/System.err(294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 00:37:53.322: WARN/System.err(294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 00:37:53.330: WARN/System.err(294): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-10 00:37:53.340: WARN/System.err(294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-10 00:37:53.350: WARN/System.err(294): at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 00:37:53.350: WARN/System.err(294): at android.os.Looper.loop(Looper.java:123)
05-10 00:37:53.361: WARN/System.err(294): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 00:37:53.361: WARN/System.err(294): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 00:37:53.372: WARN/System.err(294): at java.lang.reflect.Method.invoke(Method.java:521)
05-10 00:37:53.380: WARN/System.err(294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 00:37:53.380: WARN/System.err(294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 00:37:53.401: WARN/System.err(294): at dalvik.system.NativeStart.main(Native Method)
05-10 00:37:56.773: WARN/ActivityManager(58): Launch timeout has expired, giving up wake lock!
05-10 00:37:58.083: WARN/ActivityManager(58): Activity idle timeout for HistoryRecord{44fc9108 com.example.hellowebview/.HelloWebView}
05-10 00:38:06.300: DEBUG/KeyguardViewMediator(58): pokeWakelock(5000)
05-10 00:38:06.651: INFO/ARMAssembler(58): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x3724c8:0x3725d4] in 7266287 ns
05-10 00:38:06.720: INFO/ARMAssembler(58): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x371380:0x371548] in 1486222 ns
05-10 00:38:30.430: DEBUG/AndroidRuntime(294): Shutting down VM
05-10 00:38:30.430: WARN/dalvikvm(294): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): FATAL EXCEPTION: main
05-10 00:38:30.752: ERROR/AndroidRuntime(294): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hellowebview/com.example.hellowebview.HelloWebView}: java.lang.NullPointerException
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.os.Looper.loop(Looper.java:123)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at java.lang.reflect.Method.invokeNative(Native Method)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at java.lang.reflect.Method.invoke(Method.java:521)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at dalvik.system.NativeStart.main(Native Method)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): Caused by: java.lang.NullPointerException
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at com.example.hellowebview.HelloWebView.onCreate(HelloWebView.java:51)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-10 00:38:30.752: ERROR/AndroidRuntime(294): ... 11 more
Got it. For some reason the order in which the permission is set matters a lot. I changed the order of my permission setting in manifest file and it worked. Here's the modified manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellowebview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloWebView"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I am not sure what is the significance of this but would appreciate if anyone could elaborate.
Got it. For some reason the order in which the permission is set matters a lot. I changed the order of my permission setting in manifest file and it worked. Here's the modified manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellowebview"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".HelloWebView"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
mWebView = (WebView) findViewById(R.id.webview);
WebSettings setting =mWebView.getSettings();
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
mWebView.loadUrl("http://www.google.com");
Use this code .shouldOverrideUrlLoading() not use compulsary.use this code and please reply me this code work or not
Your code looks fine. I would make sure internet is working correctly on the emulator by browsing a few pages on the Android Browser. I have had problems before where the emulator would lose network access.

Categories

Resources