SOLVED. please lock.
I have 2 buttons, Server and Client.
The server button contain a textview which prints stuff received from the client.
The client button open Editbox and Send button which uses OnClick function.
In debug mode everything works fine.
When I run them independently and playing with ON/OFF SocketServer and Existing/New SocketClient the program would mostly get stuck and sometimes i get flowed with "Client says: null"
It usually happens when I click in device1 on Server Button, in device2 on client -> send a message from device2 to device1 and it successes -> close server on device1 -> send about 3 messages on device2 (remember that the serverSocket is closed) -> open server on device1 -> close and open client on device2.
The app also getting stuck randomaly after some turn off screen and turn on using the power button while playing with buttons.. and I cant find the issue.
Server.java:
Code:
package com.example.socketproject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.concurrent.TimeUnit;
import org.apache.http.conn.util.InetAddressUtils;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
public class Server extends Activity
{
private ServerSocket serverSocket;
Handler updateConversationHandler;
Thread serverThread = null;
private TextView text;
private final static int SECONDS_TO_WAIT = 1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_server);
text = (TextView) findViewById(R.id.textview_server);
updateConversationHandler = new Handler();
this.serverThread = new Thread(new ServerThread());
this.serverThread.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.server, menu);
return true;
}
@Override
protected void onDestroy()
{
super.onDestroy();
try
{
if (!serverSocket.isClosed())
{
serverSocket.close();
}
if (!serverThread.isInterrupted())
{
serverThread.interrupt();
}
}
catch (IOException e)
{
Log.e(TAG, e.getMessage() + " |||| " );
}
}
@Override
protected void onStop()
{
super.onStop();
try
{
if (!serverSocket.isClosed())
{
serverSocket.close();
}
if (!serverThread.isInterrupted())
{
serverThread.interrupt();
}
}
catch (IOException e)
{
Log.e(TAG, e.getMessage() + " |||| " );
}
}
private class ServerThread implements Runnable
{
public void run()
{
boolean accepted = false;
InetSocketAddress socketAddr = new InetSocketAddress(59135);
try
{
serverSocket = new ServerSocket();
serverSocket.setReuseAddress(true);
serverSocket.setSoTimeout((int) TimeUnit.SECONDS.toMillis(SECONDS_TO_WAIT));
serverSocket.bind(socketAddr);
}
catch (IOException e)
{
Log.e(TAG, e.getMessage() + " |||| " );
}
while (!Thread.currentThread().isInterrupted())
{
Socket socket = null;
try
{
socket = serverSocket.accept();
accepted = true;
}
catch (InterruptedIOException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
Thread.currentThread().interrupt();
}
if (accepted)
{
CommunicationThread commThread = new CommunicationThread(socket);
new Thread(commThread).start();
}
accepted = false;
}
}
}
private class CommunicationThread implements Runnable
{
private Socket clientSocket;
private BufferedReader input;
public CommunicationThread(Socket clientSocket)
{
this.clientSocket = clientSocket;
try
{
this.input = new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream()));
}
catch (IOException e)
{
Log.e(TAG, e.getMessage() + " |||| " );
Thread.currentThread().interrupt();
}
}
public void run()
{
while (!Thread.currentThread().isInterrupted())
{
try
{
String read = input.readLine();
updateConversationHandler.post(new updateUIThread(read));
}
catch (IOException e)
{
Log.e(TAG, e.getMessage() + " |||| " );
Thread.currentThread().interrupt();
}
}
}
}
private class updateUIThread implements Runnable
{
private String msg;
public updateUIThread(String str)
{
this.msg = str;
}
@Override
public void run()
{
text.setText(text.getText().toString()+"Client Says: "+ msg + "\n");
}
}
}
Client.java:
Code:
package com.example.socketproject;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.http.conn.util.InetAddressUtils;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class Client extends Activity
{
private final static int SECONDS_TO_WAIT = 5;
private PrintWriter out = null;
private Socket socket = null;
private ClientThread clientThread = new ClientThread();
private String serverIp = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_client);
serverIp = MY_PHONE_IP_HERE;
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.client, menu);
return true;
}
private String getLocalIpAddress()
{
String ipAddr = null;
try
{
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
{
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
{
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress()) )
{
ipAddr = inetAddress.getHostAddress();
return ipAddr;
}
}
}
}
catch (SocketException ex)
{
Log.d(TAG, ex.toString());
}
return ipAddr;
}
public void onClick(View view)
{
try
{
ExecutorService poolExecutor = Executors.newSingleThreadExecutor();
poolExecutor.execute(clientThread);
poolExecutor.shutdown();
poolExecutor.awaitTermination(SECONDS_TO_WAIT, TimeUnit.SECONDS);
EditText et = (EditText) findViewById(R.id.editText_client);
String str = et.getText().toString();
if(out == null)
{
out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream())),
true);
}
out.println(str);
}
catch (UnknownHostException e)
{
Log.e(TAG, e.getMessage() + " |||| " + e.getStackTrace());
}
catch (IOException e)
{
Log.e(TAG, e.getMessage() + " |||| " + e.getStackTrace());
}
catch (Exception e)
{
Log.e(TAG, e.getMessage() + " |||| " + e.getStackTrace());
}
}
class ClientThread implements Runnable
{
@Override
public void run()
{
try
{
InetAddress serverAddr = InetAddress.getByName(serverIp);
socket = new Socket();
socket.connect(new InetSocketAddress(serverAddr, 59135), (int) TimeUnit.SECONDS.toMillis(SECONDS_TO_WAIT));
//socket = new Socket(serverAddr, 59135);
}
catch (UnknownHostException e)
{
Log.e(TAG, e.getMessage() + " |||| " + e.getStackTrace());
}
catch (IOException e)
{
// TODO IF HOST ISNT EXIST
Log.e(TAG, e.getMessage() + " |||| " + e.getStackTrace());
}
}
}
}
EDIT:
nevermind, it was interrupt flag which was erased and made unexpected results with threads. decided to use booleans instead.
Closed at OP's request
Related
I'm developing an application that utilizes zooming in and out (for readability) and allows for swiping left and right to change pages.
Basically the flipping back and forth part works and zoom works. However, if I do any kind of zooming and then try to change a page the program crashes.
I've only tested this on the Epic 4G and on the G2 with the same problem.
Any help that can tell me what is going on or what I need to change would be greatly appreciated. (I tried to code out on the net to fix the HTC incredible having this kind of issue but the problem is still there)
Code:
package my.package;
import java.io.IOException;
import java.io.InputStreamReader;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.SubMenu;
import android.view.View;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.View.OnTouchListener;
import android.webkit.WebView;
public class LessonShower extends Activity {
private char[] buffer = new char[128];
private WebView webView;
private int lessonNumber, lessonPage;
private AssetManager assetManager;
private int lessonsCount;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int lessonNumber = getIntent().getIntExtra("lessonNumber", 1);
int lessonPage = getIntent().getIntExtra("lessonPage", 1);
webView = new MyWebView(this);
assetManager = getAssets();
try {
lessonsCount = assetManager.list("").length - 3;
loadPage(lessonNumber, lessonPage);
} catch (IOException e) {
}
SimpleOnGestureListener gestureListener = new SimpleOnGestureListener(){
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
Log.d("debugging", "onFling");
if(Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY && e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE){
loadNextPage();
return true;
}
else if(e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE){
loadPrevPage();
return true;
}
if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE){
webView.pageDown(false);
}
else if(e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE){
webView.pageUp(false);
}
return super.onFling(e1, e2, velocityX, velocityY);
}
};
final GestureDetector gDetector = new GestureDetector(webView.getContext(), gestureListener);
webView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
return gDetector.onTouchEvent(arg1);
}
});
webView.getSettings().setBuiltInZoomControls(true);
setContentView(webView);
}
public void loadNextPage(){
int nextPage = lessonPage + 1;
try{
InputStreamReader is = new InputStreamReader(assetManager.open("lesson" + lessonNumber + "/" + nextPage + ".html"));
readPage(is);
lessonPage++;
}
catch(IOException ex){
final CharSequence[] items = {"Home", "Next lesson"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose an action");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if(item == 0){
finish();
}
else{
if(lessonNumber < lessonsCount){
lessonNumber++;
lessonPage = 1;
loadPage(lessonNumber, lessonPage);
}
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
public void loadPrevPage(){
if(lessonPage > 1){
try{
InputStreamReader is = new InputStreamReader(assetManager.open("lesson" + lessonNumber + "/" + --lessonPage + ".html"));
readPage(is);
}
catch(IOException ex){}
}
}
private void readPage(InputStreamReader is){
StringBuilder webPage = new StringBuilder();
int len = 0;
try {
while((len = is.read(buffer)) > 0){
webPage.append(buffer, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}
webView.loadData(webPage.toString(), "", "");
}
public void loadPage(int lessonNumber, int lessonPage){
if(lessonNumber > lessonsCount){
return;
}
this.lessonNumber = lessonNumber;
this.lessonPage = lessonPage;
setTitle("Lesson" + lessonNumber);
InputStreamReader is = null;
try {
is = new InputStreamReader(assetManager.open("lesson" + lessonNumber + "/" + lessonPage + ".html"));
} catch (IOException e) {
}
readPage(is);
}
private static final int homeMenuItem = 1;
private static final int exitMenuItem = 2;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(Menu.NONE, homeMenuItem, Menu.NONE, "Home");
SubMenu pagesMenu = menu.addSubMenu("Pages");
try {
int lessonPages = assetManager.list("lesson" + lessonNumber).length;
for(int i = 1; i <= lessonPages; i++)
//"+ 1000" is used to escape collision with other menu items
pagesMenu.add(Menu.NONE, i + 1000, Menu.NONE, "Page" + i);
} catch (IOException e) {}
finally{
menu.add(Menu.NONE, exitMenuItem, Menu.NONE, "Hide");
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch(item.getItemId()){
case homeMenuItem:
finish();
break;
case exitMenuItem:
moveTaskToBack(true);
break;
default:
//Page was selected
if(item.getItemId() > 1000){
lessonPage = item.getItemId() - 1000;
loadPage(lessonNumber, lessonPage);
}
}
return true;
}
}
class MyWebView extends WebView{
private LessonShower lp = null;
public MyWebView(Context context) {
super(context);
lp = (LessonShower) context;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT){
lp.loadPrevPage();
}
else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT){
lp.loadNextPage();
}
return false;
}
}
No ideas? Anyone?
Sent from my SPH-D700 using XDA App
I am building an android application to do various queries on my MySQL database. Once a successful login has returned on the main activity, I create a new Intent that holds search and query options. Here's the issue I am having. I keep getting a null pointer exception on stmt = con.createStatement(); Below is my logcat:
Code:
08-20 16:12:07.359 654-810/com.android.exchange D/ExchangeService: !!! deviceId unknown; stopping self and retrying
08-20 16:12:08.469 36-653/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
08-20 16:12:11.559 1926-1949/com.example.testapplication W/System.err: java.lang.NullPointerException
08-20 16:12:11.559 1926-1949/com.example.testapplication W/System.err: at com.example.testapplication.Networking.Search(Networking.java:44)
08-20 16:12:11.559 1926-1949/com.example.testapplication W/System.err: at com.example.testapplication.ControlActivity$1.run(ControlActivity.java:53)
08-20 16:12:11.559 1926-1949/com.example.testapplication W/System.err: at java.lang.Thread.run(Thread.java:856)
08-20 16:12:12.369 654-654/com.android.exchange D/ExchangeService: !!! EAS ExchangeService, onStartCommand, startingUp = false, running = false
08-20 16:12:12.369 278-498/system_process W/ActivityManager: Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
08-20 16:12:12.369 654-815/com.android.exchange D/ExchangeService: !!! Email application not found; stopping self
08-20 16:12:12.379 278-278/system_process W/ActivityManager: Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
I'm curious whether it is better practice to close the connection and reopen it in the new intent? Or pass the connection between intents somehow?
Any input would be greatly appreciated!
wait...
Here are snippets of my code to help debug.
Code:
[user=439709]@override[/user]
public void onClick(View view) {
if(view.getId() == R.id.LoginButton) {
Toast.makeText(getApplicationContext(), "Attempting Connection", Toast.LENGTH_SHORT).show();
//Spawn new thread
new Thread(new Runnable() {
public void run() {
if(net.execLogin(mUserInput.getText().toString(), mPassInput.getText().toString())) {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "Connected to Database", Toast.LENGTH_LONG).show();
}
});
//start new activity
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
[user=439709]@override[/user]
public void run() {
Intent intent = new Intent(LoginActivity.this, ControlActivity.class);
startActivity(intent);
}
});
}
else {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "Connection Failed :(", Toast.LENGTH_LONG).show();
}
});
}
}
}).start();
}
}
And here is the new activity started by the above code:
Code:
package com.example.testapplication;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class ControlActivity extends Activity implements View.OnClickListener {
private ArrayList<Hardware> list = new ArrayList<Hardware>();
EditText mEditText;
ListView mListView;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_control);
setupPage();
}
public void setupPage() {
Button search = (Button)findViewById(R.id.search);
search.setOnClickListener(this);
mEditText = (EditText)findViewById(R.id.editText);
mListView = (ListView)findViewById(R.id.listView);
}
[user=439709]@override[/user]
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.control, menu);
return true;
}
public void onClick(View view) {
if(view.getId() == R.id.search) {
new Thread(new Runnable() {
public void run() {
list = new Networking().Search("Type", mEditText.getText().toString());
}
}).start();
ArrayAdapter<Hardware> adapter = new ArrayAdapter<Hardware>(this, android.R.layout.simple_list_item_1, list);
adapter.notifyDataSetChanged();
mListView.setAdapter(adapter);
if(list == null) {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "0 Results Yielded :(", Toast.LENGTH_SHORT).show();
}
});
}
}
}
}
And here is the code I use to connect and query the database
Code:
import java.sql.*;
import java.util.*;
public class Networking implements DbQuery {
private static final String DRIVER = "org.mariadb.jdbc.Driver";
private static final String URL = "jdbc:mysql://146.187.16.32/Peirce";
ArrayList<Hardware> ara = new ArrayList<Hardware>();
Database db = new Database();
Hardware h1;
Connection con = null;
Statement stmt = null;
public boolean execLogin(String uName, String pWord) {
try {
Class.forName(DRIVER);
con = DriverManager.getConnection(URL, uName, pWord);
if(!con.isClosed()){
return true;
}
return false;
}catch(SQLException e) {
e.printStackTrace();
}catch(ClassNotFoundException e) {
e.printStackTrace();
}
return false;
}
public ArrayList<Hardware> Search(String arg, String target) {
try {
stmt = con.createStatement(); //throws null pointer exception
ResultSet rs = stmt.executeQuery("Select * from " + db.getTable() + " where " + arg + "='" + target + "';");
while(rs.next()) {
ara.add(new Hardware(rs.getString("Type"), rs.getString("Make"), rs.getString("Model"), rs.getString("Serial"), rs.getString("Comments")));
}
return ara;
}catch(SQLException e) {
e.printStackTrace();
}catch(NullPointerException e) {
e.printStackTrace();
}
return ara;
}
nevermind
i have figured it out.
I am working on an android application that modifies an external MySQL database. I know I can use an intermediate PHP/JSON service to do it, but I rather use JBDC because connection is faster and my project teachers want me to do it this way.
As it's my first app, I started with a simple button and an action(create a database), which actually works (in fact two buttons, the first one doesn't work on skd higher than 9, AsyncTask has to be used in them):
Code:
package com.example.prova;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.sql.*;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button1 = (Button) findViewById(R.id.btconn1);
final Button button2 = (Button) findViewById(R.id.btconn2);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try
{
String URL = "jdbc:mysql://" + "192.168.1.200" + ":" + "3306";
String USER = "app";
String PASS = "android";
Toast.makeText(getApplicationContext(),
"Conectando a servidor MySQL",
Toast.LENGTH_SHORT).show();
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(URL, USER, PASS);
Toast.makeText(getApplicationContext(),
"Conectado Servidor MySQL",
Toast.LENGTH_LONG).show();
Statement stmt = conn.createStatement();
String SQL = "CREATE DATABASE SYNC";
stmt.executeUpdate(SQL);
conn.close();
}
catch (ClassNotFoundException e)
{
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
catch (SQLException e)
{
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
});
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new LED13ON().execute();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public class LED13ON extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPostExecute(Void result){
SystemClock.sleep(2000);
}
@Override
protected void onPreExecute(){
SystemClock.sleep(2100);
}
@Override
protected void onProgressUpdate(Integer... values){
SystemClock.sleep(100);
}
@Override
protected Void doInBackground(Void... arg0){
try
{
String URL = "jdbc:mysql://" + "192.168.1.200" + ":" + "3306";
String USER = "app";
String PASS = "android";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(URL, USER, PASS);
Statement stmt = conn.createStatement();
String SQL = "CREATE DATABASE aSYNC";
stmt.executeUpdate(SQL);
conn.close();
}
catch (ClassNotFoundException e)
{
}
catch (SQLException e)
{
}
catch (Exception e)
{
}
return null;
}
}
}
The problem is when I try to use fragments, eclipse returns no errors but JDBC code is not working (logcat gives me no errors too). I know that's only the JDBC code which is not working because it gets inside the LED13ON and makes the SystemClock.sleep(2000), because the button is marked for two seconds. This is the code I have for the fragment in a new class:
Code:
package com.example.smarthome;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Locale;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class Fragment_main extends Fragment {
public Fragment_main() {
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main,container, false);
Button btn = (Button) rootView.findViewById(R.id.btconn1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v) {
new LED13ON().execute();
}
});
return rootView;
}
public class LED13ON extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPostExecute(Void result){
SystemClock.sleep(2000);
}
@Override
protected void onPreExecute(){
SystemClock.sleep(2100);
}
@Override
protected void onProgressUpdate(Integer... values){
SystemClock.sleep(100);
}
@Override
protected Void doInBackground(Void... arg0){
try
{
String URL = "jdbc:mysql://" + "192.168.1.200" + ":" + "3306";
String USER = "app";
String PASS = "android";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(URL, USER, PASS);
Statement stmt = conn.createStatement();
String SQL = "CREATE DATABASE aSYNC";
stmt.executeUpdate(SQL);
conn.close();
}
catch (ClassNotFoundException e)
{
}
catch (SQLException e)
{
}
catch (Exception e)
{
}
return null;
}
}
}
So I don't understand why being the same code it's not working for the second app, having changed the setOnClickListener to work in the fragment. Can anyone help me? I would really like to use the swipe views for my app as I think it fits more the android Holo style.
Thank you for your time!
EDIT:
I found the solution to my problem:
I logged the exceptions, it gave me the error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Click to expand...
Click to collapse
The solution was to add newInstance in the Class.forName:
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Click to expand...
Click to collapse
So that's all, now my app is working as I intended. Thanks for everything!
I have the code below created but I can not for the life of me figure out how I can send data from the accelerator. I need it to send a constant stream of data until I turn it off. I can't even figure out how to cast the data to a proper variable. Any suggestion would be greatly appreciated.
Code:
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.UUID;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements SensorEventListener
{
private static final String TAG = "bluetooth1";
Sensor accelerometer;
SensorManager sm;
TextView acceleration;
Button on, off;
float values;
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uuid = tManager.getDeviceId();
private BluetoothAdapter btAdapter = null;
private BluetoothSocket btSocket = null;
private OutputStream outStream = null;
// SPP UUID service
private UUID MY_UUID = UUID
.fromString(uuid);
// MAC-address of Bluetooth module (you must edit this line)
private static String address = "B0:C4:E7:CF:19:6E";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sm = (SensorManager) getSystemService(SENSOR_SERVICE);
accelerometer = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sm.registerListener(this, accelerometer,
SensorManager.SENSOR_DELAY_NORMAL);
acceleration = (TextView) findViewById(R.id.accelText);
off = (Button) findViewById(R.id.bOff);
on = (Button) findViewById(R.id.bOn);
btAdapter = BluetoothAdapter.getDefaultAdapter();
checkBTState();
// On click Listeners
off.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
sendData("a");
Toast.makeText(getBaseContext(), "Turn on LED",
Toast.LENGTH_SHORT).show();
}
});
on.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
sendData("a");
Toast.makeText(getBaseContext(), "Turn on LED",
Toast.LENGTH_SHORT).show();
}
});
// End Onclick Listeners
private BluetoothSocket createBluetoothSocket(BluetoothDevice device)
throws IOException
{
if (Build.VERSION.SDK_INT >= 10)
{
try
{
final Method m = device.getClass().getMethod(
"createInsecureRfcommSocketToServiceRecord",
new Class[] { UUID.class });
return (BluetoothSocket) m.invoke(device, MY_UUID);
} catch (Exception e)
{
Log.e(TAG, "Could not create Insecure RFComm Connection", e);
}
}
return device.createRfcommSocketToServiceRecord(MY_UUID);
}
@Override
public void onResume()
{
super.onResume();
Log.d(TAG, "...onResume - try connect...");
// Set up a pointer to the remote node using it's address.
BluetoothDevice device = btAdapter.getRemoteDevice(address);
// Two things are needed to make a connection:
// A MAC address, which we got above.
// A Service ID or UUID. In this case we are using the
// UUID for SPP.
try
{
btSocket = createBluetoothSocket(device);
} catch (IOException e1)
{
errorExit("Fatal Error", "In onResume() and socket create failed: "
+ e1.getMessage() + ".");
}
// Discovery is resource intensive. Make sure it isn't going on
// when you attempt to connect and pass your message.
btAdapter.cancelDiscovery();
// Establish the connection. This will block until it connects.
Log.d(TAG, "...Connecting...");
try
{
btSocket.connect();
Log.d(TAG, "...Connection ok...");
} catch (IOException e)
{
try
{
btSocket.close();
} catch (IOException e2)
{
errorExit("Fatal Error",
"In onResume() and unable to close socket during connection failure"
+ e2.getMessage() + ".");
}
}
// Create a data stream so we can talk to server.
Log.d(TAG, "...Create Socket...");
try
{
outStream = btSocket.getOutputStream();
} catch (IOException e)
{
errorExit(
"Fatal Error",
"In onResume() and output stream creation failed:"
+ e.getMessage() + ".");
}
}
@Override
public void onPause()
{
super.onPause();
Log.d(TAG, "...In onPause()...");
if (outStream != null)
{
try
{
outStream.flush();
} catch (IOException e)
{
errorExit(
"Fatal Error",
"In onPause() and failed to flush output stream: "
+ e.getMessage() + ".");
}
}
try
{
btSocket.close();
} catch (IOException e2)
{
errorExit("Fatal Error", "In onPause() and failed to close socket."
+ e2.getMessage() + ".");
}
}
private void checkBTState()
{
// Check for Bluetooth support and then check to make sure it is turned
// on
// Emulator doesn't support Bluetooth and will return null
if (btAdapter == null)
{
errorExit("Fatal Error", "Bluetooth not supported");
} else
{
if (btAdapter.isEnabled())
{
Log.d(TAG, "...Bluetooth ON...");
} else
{
// Prompt user to turn on Bluetooth
Intent enableBtIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, 1);
}
}
}
private void errorExit(String title, String message)
{
Toast.makeText(getBaseContext(), title + " - " + message,
Toast.LENGTH_LONG).show();
finish();
}
private void sendData(String message)
{
byte[] msgBuffer = message.getBytes();
Log.d(TAG, "...Send data: " + message + "...");
try
{
outStream.write(msgBuffer);
} catch (IOException e)
{
String msg = "In onResume() and an exception occurred during write: "
+ e.getMessage();
if (address.equals("00:00:00:00:00:00"))
msg = msg
+ ".\n\nUpdate your server address from 00:00:00:00:00:00 to the correct address on line 35 in the java code";
msg = msg + ".\n\nCheck that the SPP UUID: " + MY_UUID.toString()
+ " exists on server.\n\n";
errorExit("Fatal Error", msg);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy)
{
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent event)
{
// TODO Auto-generated method stub
acceleration.setText("x: " + event.values[0] + "\nY:" + event.values[1]
+ "\nZ:" + event.values[2]);
}
}
NoiseAgent said:
I can not for the life of me figure out how I can send data from the accelerator.
Click to expand...
Click to collapse
What's your exact problem? You're getting the data from the accelerator in the onSensorChanged()-Method, so you just need to send them there.
Reply
EmptinessFiller said:
What's your exact problem? You're getting the data from the accelerator in the onSensorChanged()-Method, so you just need to send them there.
Click to expand...
Click to collapse
My problem is I am unsure how to send it. How do you actually do that? I don't know what the syntax is to transmit data over bluetooth. The sendData wont work it gives me the error sendData(String) in the type MainActivity is not applicable for the arguments(Sensor)
Use DataOutputStream and DataInputStream to send/read the three float-values: DataOutputStream#writeFloat(event.values[0/1/2]);
EmptinessFiller said:
Use DataOutputStream and DataInputStream to send/read the three float-values: DataOutputStream#writeFloat(event.values[0/1/2]);
Click to expand...
Click to collapse
Sweet baby jesus, lord all mighty, thank you.
When I add that to the onSensorChanged I get the error "Cannot make a static reference to the non-static method writeFloat(float) from
the type DataOutputStream" not sure how to clear it up.
Also, I have jumped in way over my head, I really just want to wrap this last bit up and start from scratch. If anyone has a good resource for learning object oriented Java programming and would like to share, that would just be the bees-knees.
Of course java/object oriented programming is necessary.
You have to create an object from the ObjectOutputStream like
ObjectOutputStream oos = new ObjectOutputStream(...);
oos.writeFloat(...);
...
Hello everyone.
I am trying to load the Images in an listview that the RSS provides me.
http://www.nutech.nl/rss is the rss i use.
i want to load the image in listview from these tags
<enclosure> </enclosure (
Code:
<enclosure url="http://media.nu.nl/m/m1nx89taa599_sqr256.jpg" length="None" type="image/jpeg"></enclosure>
)
Now i have tried several things i found on google but none worked or werent explaining enough.
Here is some of my main Codes
RSSreader.java
Code:
package com.thedutch.technews;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import android.os.StrictMode;
public class RSSReader {
DefaultHttpClient httpClient = new DefaultHttpClient();
public Document getRSSFromServer(String url) {
Document response = null;
response = getDomFromXMLString(getFeedFromServer(url));
return response;
}
private String getFeedFromServer(String url) {
String xml = null;
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
try {
HttpGet httpget =new HttpGet(url);
//HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpget);
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (Exception e) {
e.printStackTrace();
}
return xml;
}
private Document getDomFromXMLString(String xml) {
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (Exception e) {
}
return doc;
}
public String getValue(Element item, String key) {
NodeList nodeList = item.getElementsByTagName(key);
return this.getElementValue(nodeList.item(0));
}
public final String getElementValue(Node node) {
Node child;
if (node != null) {
if (node.hasChildNodes()) {
for (child = node.getFirstChild(); child != null; child = child
.getNextSibling()) {
if (child.getNodeType() == Node.TEXT_NODE) {
return child.getNodeValue();
}
}
}
}
return "";
}
}
Nutech.java
Code:
package com.thedutch.technews;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import com.faizmalkani.floatingactionbutton.FloatingActionButton;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class Nutech extends Fragment implements OnClickListener{
String key_items = "item";
String key_title = "title";
String key_description = "description";
String key_link = "link";
String key_date = "pubDate";
ListView lstPost = null;
List<HashMap<String, Object>> post_lists = new ArrayList<HashMap<String, Object>>();
List<String> lists = new ArrayList<String>();
ArrayAdapter<String> adapter23 = null;
RSSReader rssfeed = new RSSReader();
FloatingActionButton mFab;
public static Fragment newInstance(Context context) {
Nutech f = new Nutech();
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(
R.layout.activity_main4, container, false);
((MainActivity) getActivity())
.setActionBarTitle("Nutech");
mFab = (FloatingActionButton) view.findViewById(R.id.fabbutton);
mFab.setOnClickListener(this);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Appstatus.getInstance(getActivity()).isOnline()) {
lstPost = (ListView) getView().findViewById(R.id.lstPosts);
mFab = (FloatingActionButton) getView().findViewById(R.id.fabbutton);
mFab.listenTo(lstPost);
adapter23 = new ArrayAdapter<String>(getActivity(),
R.layout.feed_list_item, R.id.title, lists) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView txt1 = (TextView) view
.findViewById(R.id.title);
TextView txt2 = (TextView) view
.findViewById(R.id.desc);
TextView txt3 = (TextView) view
.findViewById(R.id.date);
HashMap<String, Object> data = post_lists.get(position);
txt1.setText(data.get(key_title).toString());
txt2.setText(data.get(key_description).toString());
txt3.setText(data.get(key_date).toString());
return view;
}
};
Document xmlFeed = rssfeed
.getRSSFromServer("http://www.nutech.nl/rss");
NodeList nodes = xmlFeed.getElementsByTagName("item");
for (int i = 0; i < nodes.getLength(); i++) {
Element item = (Element) nodes.item(i);
HashMap<String, Object> feed = new HashMap<String, Object>();
feed.put(key_title, rssfeed.getValue(item, key_title));
feed.put(key_description, rssfeed.getValue(item, key_description));
feed.put(key_link, rssfeed.getValue(item, key_link));
feed.put(key_date, rssfeed.getValue(item, key_date));
post_lists.add(feed);
lists.add(feed.get(key_title).toString());
}
lstPost.setAdapter(adapter23);
lstPost.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
if (Appstatus.getInstance(getActivity()).isOnline()) {
Document xmlFeed = rssfeed
.getRSSFromServer("http://www.nutech.nl/rss");
NodeList nodes = xmlFeed.getElementsByTagName("item");
Element item = (Element) nodes.item(position);
Intent indisplay = new Intent(getActivity(),PostViewActivity.class);
indisplay.putExtra("link", rssfeed.getValue(item, key_link));
startActivity(indisplay);
} else {
getActivity().setContentView(R.layout.activity_main3);
Thread background = new Thread() {
public void run() {
try {
sleep(5*1100);
getActivity().finish();
} catch (Exception e) {
}
}
};
background.start();
}
}
});
lstPost.setLongClickable(true);
lstPost.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int position, long id) {
if (Appstatus.getInstance(getActivity()).isOnline()) {
Document xmlFeed = rssfeed
.getRSSFromServer("http://www.nutech.nl/rss");
NodeList nodes = xmlFeed.getElementsByTagName("item");
Element item = (Element) nodes.item(position);
final Intent wintent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(rssfeed.getValue(item, key_link)));
startActivity(wintent);
return true;
} else {
getActivity().setContentView(R.layout.activity_main3);
Thread background = new Thread() {
public void run() {
try {
sleep(5*1100);
getActivity().finish();
} catch (Exception e) {
}
}
};
background.start();
}
return true;
}
});
} else {
getActivity().setContentView(R.layout.activity_main3);
Thread background = new Thread() {
public void run() {
try {
sleep(5*1100);
getActivity().finish();
} catch (Exception e) {
}
}
};
background.start();
}
}
public void fabClicked(View view) {
adapter23.notifyDataSetChanged();
}
@Override
public void onClick(View v) {
adapter23.notifyDataSetChanged();
this.adapter23.notifyDataSetChanged();
lstPost.invalidateViews();
lstPost.refreshDrawableState();
Toast.makeText(this.getActivity(),
"Refreshed Nutech News!", Toast.LENGTH_LONG).show();
}
public void hideFab(View view) {
mFab.hide(true);
//getActionBar().hide();
}
public void showFab(View view) {
mFab.hide(false);
//getActionBar().show();
}
}
MainActivity.java
Code:
package com.thedutch.technews;
import java.util.ArrayList;
import com.google.analytics.tracking.android.EasyTracker;
import com.google.analytics.tracking.android.MapBuilder;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private EasyTracker easyTracker = null;
private Toolbar mToolbar;
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private ListView mDrawerList;
private ArrayList<ListMenuModel> mListMenu;
private ListMenuAdapter mListMenuAdapter;
final String[] data ={"Nutech","Tweakers","Hardware Info"};
final String[] fragmentos ={
"com.thedutch.technews.Nutech",
"com.thedutch.technews.Tweakers",
"com.thedutch.technews.Hardwareinfo"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
easyTracker = EasyTracker.getInstance(MainActivity.this);
mToolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(mToolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mListMenu = new ArrayList<ListMenuModel>();
mListMenu.add(new ListMenuModel("Nutech", "Nutech", R.drawable.ic_nu));
mListMenu.add(new ListMenuModel("Tweakers", "Tweakers", R.drawable.ic_tweakers));
mListMenu.add(new ListMenuModel("Hardware Info", "Hardware Info", R.drawable.ic_hardwareinfo));
mListMenuAdapter = new ListMenuAdapter(getApplicationContext(),
mListMenu);
mDrawerList.setAdapter(mListMenuAdapter);
mDrawerList.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, final int pos,long id){
mDrawerToggle.syncState();
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.content_frame, Fragment.instantiate(MainActivity.this, fragmentos[pos]));
tx.commit();
mDrawerList.setSelection(pos);
easyTracker.send(MapBuilder.createEvent("Nav Drawer",
"Opened Navigation Drawer", "Navigation Drawer", null).build());
mDrawerLayout.closeDrawer(mDrawerList);
}
});
FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
tx.replace(R.id.content_frame,Fragment.instantiate(MainActivity.this, fragmentos[0]));
tx.commit();
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
mToolbar,
R.string.drawer_open,
R.string.drawer_close){
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
syncState();
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
mToolbar.setClickable(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.about:
Intent intent = new Intent(this, AboutActivity.class);
this.startActivity(intent);
easyTracker.send(MapBuilder.createEvent("AboutActivity",
"Entered About Page", "about", null).build());
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
public void setActionBarTitle(String title) {
getSupportActionBar().setTitle(title);
}
@Override
public void onBackPressed() {
if(mDrawerLayout.isDrawerOpen(Gravity.START|Gravity.LEFT)){
mDrawerLayout.closeDrawers();
return;
}
super.onBackPressed();
}
public void fabClicked(View view) {
Toast.makeText(this, "Refreshed.", Toast.LENGTH_LONG).show();
}
@Override
public void onStart() {
super.onStart();
EasyTracker.getInstance(this).activityStart(this);
}
@Override
public void onStop() {
super.onStop();
EasyTracker.getInstance(this).activityStop(this);
}
}
is there someone who could help me ?
thank you
After few months i still havent found a solution or idea.
anyone here has ?
Use a RSS parsing library
Use my AndroidWithoutStupid Java library. It is on GitHub. There is also an article about the usage on CodeProject.
Enclosure tag is usually used for mp3 files but it doesn't matter.
After getting the enclosure value using the MvNewsFeed class, you need to download it. Use MvAsyncDownload for that. Then, use BitmapFactory.decodeFile() or a similar method to display the image in an ImageView.
SpaceCaker said:
After few months i still havent found a solution or idea.
anyone here has ?
Click to expand...
Click to collapse