I don't know if you already tested the Google IO application, but there is a cool feature displaying all the tweets including Google IO hashtags.
I really would like to offer the same feature to my users.
I can do something similar using the API, but I would have to create a custom listview, parsing XML/JSON feeds and that's quite overcomplicated! and of course this list will not update automatically and be a livefeed.
In the application, I have just seen that when I turn off wifi, This is indeed a webview with this url:
http://www.google.com/search?%20tbs=mbl%3A1&hl=en&source=hp&biw=1170&bih=668&q=%23io2011&btnG=Search
Here is a screenshot of the app and the same url in the browser
High resolution picture: http://cl.ly/3q1r0c2J3H163E3G2p2X
But using this url in a webview display only a google search, and does not offer same feature.
I know this app will certainly be opensources, but i am so negative about "within next days" that google promise.
We are still waiting for the Twitter app source code!
If you wait 'til after the conference is over, you'll find the source code for the app here. You'll also find last year's application's source code there.
Update:
Just viewed the source code, and you're almost right. It's a webview with this URL: http://www.google.com/search?tbs=mbl%3A1&hl=en&source=hp&biw=1170&bih=668&q=%23io2011&btnG=Search so it just seems you put %20 in there by accident maybe.
Code:
public static final String EXTRA_QUERY = "com.google.android.iosched.extra.QUERY";
public static final String CONFERENCE_HASHTAG = "#io2011";
private String mSearchString;
//onCreate()
final Intent intent = BaseActivity.fragmentArgumentsToIntent(getArguments());
mSearchString = intent.getStringExtra(EXTRA_QUERY);
if (TextUtils.isEmpty(mSearchString)) {
mSearchString = CONFERENCE_HASHTAG;
}
if (!mSearchString.startsWith("#")) {
mSearchString = "#" + mSearchString;
}
//onCreateView
mWebView = (WebView) root.findViewById(R.id.webview);
mWebView.post(new Runnable() {
public void run() {
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
try {
mWebView.loadUrl(
"http://www.google.com/search?tbs="
+ "mbl%3A1&hl=en&source=hp&biw=1170&bih=668&q="
+ URLEncoder.encode(mSearchString, "UTF-8")
+ "&btnG=Search");
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Could not construct the realtime search URL", e);
}
}
});
Probably implemented with Loaders API with throttling.
Impatiently waiting for source code as well.
Related
I followed https://github.com/vimeo/vimeo-networking-java to configure Vimeo client(initialized by that accesstoken) on Android using hardcoded access token (has access to public and private videos). but the call of VimeoClient.getInstance().fetchContent() fails.
public void vimeoSettings(){
String urlPublic = "https://player.vimeo.com/video/496738949";
String urlPrivate = "https://player.vimeo.com/video/496739025";
Configuration.Builder confBuilder = new Configuration.Builder("ACCESS_TOKEN");
//later will generate in runtime and whats the validity?
Configuration configuration = confBuilder.build();
VimeoClient.initialize(configuration);
VimeoClient.getInstance().fetchContent(String.valueOf(Uri.parse(urlPublic)), CacheControl.FORCE_NETWORK, new ModelCallback<Video>(Video.class){
#Override
public void success(Video video) {
if(video != null){
Log.d("webviewactivity","inside vimeo settings - video not null ");
Play play = video.getPlay();
if (play != null) {
VideoFile dashFile = play.getDashVideoFile();
String dashLink = dashFile.getLink();
// load link
VideoFile hlsFile = play.getHlsVideoFile();
String hlsLink = hlsFile.getLink();
// load link
ArrayList<VideoFile> progressiveFiles = play.getProgressiveVideoFiles();
String linkToMp4File = progressiveFiles.get(0).getLink();
webView.load(linkToMp4File);
}
}
}
#Override
public void failure(VimeoError error) {
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
facing these Errors :
E/cr_VariationsUtils: Failed reading seed file "/data/user/0/com.emergingit.emergingstudy/app_webview/variations_seed": /data/user/0/com.emergingit.emergingstudy/app_webview/variations_seed (No such file or directory)
E/chromium: [ERROR:gl_surface_egl.cc(335)] eglChooseConfig failed with error EGL_SUCCESS
what are these errors indicate and, even if I solve this,
is this the right approach to load in Webview as I must have to make my video private with domain restriction for the website use case?
can I use this approach to play in https://github.com/ct7ct7ct7/Android-VimeoPlayer?
I am getting verified first by our token from the backend and then given the URL. after that using the access token and configuring the Vimeo client I need to load the video.
Vimeo official documentation for this kind of private video scenario for android seems really unclear to me and also contacted for help but did not get any response though I have a paid account.
Please help or suggest..!!
I have tried playing vimeo video using webview. But it doesn't look good, it makes the screen scrollable.
Vimeo has suggested one more way to play using native playback, but it has specific requirements to use
The basic requirements for native playback are:
User must be logged in.
User must be the owner of the video.
User must be PRO or higher (or the app must have the "can access owner's video files" capability).
Token must have the video_files scope.
User must be the owner of the API app making the request
I don't have PRO account. How can i use native playback just to test, if all goes well then i will go for vimeo PRO
THIS IS CODE WHICH I AM USING FOR PLAYING USING WEBVIEW
VimeoClient.getInstance().fetchNetworkContent(uri, new ModelCallback<Video>(Video.class) {
#Override
public void success(Video video) {
String html = video.embed != null ? video.embed.html : null;
if(html != null) {
WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadData(html, "text/html", "utf-8");
}
}
#Override
public void failure(VimeoError error) {
Log.d(TAG, "failure: ");
}
});
}
Is there any other way to play the video?
In my case I used Exoplayer. Exoplayer is more customizable. All you need is to extract the url link from the config link. You may use retrofit to extract the video url.
BASE_URL = "https://player.vimeo.com/video/"
You will need to use a get method like below:
#GET("{id}/{config}")
Call<JsonObject>getVideoLink(#Path("id") String id, #Path("config") String config);
You will get the id from video link. Example: "https://vimeo.com/123456789/" Here the id is: 123456789 .
JsonObject jsonObject = response.body();
JsonObject req = jsonObject.getAsJsonObject("request");
JsonObject file = req.getAsJsonObject("files");
JsonArray arr = file.getAsJsonArray("progressive");
String url = arr.get(0).getAsJsonObject().get("url").getAsString();
Now you can play using this url . Don't forget to initiate Exoplayer first.
I'm trying to implement oauth authorization into my Android(KitKat based) app.
I've prepared own oauth2 server,based on php (Symfony3 Framework + FOS Oauth Server Bundle).
Now I need to make authorization in android app.
I was wondering on internet and I didn't found any solution which can help me to do authorization. There are a lot of docs, which describes OAUTH using google or other social services, but, as I told, I have my own oauth server.
I was trying to make something in mobile app, and i meet a few problems.
Oauth flow requires to open web-view element in app and accept usage of my web account by my app. This flow works in my server, but i have no idea how to do it in app. I tried to open web view, i was passing auth flow and was getting code, but it is displayed inside webview.
I found method - which catch the moment of web-view load, and in this case - i can catch some params from web-view URL, but my oauth flow in web is under firewall. If i'm not authorized in web - flow will redirect me to login page, and later - after success login - it will offer me accept or deny usage of my account data. So, i can't use onPageFinished or something else.
Other case, i can obtain access_token by passing login,password, client_id,secret and other params. I was thinking to make 2 services in app, first will check locally - if my token is not expired, and if it is - it will run second service - to refresh my token - to make http request to my oauth server(web application). But I meet another problem here.
I'm using Volley library to make http calls. AS I know, volley runs asynchronous requests to web. I was trying to move my request into separate class/service.
But i had problems with nullable context. Ok. I decided to make requests in activity class (not good case of usage, but ok), and there - i meet another problems.
I have defined button, and onClick listener for it.
I want to authenticate user after he'll path login and password into EditText fields and in onClick for sign in button - i'm checking SharedPreferences for client_id, and if it's empty - i want to get new oauth client_id from web, i'm runing new volley request in onCLickListener. The problem is that - i can't obtain response correctly.
My code example.
```
signIn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
String login = LoginView.getText().toString();
String password = PasswordView.getText().toString();
auth_dialog = new Dialog(LoginActivity.this);
auth_dialog.setContentView(R.layout.auth_dialog);
preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
preferences.edit().putString(getString(R.string.oauth_client_id), null).apply();
String clientId = preferences.getString(getString(R.string.oauth_client_id), null);
preferences.edit().putString(getString(R.string.user_login), login).apply();
preferences.edit().putString(getString(R.string.user_password), password).apply();
if(clientId == null){
RequestQueue queue = Volley.newRequestQueue(context);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String url = context.getString(R.string.url) + context.getString(R.string.url_token) + "?";
url += "client_id=" + preferences.getString(context.getString(R.string.oauth_client_id), null) + "&";
url += "client_secret=" + preferences.getString(context.getString(R.string.oauth_client_secret), null) + "&";
url += "grant_type=" + context.getString(R.string.grant_type_password) + "&";
url += "username=" + preferences.getString(context.getString(R.string.user_login), null) + "&";
url += "password=" + preferences.getString(context.getString(R.string.user_password), null);
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
#Override
public void onResponse(String response){
clientResponse = response;
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, "Request for getting Token failed", Toast.LENGTH_SHORT).show();
}
});
queue.add(stringRequest);
}
Log.d("VIOO_APP", clientResponse);// THIS IS THE PLACE WHERE ERROR HAPPENS
token = getToken();
Toast.makeText(getApplicationContext(), token.getAccessToken(), Toast.LENGTH_LONG).show();
}
});```
I want to say that all variables are defined - it's jsut the part of code from button onClick Listener. clientResponse variable defined in activity class as Global variable.
Ofcorse, i can put my logic into response statement - when volley got response - do my stuff, but i think - later, my code will be unreadable and it's not good approach in building app structure. It's a total bullshit to make request in response from another request, and so on...
I had good cases, when my request was working in another class.
I saw examples in internet - how some guys tries to make app service - to make requests through volley, but probably, this info is not actual now. Every internet case - which i found - won't work or provide useless info.
I see this challenge like unwinnable. All stuff I try - fails and won't work.
I hope, i explained my problem fully.
Thank you.
I'm making an Android app for my board community. The board provider gives me RSS feeds from general categories but don't generate feeds from topics. So I retreive topics URLs from these feeds and want to parse HTML with Jsoup and give it to a WebView.
It works nice except with the select() function which returns nothing.
The "HTML RETREIVED" log gives me : <html><head><title>The topic title</title></head><body></body></html>
h1 tags are in the code on test purpose : it displays well on WebView and the title of the parsed webpage too.
I also putted the log line right after the select() line. It returns nothing too.
I've tried in a pure Java project to parse with Jsoup only and it goes well.
So I assumed something's wrong with Android.
PS : Internet permission is active in the manifest.
Did I miss something ?
Here is the code :
String html;
Bundle param = this.getIntent().getExtras();
String url = param.getString("url");
try {
Document doc = Jsoup.connect(url).get();
doc.select(".topic .clear").remove();
String title = doc.title().toString();
html = doc.select(".username strong, .entry-content").toString();
html = "<html><head><title>"+title+"</title></head><body><h1>"+title+"</h1>"+html+"</body></html>";
WebView webview = new WebView(this);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setProgress(progress * 1000);
Log.d("LOADING",""+ progress);
}
});
webview.loadData(html, "text/html", "UTF-8");
//webview.loadUrl(url);
Log.i("HTML RETREIVED", ""+html);
} catch (IOException e) {
Log.e("ERROR", "Error while generate topic");
}
Ok I've found out something interesting.
The class I wanted to select was not here because I'm getting the mobile version of the webpage. It appears Android App use a mobile user-agent, which is quite normal but not said anywhere.
Anyway I know what thinking about now.
I am trying to parse HTML in android from a webpage, and since the webpage it not well formed, I get SAXException.
Is there a way to parse HTML in Android?
I just encountered this problem. I tried a few things, but settled on using JSoup. The jar is about 132k, which is a bit big, but if you download the source and take out some of the methods you will not be using, then it is not as big.
=> Good thing about it is that it will handle badly formed HTML
Here's a good example from their site.
File input = new File("/tmp/input.html");
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
//http://jsoup.org/cookbook/input/load-document-from-url
//Document doc = Jsoup.connect("http://example.com/").get();
Element content = doc.getElementById("content");
Elements links = content.getElementsByTag("a");
for (Element link : links) {
String linkHref = link.attr("href");
String linkText = link.text();
}
Have you tried using Html.fromHtml(source)?
I think that class is pretty liberal with respect to source quality (it uses TagSoup internally, which was designed with real-life, bad HTML in mind). It doesn't support all HTML tags though, but it does come with a handler you can implement to react on tags it doesn't understand.
String tmpHtml = "<html>a whole bunch of html stuff</html>";
String htmlTextStr = Html.fromHtml(tmpHtml).toString();
We all know that programming have endless possibilities.There are numbers of solutions available for a single problem so i think all of the above solutions are perfect and may be helpful for someone but for me this one save my day..
So Code goes like this
private void getWebsite() {
new Thread(new Runnable() {
#Override
public void run() {
final StringBuilder builder = new StringBuilder();
try {
Document doc = Jsoup.connect("http://www.ssaurel.com/blog").get();
String title = doc.title();
Elements links = doc.select("a[href]");
builder.append(title).append("\n");
for (Element link : links) {
builder.append("\n").append("Link : ").append(link.attr("href"))
.append("\n").append("Text : ").append(link.text());
}
} catch (IOException e) {
builder.append("Error : ").append(e.getMessage()).append("\n");
}
runOnUiThread(new Runnable() {
#Override
public void run() {
result.setText(builder.toString());
}
});
}
}).start();
}
You just have to call the above function in onCreate Method of your MainActivity
I hope this one is also helpful for you guys.
Also read the original blog at Medium
Maybe you can use WebView, but as you can see in the doc WebView doesn't support javascript and other stuff like widgets by default.
http://developer.android.com/reference/android/webkit/WebView.html
I think that you can enable javascript if you need it.