Android Project with Eclipse - HTML - WebSources - java

I am creating an Android project with eclipse. My main on create class refers ton an HTML file so I can program my application within HTML (where I am most fluent) using this code:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/www/index.html");
}
This works just fine but when I work within my .html file I cannot fetch a file from the internet. For example this line:
<img src="http://www.johndoe.gr/newpicks.jpg"
It does not return the picture I want. What do I have to do to be able to fetch data from the web into my application?
ps. the picture link I added is random and does not refer to a real picture in the Question. I use a real link on my code and it doesn't work.

#Symeon - Have to Provided the Internet Permission in Manifest File.
And to use HTML i will suggest Please use Phonegap.. import CoroDova.jar and required Permissions for phonegap.. than when u run the HTML through Phonegap on Android i will run with ease and Even u will be able to use jquery mobile and javascripts and all

Related

How to change a photo?

I am trying to change photos in android studio by clicking on my button.
When I put code for changing the photo in my MainActivity.java I keep getting this type of error messages and it says :
Cannot resolve symbol "image"
image.setImageResource(R.drawable.xxx);
I am watching Udemy course for android development and I have done everything same like the professor on that video.
I have tried to restart android studio.
I have tried to make new project.
I have tried to clear invalidate caches and restart.
public void changeImage(View view)
{
ImageView bitcoin = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);
}
I hope there is actual error with android studio,because code is clone of the video that I am watching.
You are binding your layout's ImageView in Java file with bitcoin variable and you are trying to set an image on an unknown variable 'image'(maybe it's not defined in the class). So you have to set as below.
ImageView bitcoin = findViewById(R.id.bitcoin);
bitcoin.setImageResource(R.drawable.xxx);
Set Your Code Like this
ImageView image = findViewById(R.id.bitcoin);
image.setImageResource(R.drawable.xxx);
change your this line
image.setImageResource(R.drawable.xxx)
to this one:
bitcoin.setImageResource(R.drawable.xxx)

Android - Playing Youtube Videos using Youtube Player API in ListView

I have tried using WebViews to display Youtube Videos in ListView, what happens is when i scroll off screen and back to the cell the Video was located the Video disappears meaning that the WebView does not render back the WebView with the Video in it. So i tried using YoutubePlayerAPI but i am finding it difficult to understand how i can insert these Videos using the YoutubePlayerAPI.
Could someone please advise?
I have tried using YoutubePlayerView in my ArrayAdapter but i get Inflate errors, i have also created YoutubeBaseActivity and YoutubeFragment but cant understand how i get the layout or ui to display these videos in my ListView Cells.
How i did it
Download the youtube android SDK from here then get the jar file and copy it to libs folder on your app.
Enter this in dependency in gradle.build under dependencies
compile files('libs/YouTubeAndroidPlayerApi.jar')
Syc and build.
Create an activity that extends YoutubeBaseActivity like below and implement the YoutubePlayer.OnInitializedListener as shown below. Override the methods on the interace. Android studio can help you do this.
public class Display extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
Then, when it loads successfully,
#Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean b) {
if (!b) {
player.cueVideo(videoID);
}
}
This will load the youtube player and you play on the API
Happy coding, sorry am late

Android Unable to Import Library project

I read almost every answer obout this topi c but i cannot find a working solution for my case or maybe I'm missing somthing.
I use eclipse as IDE and I would like to use an external library for example I'm trying to add this Library to my project but I don't understand what i'm doing wrong.
I tried download the full project and import it into the workspace, mark it as library and then under my project and add it as reference.
If everything is ok how should I call an activity from the linke library?
I tried to defind the linked activity into my manifest file but without success.
Could you please point me in the right way?
Thank you
You need to write code which will call the library activity inside onCreate() or any other method which you choose like
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
//Here you need to call directory chooser activity.
final Intent chooserIntent = new Intent(this, DirectoryChooserActivity.class);
final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
.newDirectoryName("DirChooserSample")
.allowReadOnlyDirectory(true)
.allowNewDirectoryNameModification(true)
.build();
chooserIntent.putExtra(DirectoryChooserActivity.EXTRA_CONFIG, config);
startActivityForResult(chooserIntent, REQUEST_DIRECTORY);
}
Import DirectoryChooserActivity and DirectoryChooserConfig class in your activity; If you are not able to import the mentioned class then you are not added library into the project correctly.

Custom webview in cordova app

I am new to android development and just started working on a web app using cordova, ionic framework and angular. I have completed the basic features of the app and found that the transitions between views in the app are a bit slow
I found this article to improve them here:
https://github.com/ajoslin/angular-mobile-nav/wiki/PhoneGap,-improving-performance
I have never coded in java and so I am stuck.
I tried doing the following
went to the cordovawebview.java in the path myapp\platforms\android\CordovaLib\src\org\apache\cordova and added the import statements missing in the file (except for the "import org.apache.cordova.CordovaWebView")
which were using in the article and copy-pasted the myWebview class.
Then I went to the StarterApp.java, below path
\myapp\platforms\android\src\com\ionicframework\starter
and modified it to
public class StarterApp extends CordovaActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
CordovaWebView webView = new MyWebView(MyActivity.this);
super.init(webView, new CordovaWebViewClient(this, webView), new CordovaChromeClient(this, webView));
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html")
}
}
But when I run the cordova build command I am getting a error. Could someone tell me, what I am missing?
This looks incorrect to me:
CordovaWebView webView = new MyWebView(MyActivity.this);
Have you written code for MyWebView?
MyActivity doesn't seem to exist. You can just use this.

Error caused when converting android activity based app to fragment based

I am new to Android Development and I have a simple list app which I have been asked to create.I have had no problems having the app as activity based however I have to extend the functionality and use fragments for a 'universal' app. My main activity is:
I was able to successfully compile your code by taking the following steps:
It looks like this line is the problem (inside Main.java):
contactCursor = contactDBAdapter.getAllContactsCursor();
I looked at how your contactDBAdapter gets initialized and it turns out you initialize it after you setContentView for your activity. However, your view involves calls to contactDBAdapter. So in Main.java you need to move the following two lines to the TOP of the onCreate window:
public void onCreate(Bundle savedInstanceState)
{
contactDBAdapter = new ContactDBAdapter(this);
contactDBAdapter.open();
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
....
}
Furthermore, the following line in Main.java needs to be removed (or commented out):
contact.clear();
Also, I had to make two further changes to how you call ListView
In list_view.xml, the way you identify a ListView for Android is :
android:id="#+id/android:list"
In ContactListFragment.java, then call the ListView this way :
parent.myListView = (ListView)v.findViewById(android.R.id.list);
have you not just tried using the Eclipse Template which set up everything for you just copy in your existing code?
File>New>Android Application Project then under the Create Activity Step select
Your Fragment class needs an empty default constructor. See Android Reference

Categories