Wednesday, May 1, 2013

[android help] Is there a way to programmatically discover specifics about an Android device's GPU?

Is there a way to programmatically discover specifics about an Android device's GPU? - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I have searched the internet including developer.android.com. I have read this Stack Overflow post: how to query android device hardware info. I am aware of System.getProperties().


My question is: is there a way to programmatically discover specific information about the GPU on a particular Android device? Is it at least possible to get the make and model of the GPU on a device?


Or, should I just use the MANUFACTURER and MODEL fields of the Build class to infer the GPU that is used on that particluar device?


My ends in regard to this question is to find a way to identify the graphics processing capability of devices that my apps run on so that I can adjust the graphics processing demands of my apps accordingly.


Thanks, Chris





























You can use glGetString() with GL_VENDOR to determine the GPU vendor name and GL_RENDERER to determine the GPU name.


Check out the documentation























default






.

stackoverflow.comm

[android help] SDK Manager does not pop up when clicked


im having a problem with my SDK Manager its doesnt pop up when i click the icon of the window.i have downloaded the file for the 2nd time but it still doesnt pop up,i followed the instructions in here After Installing ADT Plugin, Welcome to Android Development Doesnt Appear as well i must have missed something but all is well im just missing google com.google.android.gms. and for that i cant continue with my project.how can i fix this mess.



.

stackoverflow.comm

[android help] Finding the nearest bus stations

android - Finding the nearest bus stations - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I'm just beginning to build an Android app that leverages the NextBus API to provide transit predictions.


When the app loads, I want it to get the user's location and then find the closest bus stops to them. Unfortnuately, the NextBus API doesn't provide a method for doing so. I do have a list of all bus stops (there are 5600 of them) in a text file, each with its textual name, numerical Stop ID and its latitude and longitude.


I'm considering several options, each with its own problems:



  1. Make a call the Google Places API to get all stops within (say) a mile of the user. The problem with this method is that Google returns only the name of the stop in text form, and the NextBus API requires the numerical Stop ID. So, I could create a map with the textual names as the keys and the numerical Stop ID's as the values (or, more probably, load them all into a MySQL database).




  2. Store the text file itself as a resource (perhaps converting it to XML or some other format that's easier to search), and compare the GPS locations of all 5600 stops to the user's current location. This solution seems utterly untenable, as it would be prohibitively expensive. However, perhaps I'm overestimating its cost?




  3. I also have the bus stop data in the form of KML (Google Earth) and GIS files, but I have never interacted with either of these two formats. Is there a way I could use them to locate the closest stops more efficiently than the previous two solutions?




















Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.










default






.

stackoverflow.comm

[android help] How would I figure out which friends of a user is also using my app?

android - How would I figure out which friends of a user is also using my app? - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I´m building a webapp+android app and thought it would be useful if I could show "UserA" which of his friends that also use the service.


User authentication is done through google oath2 so I have access to the email of all users.


What I´m wondering is how I would structure such a query? Since what I basically have is


  • Users possibly huge list of people UserA:(userB@gmail.com, user..)

  • The users in my database (userA@gmail.com, userB@gmail.com, ..)

  • Whether the "friendship" is reciprocal or not UserB:(userA@gmail.com, user..) || (UserC@gmail.com, user..)

I would prefer not to have a "are we friends yes/no" system and looping through a users entire contactlist seems very wasteful. The backend runs on php+mysql.


How would I actually query for the list of people I´m interested in?





























There is a known feature request for an API call that can do this. If you'd like to track this progress of this API call, you can star the following issues to get email updates on it. https://code.google.com/p/google-plus-platform/issues/detail?id=531























default






.

stackoverflow.comm

[android help] (Android) ANTLRStringStream throwing exception


I've been trying to get ANTLR-3.5-complete.jar to work on an Android app, but I can't get it to work! Bart Kiers's answer HERE has helped me a lot, but I still can't get it to work.


I'm trying to make a Button that, when clicked, will validate whether the text in the EditText view is correct according to my grammar.g, but it doesn't matter whether the text I input is correct or not, my app always crashes when I click the button while instantiating the ANTLRStringStream. Here's what I have:



public void onClickVerify(View v) throws TypeNotPresentException {
String source = "foobar";
Log.e("TestDebug", "Instantiating views");
TextView out = (TextView) findViewById(R.id.textView1);
EditText in = (EditText) findViewById(R.id.editText1);
try {
Log.e("TestDebug", "Getting source from EditText");
source = in.getText().toString();
Log.e("TestDebug", "source = " + source);
Log.e("TestDebug", "Instantiating stream");
ANTLRStringStream stream = new ANTLRStringStream(source);
Log.e("TestDebug", "Instantiating lexer");
grammarLexer lexer = new grammarLexer(stream);
Log.e("TestDebug", "Instantiating parser");
grammarParser parser = new grammarParser(
new BufferedTokenStream(lexer));
Log.e("TestDebug", "Applying rule to parser");
out.setText(source + " = " + !parser.failed());
} catch (IllegalStateException ise) {
out.setText("Exception caught");
}
}


And here's what I see in the logs:


  • Instantiating views

  • Getting source from EditText

  • source = test33

  • Instantiating stream

And then the "Unfortunately, TestAntlrApp has stopped." window pops up.


EDIT: Here's more of my logcat.



java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3591)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3586)
... 11 more
Caused by: java.lang.NoClassDefFoundError: org.antlr.runtime.ANTLRStringStream
at com.test.antlr.MainActivity.onClickVerify(MainActivity.java:89)


Something about not finding the class ANTLRStringStream class? However there seems to be no errors/warnings in the code and I can even see the class's hierarchy.



.

stackoverflow.comm

[android help] Android - TextView not showing


I have a TextView that used to show on the screen, and did what I wanted. However, I streamlined some later code that repositions it with a touch to it's parent FrameLayout. Now, the TextView (named angleView) ceases to show on screen, but when I print out it's coordinates, it still works the same way. Can anyone see what I'm doing wrong?


Here is the code from my onCreate() method:



angleView = new TextView(getApplicationContext());
angleView.setTextColor(Color.RED);
angleView.setText("0");
angleView.setLayoutParams(new FrameLayout.LayoutParams(SCREEN_WIDTH/20, SCREEN_HEIGHT/20));


and the code from the FrameLayout's onTouchListener:



preview.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
float y = (centerPoint.getY() - event.getY() + STATUS_BAR_HEIGHT);
float x = (centerPoint.getX() - event.getX());
double angle = Math.atan(y/x);
setAngleFieldData(event, angle, y, x);
setFingerFollower(event, angle);
setYMeasure(event, y);
setXMeasure(event, x);
setTextPositions(event, angle, y, x);
Log.i("angleX", String.valueOf(angleView.getX()));
Log.i("angleY", String.valueOf(angleView.getY()));
return true;
}

private void setAngleFieldData(MotionEvent event, double angle, float y, float x){
angleView.setText(String.valueOf(angle));
angleView.setX(event.getX());
angleView.setY(event.getY());
if(isRadians) {
if(x < 0 && y >= 0){
angleView.setText(String.valueOf(2 * Math.PI + angle));
}
}

}


(the other methods are irrelevant, it used to be that all the code from the individual methods was in the onTouch.)


And in case you are wondering, yes, there is a:



preview.addView(angleView);


Many thanks!



.

stackoverflow.comm

[android help] How to fix: Error device not found with ADB.exe

android - How to fix: Error device not found with ADB.exe - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















In cmd when I try to do the command:


adb shell


it shows device not found error. Can someone help me please. It'll be appreciated.


























It depends on windows system but usually:


  1. you go to system properties

  2. look at hardware devices

  3. Right click on the yellow (has to be yellow if it's driver problem) icon representing your mobile device

  4. select property

  5. Then go on the driver tab

  6. select update driver

  7. choose the bottom selection find on local computer

  8. then choose manually

  9. From the windows opened look for driver disk the bottom right button

  10. Choose the driver from the folder \extras\google\usb_driver\i386 (or amd64 for and).

  11. Remember to uncheck the show only compatible hardware.

  12. Then choose the driver

  13. When windows warn your about possible incompatibility go on.

For my mobile it works, but depend on your mobile if it work or not.


Hope this help, bye.


























If you installed Eclipse have Android SDK, go to DDMS. If the list device display "?????????"


you do adb kill-server and then adb start-server.


Please make sure you install USB driver and enable debug mode.






















I had this problem suddenly crop up in Windows 7 with my Nexus One - somehow the USB drivers had been uninstalled. I ran android-sdk/SDK Manager.exe, checked Extras/Google USB Driver and installed it. Then I unplugged the phone and plugged it back in, and ran "adb devices" to confirm the phone was attached.


This doesn't work for all phones, just the ones listed here: http://developer.android.com/sdk/win-usb.html






















I have a Droid 3 (Verizon). I went to Motorola here and found the driver for the device 'Motorola ADB Interface' which was showing in device manager. It's kind of a big download for just the driver, but during installation it found it and installed correctly.






















Don't forget to go to your device and enable Settings->Developer Options->USB debugging.























default






.

stackoverflow.comm

[android help] creating files with IF logic inbeded


Actually two questions:


The main question: I hope it isn't true that you can't have simple logic in writing out a file!!! I have a cursor to load a dynamic list on the screen normally invoked by onCreate. That works. Now, I need to write out to the "sdCard" as a back-up. (If my watch decides to reset to day one, I will reload - it also allows me to add entries from my PC which has a keyboard.)


I decided the best way is to call the existing cursor but set a switch to indicate to write it out. Files require a try - catch, so I put it around the open, the write, and the close. The "writers" are undefined. So I put it all inside one "TRY" that worked if there are no brackets - no "IF"s.


But add "IF (--SWITCH SET)" {---writer.write(strBuRec); ..}" which requires {--} now again the writer is undefined.


I sure hope I am doing something else wrong (probably something stupid)! I can copy the code into a second cursor, but prefer not to.


Second question: Note the close cursor (//cursor.close();) is commented out. This is because if I repaint the screen or in this case, re-invoke the cursor to write out my file, I get cursor closed. I can only load the cursor once if I close it.


Note: This is a simple app for my WIMMOne so it needs version 7. This code is in a fragment, (bad decision, but it's there).


Many thanks, Clark



@Override
public void onLoadFinished(Loader loader, Cursor cursor)
{
Log.d("EventLst","0 LoadFin");
int iRecNo = 0;
iBuCnt = 0;
mAdapter.swapCursor(cursor);

//----------------------------------------
// if exporting, open the file

try
{
if (strRunBu == "Y")
{
FileWriter writer;
String path = Environment.getExternalStorageDirectory().getAbsoluteFile() + "/Event";
File dir = new File(path);
Log.d("Eventfile","00 File:" + dir);
File flEvent = new File(dir, "EVENT.TXT");
boolean canIWrite = dir.canWrite();

Log.d("Eventfile","0 File:" + flEvent + "=" + canIWrite);
flEvent.createNewFile();
Log.d("Eventfile","1 File:" + flEvent);
writer = new FileWriter(flEvent);
}

// ------------------------------------------
// Insert dummy first record to serve as a label
//
String strBuRec = "";
strRecord.clear();
strRecord.add(0, "mm-dd-yy: Event name");
cursor.moveToFirst();

Log.d("EventLst","1 LoadFin DO");
// ----------------------------------------
// Read from cursor and add each record to list
while (cursor.isAfterLast() == false)
{
iRecNo = iRecNo + 1;
// - Table has 4 columns, read them into string array: strC
String strC[] = { (cursor.getString(0)), (cursor.getString(1)),
(cursor.getString(2)), (cursor.getString(3))
};
// - The fourth column is the date/time in milliseconds since
// January 1,1970
// convert to date in yyyy-mm-dd format
String strDateMil = (cursor.getString(3));
long lgDate = cursor.getLong(3);
Log.d("EventLst","4 LoadCSR:" + "I:" + iRecNo + "Ld:" + lgDate);
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yy");
String strDate = dateFormat.format(new Date(lgDate));

// - Concatenate date and event into one string, add to table
strRecord.add(iRecNo, strDate + ": " + strC[2]);

// - save record number for each event in strRecId
// - Records are sorted by date, so we need to save RowId to pass
// - to edit screen
strRecId.add((cursor.getString(0)));

//---------------------------
// if-creating export file, write a record
if (strRunBu == "Y")
{
dateFormat = new SimpleDateFormat("HH:mm");
String strTime = dateFormat.format(new Date(lgDate));

strBuRec = ( (cursor.getString(1)) + "," + (cursor.getString(2))
+ "," + strDate + "," + strTime + "\r\n" );
Log.d("EventLst","4 LoadCSR:" + "BU:" + strBuRec);

// ERROR: writer cannot be resolved ??????????
writer.write(strBuRec);
Log.d("Eventfile","4 File:" + "wrote");
}

strEventRec.add(iBuCnt, strBuRec);
iBuCnt = iBuCnt + 1;

cursor.moveToNext();
} // ----end of while loop
//------------------------------------
// COULD NOT CLOSE THE CURSOR?????
//cursor.close();
//------------------------------------
if (strRunBu == "Y")
{
// ERROR: writer cannot be resolved ???????????
writer.flush();
// ERROR: writer cannot be resolved ???????????
writer.close();
};
} //---> BACKTO try
catch (IOException e)
{
Toast.makeText(getActivity(), "Close ER"+ e,
Toast.LENGTH_SHORT).show();
}
Log.d("Eventfile","4 File:" + "Closed");
strRunBu = "N";

lstAdapter = new ArrayAdapter(getActivity(),
R.layout.event_row, R.id.text1, strRecord);

// * Call to SetListAdapter()informs ListFragment how to fill ListView
// * here use ArrayAdapter
setListAdapter(lstAdapter);
// Log.d("EventLst","8 LoadCSR:" + "ALLDONE");

}


.

stackoverflow.comm

[General] help with google voice


i know the basics of GV, but I would like some help with more advanced feature(s) of GV. I have a verizion phone (moto razr hd) and a just signed on with t-mobile (galaxy s4). (both services are active). i'd like to make sure that i don't miss any phone calls, but i don't want to carry both phones. so, i'd like to forward ALL calls coming to my verizon phone to my t-mobile phone or to my google voice number (prefered).

any help would be greatly appreciated.

-Lucas



.

forum.xda-developers.com

[General] Location-based Customer database


I am a field technician and service over 300 clients across the Midwest. I am trying to find an app that will allow to me to record each customers history and attach it to their location. For example, I can create a file/folder(or equivalent entry) for each customer including contact/location info, work performed, outstanding issues. Then the next time I'm near their location, the app will provide the customer history preferably by alert/notification. I can then click on the entry and see the history of this customer. Bonus features could include search, attach photos, integration with Google maps, etc.

I'm sure I can accomplish this with Tasker, but I'm looking for a more simplified approach.

Thanks in advance for any suggestions.
Gadgetjedi



.

forum.xda-developers.com

[General] unlocked phones


i purchased an unlocked htc phone that is unlocked. i inserted my active straight talk sim card in th phone and it works. however straight talk says i should purchase a sim kit for unlocked phones or it wouldnt work. well it does and my question is will it burn up sim or damage phone to continue using what works? i would purchase th sim for unlocked phones but they r only offering tmobile sim kits as they call them. and tmobile reception is bad here... i gess my question is if it aint broke dont fix it? or will i have problems by simply using my active sim for my old phone in my new one? thanks for any help!



.

forum.xda-developers.com

[General] Undo Typing?


Is it not possible to Undo Typing in Andriod? I cannot tell you how many times I used the auto spell checker to correct a word and it wiped-out an entire sentence instead of the word I was typing and I wanted to through my phone on the floor in frustration! At the very least, there SHOULD be an undo feature ... somewhere!!!

Can somebody tell me where it is or how to implement it?



.

forum.xda-developers.com

[General] Battery issue


Hey guys, I have a samsung s3 international version, I had to get my phone replaced due to the sudden death syndrome, and I've had my new s3 which is my second s3 for about a month, everything was working fine until last week, I placed it on charge and the only way I can charge it is if I turn off, if I leave it on when its on charge it doesn't charge at all, or it'll say its at 100% and unplug the charger and it drops down to 50 %. I turned it off monday night to charge and it was asleep for about 8 hours and it generally takes my phone about 3 hours to charge I turned it on this morning and it was at 64%, I'm just wondering if you guys have any idea about what I can do to fix this?



.

forum.xda-developers.com

[android help] Android Contact Picking Uri


I have a string content//com.android.contacts/contacts/contacts/2 ie aft the user has selected a particular number.


From this string, how do i get the phone number of this particular contact?


I am new to android environment, so my question might seem a bit primitive.



Cursor c = (Cursor)mAdapter.getItem(a.keyAt(i));
Long id = c.getLong(c.getColumnIndex(ContactsContract.Contacts._ID));
contacts.add(ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id));

chosenContacts = sb.toString();


chosenContacts is my string and that contains content//com.android.contacts/contacts/contacts/2



.

stackoverflow.comm

[android help] onSizeChanged() calls onCreate() and onStart()? - Android


My app currently calls a method in the onCreate() method so that the game will start and animations will run once the view is created. However when i flip the screen to switch between portrait and landscape, this method is called again.


I've moved the calling line both to the onStart() method and even the methods class constructor.


this is the method that is being called:



public void startGame() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {

public void run() {
runGame();
}
}, 500);
}


There is a delay to allow everything to be constructed before it is run, otherwise it won't work.


Is there i way to stop onSizeChanged() affecting this method being called? Or is there a way i can call this method so that it starts when the activity is started (again so that onSizeChanged() cant affect it and that everything is initialized before its call).


Thanks for looking.



.

stackoverflow.comm

[android help] Can HTML5 access native components


I have a question. Can an HTML5 page interact with native components in android?


What i am trying to achieve is that on a HTML5 page that displays a list of content. i want to create a notification that some content has arrived.?


Im guessing, a way to do this is to use a webview and display my HTML5 content there but how to do get callback from the webview so that i can notify a user that some content has arrived via notifications bar that can be access using native android coding?


I already know how to create notifications on android and how to create a webview, i just need to find a way to send data from html5 page to a android component and possibly vice versa.


Can this be achievable or too ambitious?



.

stackoverflow.comm

[General] Superuser problem, please help!


Hello guys,
Well my problem is that after I get my Galaxy s3 I did the software update to jelly bean 4.1.1 after that I was searching for apps fyou know as its my first Android device, I found that you can buy everything for free, you just need to download superuser, so I did that I downloaded it, after that It didn't work it just keeps failing to get root access, so I ignored it as no big deal.
And now after a while I saw that there's no notifications for new software updates.
So I entered my settings and I found it modified

Is there anyway that I can delete the superuser without root access.
And what should I do to get updates.
Sorry for my bad English, thank u!



.

forum.xda-developers.com

[android help] NoClassDefFoundError after refactoring name


I am using the Eclipse IDE to create an Android application compliant with Android 2.2 and higher. I refactored the name of one of my main activities. My basic structure is that I have a pseudo home page activity in which other "apps" (actually activities) inside this one app have icons that lead to their respective activity. I had a class that was originally the head activity for one of these branches in the app, call it Activity.java. Activity.java ended up just pointing to Activity_Home.java and no longer did anything so I decided to get rid of it. I deleted Activity.java, rebuilt, then refactored Activity_Home.java to Activity.java, rebuilt. Got a NoClassDefFoundError:



05-01 10:13:12.609: E/AndroidRuntime(15635): FATAL EXCEPTION: main
05-01 10:13:12.609: E/AndroidRuntime(15635): java.lang.NoClassDefFoundError: Activity.java


so then I renamed it back to Activity_Home.java after fiddling for a bit thinking that might help something. Completely cleaning and rebuilding before every attempt to launch. Kept getting the error even though I checked the CLASSPATH and that the .class file was being named correctly. Eventually I read that someone, though they don't know why this worked, fixed a similar problem by deleting and remaking the file. I did that.


That seems to have worked, but I don't know why and now every file deeper then Activity_Home.java (eg. there is an activity called by it Activity_Camera.java) is having the same issue.


I obviously do not want to have to delete and remake all of the .java files and even if that fixes the issue I would still like to know WHY this is happening not just HOW TO FIX it.



.

stackoverflow.comm

[android help] Android NFC project - Several Questions


By now I'm developing some physical control access system based on NFC technology. I'm using NFC shield PN532 shield from Adafruit for development and as communication master a PIC microcontroller by I2C bus. I'm detecting tag's and all, but my goal is to use NFC Android phones to individual identification in my reader.


1) The problem is that I find out in some forums discussion that "chip emulation mode" in Android phones is not possible. Here: https://groups.google.com/forum/?fromgroups=#!topic/android-developers/oJzeLJALdG8


2) I'm guessing if there is any way by building a App for Android that communicate in any other way, like P2P for example, and change data with my "reader" (Shield from Adafruit - PN532 from NXP).Is there any way?


3)Assuming there is a way. I found out that the newer android nfc phones have NFC hardware from NXP, unlike the new nexus 4 that is a cheap evoluted nfc android phone(that is in my financial range) that come equipped with FC hardware (Broadcom). I verified at http://andytags.com/nfc-tags-nexus-4--10-compatibility.html#.UYES9bXvss4 that came up some problems related with "read/write mode" with mifare classic tag's (that are not 100% compatible with nfc forum specs) and the compability with different android phones with different chips brands is yet proved(tranfering files in P2P mode). What should I do, supposing I'm developing some product prototype?


Hope you can help! Thanks !


César Cardoso



.

stackoverflow.comm

[android help] SQL Exception error when open connection using SQL Helper Android Eclipse


I am having terrible trouble with a database connection using eclipse for an android app


I had a working example of this but since i have adapted it i have been unable to open a database connection.


I have a main activity that opens a "getData" in an Async Task


This downloads a JOSN formatted document, parses and passes to "writeSync" class


This class is designed to open the database connection add the records and then close the connection.


I am receiving an error when i run the database.open method but am unable to trap the specific error.


I have checked that i am not passing Null values and that the Helper object is populated.


Here is my code if anyone can spot my problem.


I have also written a wrapper class to pass the context when the database is opening


MAIN ACTIVITY



package com.example.jsondb;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;

public class MainActivity extends Activity {
public Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

getContext contextrequest = new getContext();

AsyncTask JSONData;
//Get JSON Data as a string
//Update display#
//SyncDataProducts();
JSONData = new GetData().execute("null");

String WriteDB = "";
//pass JSONData to database to be written
//update display

}

@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;
}

}


GETDATA



package com.example.jsondb;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;
import android.util.Log;

public class GetData extends AsyncTask {


public String getServerData(String strURL) {
InputStream is = null;

ArrayList nameValuePairs = new ArrayList();
nameValuePairs.add(new BasicNameValuePair("code","A"));

//get http data
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(strURL);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();

}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}


//convert response to string
String result = "";
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();

result=sb.toString();

//send data to database
AsyncTask WriteData;
WriteData = new WriteSync().execute(result);

return result;

}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}




return result;





}

@Override
protected String doInBackground(String... arg0) {
// TODO Auto-generated method stub
return getServerData("http://500kgiveaway.co.uk/android/products.php");
}
}


WRITESYNC



package com.example.jsondb;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

public class WriteSync extends AsyncTask {
private Context adapterContext;
public String WriteSyncData(String result) {
String httpResponce = "";
String returnstring = "";
httpResponce = result;


adapterContext = getContext.getContextNow();

DataSource datasource;
datasource = new DataSource(adapterContext);

datasource.open();


try{
JSONArray jArray = new JSONArray(httpResponce);
for(int i=0;i JSONObject json_data = jArray.getJSONObject(i);

datasource.createProduct(json_data.getString("stockref"), json_data.getString("title"), json_data.getString("price"));

//Get an output to the screen
returnstring += "\n\t" + jArray.getJSONObject(i);
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}


return returnstring;


}

@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub

return WriteSyncData(params[0]);
}
}


MYSQLHELPER



package com.example.jsondb;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper{
//Product Table
public static final String TABLE_NAME = "products";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_STOCKREF = "stockref";
public static final String COLUMN_TITLE = "title";
public static final String COLUMN_PRICE = "price";

private static final String DATABASE_NAME = "Logma.db";
private static final int DATABASE_VERSION = 2;

// Database creation sql statement

private static final String DATABASE_CREATE = "create table "
+ TABLE_NAME
+ "(" + COLUMN_ID + " integer primary key autoincrement,"
+ COLUMN_STOCKREF + " text not null,"
+ COLUMN_TITLE + " text not null,"
+ COLUMN_PRICE + " text not null"
+ ");";


public MySQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(MySQLiteHelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}

}


DATA SOURCE



package com.example.jsondb;

import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class DataSource {
private SQLiteDatabase database;
private MySQLiteHelper dbHelper;
private String[] allColumns_products = { MySQLiteHelper.COLUMN_ID,
MySQLiteHelper.COLUMN_STOCKREF,MySQLiteHelper.COLUMN_TITLE,MySQLiteHelper.COLUMN_PRICE};

public DataSource(Context context) {
dbHelper = new MySQLiteHelper(context);
}

public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}

public void close() {
dbHelper.close();
}

public String createProduct(String strStockRef, String strTitle, String strPrice) {
ContentValues values = new ContentValues();
values.put(MySQLiteHelper.COLUMN_STOCKREF, strStockRef);
values.put(MySQLiteHelper.COLUMN_TITLE, strTitle);
values.put(MySQLiteHelper.COLUMN_PRICE, strPrice);


long insertId = database.insert(MySQLiteHelper.TABLE_NAME, null,
values);

return "Completed";
}

}


GETCONTEXT



package com.example.jsondb;

import android.content.Context;

public class getContext extends android.app.Application {

private static getContext instance;

public getContext() {
instance = this;
}

public static Context getContextNow() {
return instance;
}

}


Here is my stack trace



05-01 15:21:22.948: E/AndroidRuntime(24214): FATAL EXCEPTION: AsyncTask #2
05-01 15:21:22.948: E/AndroidRuntime(24214): java.lang.RuntimeException: An error occured while executing doInBackground()
05-01 15:21:22.948: E/AndroidRuntime(24214): at android.os.AsyncTask$3.done(AsyncTask.java:299)
05-01 15:21:22.948: E/AndroidRuntime(24214): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
05-01 15:21:22.948: E/AndroidRuntime(24214): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
05-01 15:21:22.948: E/AndroidRuntime(24214): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
05-01 15:21:22.948: E/AndroidRuntime(24214): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-01 15:21:22.948: E/AndroidRuntime(24214): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-01 15:21:22.948: E/AndroidRuntime(24214): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-01 15:21:22.948: E/AndroidRuntime(24214): at java.lang.Thread.run(Thread.java:856)
05-01 15:21:22.948: E/AndroidRuntime(24214): Caused by: java.lang.NullPointerException
05-01 15:21:22.948: E/AndroidRuntime(24214): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:236)
05-01 15:21:22.948: E/AndroidRuntime(24214): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
05-01 15:21:22.948: E/AndroidRuntime(24214): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
05-01 15:21:22.948: E/AndroidRuntime(24214): at com.example.jsondb.DataSource.open(DataSource.java:19)
05-01 15:21:22.948: E/AndroidRuntime(24214): at com.example.jsondb.WriteSync.WriteSyncData(WriteSync.java:24)
05-01 15:21:22.948: E/AndroidRuntime(24214): at com.example.jsondb.WriteSync.doInBackground(WriteSync.java:51)
05-01 15:21:22.948: E/AndroidRuntime(24214): at com.example.jsondb.WriteSync.doInBackground(WriteSync.java:1)
05-01 15:21:22.948: E/AndroidRuntime(24214): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-01 15:21:22.948: E/AndroidRuntime(24214): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-01 15:21:22.948: E/AndroidRuntime(24214): ... 4 more


.

stackoverflow.comm

[General] We consider to use sub-20


We consider to use sub-20 as i2c master. Especially for it's functionality as i2c multi master and additional 4 i2c master channels. Sub-20 is going to be used in production testing device. The dut (device under test) has a number of i2c slave channels. At some moment channels can be connected to each other via i2c switch device.
The question is if such configuration is correct. Has someone used more then one sub-20 i2c channel and connected them to each other?



.

forum.xda-developers.com

[android help] to get one value of the column from the table layout after the user clicks on the row

android - to get one value of the column from the table layout after the user clicks on the row - Stack Overflow








Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I am creating an android app in which m displaying rows from the database in a table layout. In these rows i am displaying the row id and two columns from the database. I have put an on click event on the rows. what i want is now to get the id value of the specific row on which the user clicks and then display all the details from the database based on that row id... i know the part of displaying from the database by select statement. m not able to capture the row id in the onclick event... how do i do that??? anyone has any idea please help!!! here is the code for displaying details in the row...



Cursor cursor=database.rawQuery("select * from "+AllValuesTable+" ", null);
Integer index0=cursor.getColumnIndex("ROWID");
Integer index1 = cursor.getColumnIndex("appln_no");
Integer index2 = cursor.getColumnIndex("app_fname");

if(cursor.getCount()>0)
{
cursor.moveToFirst();
do
{
row=new TableRow(this);
row.setId(100);

row.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));

//setting the first column
firstCol=new TextView(this);
firstCol.setText(cursor.getString(index0));
rowid=cursor.getInt(index0);
firstCol.setTextSize(16);
firstCol.setTextColor(Color.BLACK);
firstCol.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
row.addView(firstCol); //adding coloumn to row

// Setting up the second coloumn parameters
secondCol=new TextView(this);
secondCol.setText(cursor.getString(index1));
secondCol.setTextColor(Color.BLACK);
secondCol.setTextSize(16);
secondCol.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
row.addView(secondCol); //adding coloumn to row

// Setting up the third coloumn parameters
thirdCol=new TextView(this);
thirdCol.setText(cursor.getString(index2));
thirdCol.setTextColor(Color.BLACK);
thirdCol.setTextSize(16);
thirdCol.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
row.addView(thirdCol);















Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.










default







.

stackoverflow.comm

[android help] Getting Blank Activity not with existing Product Information while click on List View Item row


I am writing a Cart App, and allowing user to add items into Cart Activity, in cart item list i am using 3 Textviews for numeric value (i.e: Item Cost, Qty, Total) and these values are coming from ProductInformationActivity.java, now i want to allow user to update any of the item which is still in Cart Activity by click on that particular item, i want to open that item in ProductInformationActivity.java with existing details like: what Qty user has entered earlier (like: we see in Cart Apps), to do that i am using below code in my Cart Adapter....


but i guess i am doing something wrong, due to two reasons:


  1. I think this is not the exact code to open that particular item with existing details

  2. I am getting force close whenever i do click on any of the Item in List View [now this problem has been resolved by @Grishu and @Pragnani]

below is the Line in ProductInformationActivity.java where i am getting NumberFormatException:


itemamount = Double.parseDouble(text_cost_code.getText().toString());



public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.listrow_cart, null);
vi.setClickable(true);
vi.setFocusable(true);

vi.setOnClickListener(new OnClickListener() {
@Override

public void onClick(View v)
{
HashMap item = Constant.wishProducts.get(position);
Log.d("CartAdapter", "onClick :: " + item);
Intent myIntent = new Intent
(activity, com.era.restaurant.versionoct.menu.ProductInformationActivity.class);
Log.d("CartAdapter", "Intent :: " + myIntent);
myIntent.putExtra("Item", item);
activity.startActivity(myIntent);
}
});


So here i need your help, tell me what you think what code i should to show selected item in ProductInformationActivity.java with existing details, because i think if i will put correct code in method then i will not get that force close error message...


ProductInformationActivity.java:



public class ProductInformationActivity extends Activity {

public static final String KEY_TITLE = "title";
public static final String KEY_DESCRIPTION = "description";
public static final String KEY_COST = "cost";
public static final String KEY_TOTAL = "total";
public static final String KEY_QTY = "qty";
public static final String KEY_THUMB_URL = "imageUri";


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.information_product);

Intent in = getIntent();
String title = in.getStringExtra(KEY_TITLE);
String description = in.getStringExtra(KEY_DESCRIPTION);
String thumb_url = in.getStringExtra(KEY_THUMB_URL);
String cost = in.getStringExtra(KEY_COST);
String total = in.getStringExtra(KEY_TOTAL);

ImageLoader imageLoader = new ImageLoader(getApplicationContext());

ImageView imgv = (ImageView) findViewById(R.id.single_thumb);
final TextView txttitle = (TextView) findViewById(R.id.single_title);
final TextView txtdescription = (TextView) findViewById(R.id.single_description);
TextView txtheader = (TextView) findViewById(R.id.actionbar);
text_cost_code = (TextView) findViewById(R.id.single_cost);
edit_qty_code = (EditText) findViewById(R.id.single_qty);
edit_qty_code.setText("1");
txt_total = (TextView) findViewById(R.id.single_total);

txttitle.setText(title);
txtheader.setText(title);
text_cost_code.setText(cost);
txt_total.setText(total);
txtdescription.setText(description);
imageLoader.DisplayImage(thumb_url, imgv);


if(text_cost_code.getText().length() > 0)
{
try
{
itemamount = Double.parseDouble(text_cost_code.getText().toString());
Log.d("ProductInformationActivity", "ItemAmount :: " + itemamount);
}
catch(NumberFormatException e)
{
itemamount=0.00;
Log.d("ProductInformationActivity", "NumberFormatException :: " + e);
}
}

txt_total.setText(Double.toString(itemamount));
edit_qty_code.addTextChangedListener(new TextWatcher() {

public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
if (!edit_qty_code.getText().toString().equals("")
|| !edit_qty_code.getText().toString().equals("")) {

// accept quantity by user
itemquantity = Integer.parseInt(edit_qty_code.getText()
.toString());

// changes in total amount as per change in qty (entered by user)
txt_total.setText(new DecimalFormat("##.#").format(itemamount*itemquantity));
} else {
txt_total.setText("0.00");
}
}

public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub

}

public void afterTextChanged(Editable s) {

}
});

ImageButton mImgAddCart = (ImageButton) findViewById(R.id.button_add);
mImgAddCart.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
mTitle = txttitle.getText().toString();

mCost = text_cost_code.getText().toString();
mCost = mCost.replace("From ", "");
mTotal = txt_total.getText().toString();
mTotal = mTotal.replace("From ", "");
mQty = edit_qty_code.getText().toString();

if ( Constant.wishProducts.size() <= 0) {
HashMap mTempObj = new HashMap();
mTempObj.put(KEY_TITLE, mTitle);
mTempObj.put(KEY_QTY, mQty);
mTempObj.put(KEY_COST, mCost);
mTempObj.put(KEY_TOTAL, mTotal);
Constant.wishProducts.add(mTempObj);
/**
* code to update, already added item details
*/

} else {
for (int i = 0; i < Constant.wishProducts.size(); i++) {
if ( Constant.wishProducts.get(i).get(KEY_TITLE)
.equals(mTitle)) {
Constant.wishProducts.remove(i);
break;
} else {
}
}

HashMap mTempObj = new HashMap();
mTempObj.put(KEY_TITLE, mTitle);
mTempObj.put(KEY_QTY, mQty);
mTempObj.put(KEY_COST, mCost);
mTempObj.put(KEY_TOTAL, mTotal);
Constant.wishProducts.add(mTempObj);
}

AlertDialog.Builder alertdialog = new AlertDialog.Builder(
ProductInformationActivity.this);
alertdialog.setTitle(getResources()
.getString(R.string.app_name));
alertdialog.setMessage("Item Added to Order");

alertdialog.setPositiveButton("OK",
new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,
int which) {
// TODO Auto-generated method stub
finish();
}
});
alertdialog.show();


}
});


See some screen shots:



> Now i want to get this kind of Activity with existing Product Information,
which i have clicked in List View Item row in Cart Activity


enter image description here



> Getting this blank Activity, whenever i do click on ListView Item
row in CartActivity:


enter image description here



> ListView Item row, which i have clicked in CartActivity.java:


enter image description here


Now i have posted code for ProductInformationActivity.java, and also written that i am passing values from ProductInformationActivity.java to CartActivity.java, and 3 main screen shots to explain you what i want, when i do click on ListView Item row and What i am getting....


Please help me..... :)



.

stackoverflow.comm

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...