How to prevent url to show in web view [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hi there I am trying to create app where I am using web view to show my google drive folder but whenever internet got disconnect in between loading the URL at that a msg comes with showing the URL information.
What can I do to prevent showing URL from users.
Is it possible to show some other msg whenever internet goes down on starting or when it goes down on after starting loading.

I have a custom HTML page that will show if something wrong happened when loading the url.
webView.setWebViewClient(new WebViewClient(){
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
switch(errorCode){
case ERROR_HOST_LOOKUP:
webView.loadDataWithBaseURL(null,"<YOUR OWN CUSTOM HTML PAGE TO SHOW WHEN THERE'S AN ERROR>", "text/html", "UTF-8",null);
break;
case ERROR_CONNECT:
webView.loadDataWithBaseURL(null,"<YOUR OWN CUSTOM HTML PAGE TO SHOW WHEN THERE'S AN ERROR>", "text/html", "UTF-8",null);
break;
case ...[IF YOU WANT TO CATCH MORE ERRORS]
}
}
}
Reference: https://developer.android.com/reference/android/webkit/WebViewClient#onReceivedError(android.webkit.WebView,%20int,%20java.lang.String,%20java.lang.String)
Error Code Reference:
https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_AUTHENTICATION

Yes! You can either print the message or redirect the user to some other activity by checking the following method soon after the app gets launches...
DD4YouConfig dd4YouConfig = new DD4YouConfig(context);
if (dd4YouConfig.isInternetConnectivity()) {
//redirect to webview
}
else
{
//call alert dialog stating no internet
}
This is a library function so obviously don't fail to add this line in Gradle
implementation 'in.dd4you.appsconfig:appsconfig:1.3.3'

Related

Android Studio Webview Check for URL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I just wanted to know how can I execute a specific action when a User navigates to an URL inside a Webview, for Example something like:
if (URL == https://google.com) {
execute Action
You need to setWebViewClient to override the urls like below -
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if ( url.startsWith("https://google.com")){
// your action
}
});
Hope this will help you.

selenium POM framework and TestNG wait Time [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
In my Test script have to write waiFor(5) for every excution, else Test fails.
Am using POM, and have separate class.
#Test(priority=2)
public void TestMedical() throws InterruptedException {
waitFor(5);
MedicalPage medicalpage = new MedicalPage(driver);
waitFor(5);
medicalpage.PhysicianName(Repo.getProperty("fName"));
medicalpage.seteditableLastName(Repo.getProperty("lName"));
waitFor(5);
medicalpage.setPhone(Repo.getProperty("Phone"));
waitFor(5);
medicalpage.setEmail(Repo.getProperty("Email"));
}
This is my Login Page (Object)-
// Created methods in this page, and using Testng trying to call all the below methods. But getting failure message Unable to Locate Element, If there is no wait time watFor(5). With Wait time its running fine.In base page have explicit wait time method, but its not working. After input the data in text field when i click on submit button page is doing some Java Script or Ajax.
Ajax call takes 60 sec max.
driver.findElement(firstName).click();
driver.findElement(editableFirstName).clear();
driver.findElement(editableFirstName).click();
driver.findElement(editableFirstName).sendKeys(fName);
}
Added try - catch, works fine now
WebElement element = driver.findElement(XYZ);
boolean clicked = false;
do{
try {
element.click();
} catch (WebDriverException e) {
continue;
} finally {
clicked = true;
}
} while (!clicked);;

FaceBook ShareLinkContent setImageUrl image is overriden by setContentUrl meta-data image [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to Post the below infromation to FaceBook from Myapp using FaceBook ShareLinkContent class
- link url (using SetContentUrl method)
- image (using setImageurl method)
- hashtags (using setHashTag method)
- and Description
as like
ShareHashtag shareHashTag = new ShareHashtag.Builder().setHashtag(hashtag_name).build();
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setImageUrl(Uri.parse(selectedImagePath))
.setShareHashtag(shareHashTag)
.setContentDescription(textd)
.setContentUrl(Uri.parse(linkUrlPath))
.build();
shareDialog.show(linkContent);
}
} else {
shareImage();
}
The question is, instead of posting the image from "selectedImagePath" url, it post the meta-data image coming from the "linkUrlPath" url.
How to overcome it, so that i can post the image which i send in the method setImageUrl() method.
note: I am using Facebook SDK 4.14.1
Kindly provide suggestions
I guess this is what you are looking for -
Template Matching
Template Matching is a method for searching and finding the location of a template image in a larger image. OpenCV comes with a function matchTemplate() for this purpose. It simply slides the template image over the input image (as in 2D convolution) and compares the template and patch of input image under the template image.

How do you make a one time "I agree" activity screen for users on your app? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Can you help me figure out how to make it so my app has users check mark an I agree box before my app goes to the main menu? I need it to only show this screen the very first time the user uses the app. I am new to android studio so any help would be appreciated.
Thanks!
You can easily use SharedPreferences to accomplish this. try doing something like:
final String PREF_NAME = "MyPref";
// getting saved preferences
SharedPreferences settings = getSharedPreferences(PREF_NAME, 0);
if (settings.getBoolean("my_first_time", true)) {
//the app is being launched for first time, do something
Log.d("Comments", "First time");
// first time task
runUserAgreements();
// record the fact that the app has been started at least once
settings.edit().putBoolean("my_first_time", false).commit();
}
Then declare a function named runUserAgreements() and run an activity or dialog showing User Agreements and stuff.
EDIT:
I suggest to put above code in a class extending Application
to check firstrun generally not in the default activity:
public class MyApp extends Application {
#Override
public void onCreate() {
super.onCreate();
// CODE HERE
}
}
and DO NOT forget to call the class in AndroidManifest.xml:
<application android:name=".MyApp"
android:label="#string/app_name"
.
.
...>
....
</application>
Take a look at the Google's iosched project example, specifically this Activity: Welcome Activity. IMHO it has a pretty good UI design too.

How to upload video on twitpic/twitter programatically? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am new in Android.
I was working for uploading Image/Video on Twitter. I used the twitpic for this purpose.
I first sent image to twitpic and then updated the status in twitter with url of the tweet.
Image is successfully loading as per my selection from gallery.
But I am stuck in uploading video on Twitter. As there is option of twitpic or twitvid for uploading video. But there is no such type of code or sdk given. So confused that how to do this, which classes has to be used.
I need a sample code for uploading video.
Was stuck on this for a while myself as well (not a lot of examples around) and found a non-working example here on SO which I've managed to hammer into shape...
First you'll need the twitvid Java API
1 download the jar file (I used twitvid-java 1.6.1)
2 put it in your "libs" folder
3 right-click on your project and go to "properties"
4 select "Java build path" and include the jar ("libraries" tab) and make sure it's built ("order and export" tab)
The code that follows assumes you've already made a token with the regular twitter4j methods:
private void postToTwitvid(String videoPath){
AccessToken token = mTwitter.getAccessToken();
Values values = new Values();
values.setSession(new Session());
TwitvidApi api = new TwitvidApi(values);
api.setSecureUrlEnabled(false);
Session session;
try {
session = api.authenticate(new TwitterAuthPack.Builder()
.setConsumerKey(twitter_consumer_key)
.setConsumerSecret(twitter_secret_key)
.setOAuthToken(token.getToken())
.setOAuthTokenSecret(token.getTokenSecret())
.build());
api.getValues().setSession(session);
final UploadHelper helper = new UploadHelper(api);
File file=new File(videoPath);
TwitvidPost twitvidPost = new TwitvidPost.Builder()
.setFile(file).setChunkSize(10485760)
.setMessage("Twitvid test")
.setPostToTwitter(true)
.create();
try {
if (helper.upload(twitvidPost))
{
Toast.makeText(TwitterShare.this, "Posted on Twitter and Twitvid", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(TwitterShare.this, "Post failed", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ApiException e1) {
e1.printStackTrace();
}
}
The token depends on how you've implemented the regular posting to twitter, just include yours.
Hope this helps!
PS: I had to force the UI thread to accept network connections to make this work
(My first answer! w00t!)

Categories