This is my code, I'm trying to load the parsed data from RSS feed. But I test my app using google.com only, and there's an error.
public class WebsiteOpen extends Activity {
WebView web;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_website_open);
Intent intent = getIntent();
String message = intent.getStringExtra("rss-url");
web = (WebView) findViewById(R.id.webView1);
web.getSettings().setJavaScriptEnabled(true);
web.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
Toast.makeText(WebsiteOpen.this, description,
Toast.LENGTH_SHORT).show();
}
});
web.loadUrl("http://google.com");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.website_open, menu);
return true;
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
web.saveState(outState);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
web.restoreState(savedInstanceState);
}
}
This is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.itcuties.multicategoryrssreader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_dilc"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.itcuties.multicategoryrssreader.RssTabsActivity"
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="com.itcuties.multicategoryrssreader.RssChannelActivity" />
<activity android:name="com.itcuties.multicategoryrssreader.Upfm" />
<activity
android:name="com.itcuties.multicategoryrssreader.listeners.WebsiteOpen"
android:label="#string/title_activity_website_open"
android:configChanges="orientation|screenSize" >
</activity>
</application>
</manifest>
help me please. thank you.
I think you can replace the code of Intent and message with this:
Bundle bundle = getIntent().getExtras();
String message = "";
try{
message = bundle.getString("rss-url"");
}catch(nullpointerException e){
//System.out.println("No String Extra");
}
However, i think the following code is useless. It's should be removed instead.
Intent intent = getIntent();
String message = intent.getStringExtra("rss-url");
If it doesn't work, make sure that the id "webView1" is included in the layout "activity_website_open.xml".
Related
Some how it works on older devices but i tried in 2 new devices the release app doesnt work its shows a white blank screeen after splash screen
And there is no error showing please answer me
main activity
private WebView mywebview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebview = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mywebview.getSettings();
mywebview.setWebViewClient(new WebViewClient());
mywebview.loadUrl("https://netixshop.com/");
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
}
public class myWebClient extends WebViewClient {
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
#Override
public void onBackPressed() {
if (mywebview.canGoBack()) {
mywebview.goBack();
}else{
super.onBackPressed();
}
}
}
here is my manifest
pleasse check this out and find why is the error caused
android manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity"></activity>
<activity android:name=".splashactivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>```
Probably you didn't add the internet permission to Manifest file while it is added to debug manifest file by default. So you need to add the internet permission;
<uses-permission android:name="android.permission.INTERNET" />
and if you work with android 8 or above, probably you will need to add this line under application tag for accessing to non-https web urls;
android:usesCleartextTraffic="true"
finally it will look like this;
<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:usesCleartextTraffic="true"
...>
...
</application>
</manifest>
Sorry, I am new to android apps. creation. I have referred pretty much all solutions but this just doesn't work...and I don't see any problem in below simple-code. My app is simple, Load the splash screen, then load the webview. What is the problem below?
ERROR I get is:
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.wwes.EZEE/com.wwes.EZEE.SecondPage}; have you declared this activity in your Manifext.xml
[COMMENT] Pls. Look below, I have already declared it. what's wrong?
Files are:
MainActivity.java: Here I load the splashscreen image.
package com.example.EZEE;
import com.wwes.EZEE.SecondPage;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Thread for displaying the Splash Screen //
Thread splash_screen = new Thread() {
public void run() {
try {
sleep(1000);
} catch (Exception e){
e.printStackTrace();
} finally {
Intent i = new Intent(MainActivity.this, SecondPage.class);
startActivity(i);
}
}
}; splash_screen.start();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
SecondPage.java: This loads the webview.
package com.wwes.EZEE;
public class SecondPage extends Activity {
WebView browserView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Removed the title bare in the Application //
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_second_page);
// Creation of the Webview found in the XML Layout file //
browserView = (WebView)findViewById(R.id.webView1);
// Enable Javascripts //
browserView.getSettings().setJavaScriptEnabled(true);
browserView.getSettings()....
browserView.getSettings()....
browserView.getSettings()....
browserView.getSettings().setLoadsImagesAutomatically(true);
// Removed both vertical and horizontal scroll bars //
browserView.setVerticalScrollBarEnabled(false);
browserView.setHorizontalScrollBarEnabled(false);
browserView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
// Webview Wrap //
browserView.loadUrl("http://www.ABCDE.com");
browserView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onBackPressed()
{ if(browserView.canGoBack())
browserView.goBack();
else super.onBackPressed(); }
}
activity_main.xml:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#800808"
android:scaleType="fitStart"
android:visibility="visible"
android:src="#drawable/logo" />
4) activity_second_page.xml:
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:visibility="gone"
android:layout_alignParentTop="true" />
5) manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wwes.EZEE"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
----------------------------------updated----------------------------------
<application
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.wwes.EZEERACKS.MainActivity" //// UPDATED ///
android:configChanges="keyboard|keyboardHidden|orientation|smallestScreenSize"
android:screenOrientation="portrait"
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="com.wwes.EZEE.SecondPage"
android:label="#string/title_activity_second_page" >
</activity>
</application>
</manifest>
Thanks for the help!
you must defin your activity in manifest.xml file
<activity android:name=".SecondPage"
android:label="#string/title_activity_second_page" >
</activity>
You don't need the <intent-filter> tag in the SecondPage tag of the manifest because you are already starting the activity from MainActivity.
So, remove this:
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
from this:
<activity
android:name="com.wwes.EZEE.SecondPage"
android:label="#string/title_activity_second_page" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
how come your main activity is com.example.EZEE.MainActivity while secondPage is com.wwes.EZEE.SecondPage? I would check if both resides on the same package.
I bet if you have changed the secondPage name to com.example.EZEE.SecondPage it will work.
if it didn't work I would remove the android:name of both activity and within the "", click ctrl + space and let the eclipse handle putting the naming to the activity. therefore the shown activities are guaranteed to work in the application.
Hope this works with you, please give me a feedback.
Just change your defination of .SecondPage to the following in manifest.xml file
<activity android:name="com.wwes.EZEE.SecondPage"
android:label="#string/title_activity_second_page" >
</activity>
In virtual mobile menu is displaying.But it is not displaying in my personal mobile.I have kept mainactivity.java ,main.xml,androidmainfest.xml files here.Any answers please...
//mainactivity.java
public class MainActivity extends Activity{
String username,password; ResultSet rs =null;
boolean temcfag=false;
static boolean temqfag=true;
public static String tag="Lifecycle activity";
EditText user,pass;
AlertDialog.Builder dialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialog=new AlertDialog.Builder(this);
dialog.setNeutralButton("OK", null);
user=(EditText)findViewById(R.id.editText1);
pass=(EditText)findViewById(R.id.editText2);
final Button click=(Button)findViewById(R.id.button2);
click.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
Intent launchactivity= new Intent(MainActivity.this,com.example.desisquarea.LoginActivity.class);
startActivity(launchactivity);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
//menu/main.xml
<?xml version="1.0" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/login" android:title="SignUP" />
<item android:id="#+id/sign" android:title="Login" />
<item android:id="#+id/home" android:title="Home" />
</menu>
//androidmainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.desisquarea"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<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="com.example.desisquarea.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>
LayoutParams lp = dialog.getWindow().getAttributes();
lp.gravity = Gravity.TOP | Gravity.RIGHT;
myDialog.getWindow().setAttributes(lp);
dialog.show();
I have 2 projects, and I want to embed a project in other. I have created 2 projects and have made a project as library file and inserted in other but I am still unable to get it working. I have taken a simple activity and want to display a toast message, using Intent I have given the address of the next project library. This is the code of the main (first) project.
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.sec_pro";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "First Activity", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this, com.example.sec_pro.MainActivity.class);
EditText editText = (EditText) findViewById(R.id.editText1);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.integrate.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="com.example.sec_pro.MainActivity" >
</activity>
</application>
Now this "sec_pro" is the library file of my next project which I have inserted in the first project.
Please help.
Thanks in advance.
I think you have missed to declare your library activity in Manifest.
try this code to declare in to manifest under application tag:
<activity android:name="PackageName.YourLibraryActivity" />
Please check onClick method again, I think you missed a statement:
startActivity(intent);
I would like to make my webapp look as similar as I can to a native app, now I just realized that there's no notification bar at the top and that Android back button doesn't take you to the last screen but closes the app. Does anybody know how to fix this?
Manifest
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:hardwareAccelerated="true">
<activity
android:name="com.example.mywebapp.MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Activity
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String URL = "file:///android_asset/Compatibilidades/public_html/index.html";
WebView myWebView = (WebView) this.findViewById(R.id.webView);
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
myWebView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
myWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
myWebView.loadUrl(URL);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
}
Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Found the solution, you need to put this parameter in the activity in AndroidManifest.xml
<activity
android:theme="#android:style/Theme.NoTitleBar">
In order to support the back button, you can do the following (source):
public class MainActivity extends Activity {
#Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
}