I am trying to mirror a website in an android app which I already got a way around it, but am having issues with sharing information inside the app to social media, like when it is clicked in the app to share information to WhatsApp, Facebook, etc I want the app to be able to find each app and open the app with the information, I've tried all way but it's not working kindly help if you can
Thanks in advance
my code
public class MainActivity extends AppCompatActivity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("https://eliteglobalnetwork.net/");
webView.setWebViewClient(new WebViewClient());
}
#Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
}else {
super.onBackPressed();
}
}
}
public static final String WEBSITE_ADDRESS = "website_address";
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = getIntent().getStringExtra(WEBSITE_ADDRESS);
if (url == null || url.isEmpty()) finish();
setContentView(R.layout.activity_webview); //name of your layout
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
}
If want to open in same app -
Intent i = new Intent(YourActivity.this, WebViewActivity.class);
i.putExtra(WebViewActivity.WEBSITE_ADDRESS, ""http://www.google.com"");
startActivity(i);
Add it in Manifest file -
<uses-permission android:name="android.permission.INTERNET" />
Related
I have a WebView app that contain a wordpress site, built with elementor pro. I use a button that will allow the user to call or to navigate to an adress via waze. The issue is that it keeps giving me the
err_unknown_url_scheme
Few fixes that did't work.
public class MainActivity extends AppCompatActivity {
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.loadUrl("https://perfectskin.co.il/app/");
myWebView.setWebViewClient(new WebViewClient());
webSettings.setJavaScriptEnabled(true);
}
#Override
public void onBackPressed() {
if (myWebView.canGoBack()) {
myWebView.goBack();
}else {
super.onBackPressed();
}
}
}
Try to add call permission to manifest file.
"android.permission.CALL_PHONE"
I have tried many times to upload my app, that has a json from Wordpress and webview to open a link from json, I made the changes that was suggested here. But, when I try to upload, Google sends me this message:
Modify your app to make sure it doesn’t access or use a service or API in a manner that violates its terms of service; for example, by enabling background play of YouTube videos.
This is my webview code:
public class Webview extends AppCompatActivity {
WebView myWebView;
private boolean mShouldPause;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
String link = getIntent().getStringExtra("link");
myWebView = (WebView) findViewById(R.id.vebview);
myWebView.loadUrl(link);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient(){
#Override
public void onLoadResource(WebView webview, String url) {
super.onLoadResource(webview, url);
if (url.contains("youtube.com")) mShouldPause = true;
}
});
//button for share the link of webview
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String shareBody = "you body here";
String shareSub= "suject here";
intent.putExtra(Intent.EXTRA_SUBJECT,shareSub);
intent.putExtra(Intent.EXTRA_TEXT,shareBody);
startActivity(Intent.createChooser(intent,"Compartilhe"));
}
});
}
#Override
public void onPause() {
super.onPause();
if(mShouldPause){
myWebView.onPause();
}
mShouldPause = false;
}
Somebody knows what I'm doing wrong?
(Posted on behalf of the OP).
I found the solution, and was in my app, I miss the permission on manifest file
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
I want to do an app that is mainly base on webview. MainActivity is to load www.example.com/products.php.
www.example.com/products.php - display all products*
www.example.com/products.php?id=123 - display individual product base on product ID
www.example.com/cart.php - when clickcing on "Add to cart" on product.php?id=123, it will not open a new Activity but remain in the same activity.
MainActivity.java
private WebView wv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView) findViewById(R.id.webView);
WebSettings wss = wv.getSettings();
wss.setJavaScriptEnabled(true);
wv.loadUrl("http://www.example.com/product.php");
wv.setWebViewClient(new WebViewClient());
}
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com/cart.php")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}else{
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
}
#Override
public void onBackPressed() {
if(wv.canGoBack()){
wv.goBack();
}else{
super.onBackPressed();
}
}
And also for "shouldOverrideUrlLoading " , it shows depreciated... so what's the new name for this?
I want to know how to show a page only with some parts of a HTML code. Something like login and password box, login button... Is it possible to do this using only WebView?
My code:
MainActivity.java:
public class MainActivity extends ActionBarActivity {
Button enterButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView myWebView = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("http://siga.ufvjm.edu.br");
enterButton = (Button) findViewById(R.id.enterButton);
}
private class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("http://siga.ufvjm.edu.br")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
Try to load your page with HttpClient: https://stackoverflow.com/a/4457526/3864698
After that you can customize your html code and set to WebView with loadDataWithBaseURL.
I have a WebView that is opening a Url for an article. However, a couple of seconds after opening the link in the WebView, the browser opens up and loads the same article.
This is my activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_headline_web_view);
Intent intent = getIntent();
Uri headlineUri = intent.getData();
WebView webView = (WebView) findViewById(R.id.webView1);
webView.loadUrl(headlineUri.toString());
}
Thanks in advance!
What happens if you add:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_headline_web_view);
Intent intent = getIntent();
Uri headlineUri = intent.getData();
WebView webView = (WebView) findViewById(R.id.webView1);
webview.setWebViewClient(new MyWebViewClient());
webView.loadUrl(headlineUri.toString());
}
public class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
}