Empty Open Street Map with OSMDroid & Android Studio - java

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

Related

How to connect mobile app to database

I created a basic barcode scanner app with Java and Android Studio (on my Mac paradoxically). In this app, I simply uploaded (manually) some photos of barcodes to Android Studio in the .../app/src/main/res/drawable folder from my desktop and then I am sending one of these photos each time to Google Mobile Vision Barcode API. I receive from the API the data represented from the barcode and I simply print the data on the screen of the Android emulator.
The MainActivity.java script of this app is the following:
package *********************;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.SparseArray;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.barcode.BarcodeDetector;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ImageView myImageView = (ImageView) findViewById(R.id.imgview);
Bitmap myBitmap = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
R.drawable.image);
myImageView.setImageBitmap(myBitmap);
TextView txtView = (TextView) findViewById(R.id.txtContent);
BarcodeDetector detector =
new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE | Barcode.CODE_128)
.build();
if(!detector.isOperational()){
txtView.setText("Could not set up the detector!");
return;
}
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Barcode> barcodes = detector.detect(frame);
Barcode thisCode = barcodes.valueAt(0);
txtView.setText(thisCode.rawValue);
}
Now I want to use the retrieved data from the Barcode API, send them to (a server and to) a database and retrieve some details stored in this database about the product that has this barcode.
What is the most appropriate way to make my Java app to communicate with a database?
Personally, I am pretty confident in creating a MySQL database and sending back and forth data with PHP.
However, I am not really sure how to connect a script written in Java (which scans barcodes) to a database.
It really depends on your use case.
Possibilities:
1- Make your own database (Sqlite) in your Android App. This means you have to synchronize via web services, with your server's database, whenever you see fit.
Steps:
a) Use an ORM to connect to your local database and to relational map your tables with your classes.
b) Use web service to synchronise your classes (eg. Retrofit) with your server's database, via an API.
2- Only use the 'b' part of the 1-st step to save your data to remote database, on-fly (as soon as data is submmited)
So you actually CAN (b), but connecting to remote database immediately as the data gets submitted is really bad(in my opinion). For many reasons. Take a look here.
In the end, it all comes down to your choice and the best suit for your app's use-case.
Best

Cant find folder and variable under res folder

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();
}
});

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.

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.

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

Categories