Cant find folder and variable under res folder - java

I am new with android development and I created a new folder under res folder named videos and then I put a video file in it to use in the app. following is my code in attempt to use the video file.
package com.example.touseef.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView MyVideoView =(VideoView) findViewById(R.id.videoView);
MyVideoView.setVideoPath("android.resource://"+getPackageName()+"/"+R.videos.bang);
MyVideoView.start();
}
}
ERROR : It was giving error cannot find variable R.videos before, but then I tried to clean and rebuilt project after starting android studio, and it asked me for somelinking with bang.mp4 file as text document and I said ok.
Now when I try to build it, the bang.mp4 file opens in a text form within android studio and I receive following error.
Content is not allowed in prolog
Note: I cant see the folder videos under res folder within android view in android studio but folder does exist as I can see it in FileEx plorer in my pc and it also has that video file in it. Also note that when I restart my project, I can see the folder, but it again disappears after android studio completes loading with indexing of my project.

res/videos is not a valid resource folder. You'll need to put your video into res/raw and refer to it from R.raw. Have a look at the Providing Resources section of the Android documentation. One important gotcha to keep in mind though:
However, if you need access to original file names and file hierarchy, you might consider saving some resources in the assets/ directory (instead of res/raw/). Files in assets/ are not given a resource ID, so you can read them only using AssetManager.

Create raw folder inside res folder and put your videos in that folder
String uri = "android.resource://" + getPackageName() + "/" + R.raw.video;
Uri video = Uri.parse(uri);
VideoView videoView=(VideoView) findViewById(R.id.videoView);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
videoView.start();
}
});

Related

Empty Open Street Map with OSMDroid & Android Studio

I have a problem while developing an Android App with a simple Open Street Map Acitivity. My AVD shows a empty map and the log says:
> W/System: ClassLoader referenced unknown path: /data/app/com.example.philipp.myapplication-1/lib/x86_64
> I/OsmDroid: Using tile source: Mapnik
> E/OsmDroid: unable to create a nomedia file. downloaded tiles may be visible to the gallery. open failed: ENOENT (No such file or
> directory)
> I/OsmDroid: sdcard state: mounted
This is my MainActivity:
import android.app.Activity;
import android.os.Bundle;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.views.MapView;
public class MainActivity extends Activity {
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView map = (MapView) findViewById(R.id.map);
map.setTileSource(TileSourceFactory.MAPNIK);
}
}
I haven't found anything at my online researches. And I'm not sure if this is a code or emulator problem..
Thanks for your help! If you need more information, let me know!
I might have a solution for you:
In my case the solution was to give permissions to use location and storage to my application in the android settings. Because i did not use the latest permission model, the application did not have the necessary permission to write storage and provide tiles.
//onde mostra a imagem do mapa
Context ctx = getApplicationContext();
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
use this code within on create

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.

build.xml:1: Premature end of file

I am new in Android development, and I wanna build some apps for myself. I have installed Android SDK last version, NetBeans IDE 7.4 and also the plugin for this. I wrote a simple code for Android to see if it works:
package com.app;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("HelloWorld");
setContentView(tv);
}
}
When I try to build and run with an emulator, I get this error: [path] \AndroidApplication1\build.xml:1: Premature end of file.
When I go to the file (build.xml) I see that is empty. I should write to it? What should I do? Thanks in advance.

Android Project with Eclipse - HTML - WebSources

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

Main layout not recognized, immediately after starting new Android project

The below code was automatically generated when I started a new android project.
I'm getting an error on the "R.layout.main" saying it does not exist.
I do in fact have a main.xml and I can see the layout change as I edit it in the Graphical Layout tab.
How can I fix this so I can run my application?
public class ComplimentGeneratorActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
The package name of the R file and the package name of your source code may not match. Make sure the package your code is in is the same as the package defined in the manifest file. Otherwise you will need to import the R file with the full package name (ex: com.example.R.layout.main).
If they match, for some reason your R file was not generated properly. Try cleaning your project.
Also, start accepting some answers. I almost didn't answer this because of your horrible acceptance rate.
This may be a very simple answer, but it has happened to me before. Try to restart eclipse. File -> Restart
Try to import the R.java file with the full path inside the main activity class file...
import com.example.packagename.R;
Hope, this will solve your query.

Categories