Thursday, April 11, 2013

[android help] MapFragment in a fragment Vs MapView in a fragment with Google Maps api v2


I have an app having actionbar where one of the fragments contain a mapFragment. Also, i've to make an overlay of list on top of the map. MapFragment as of now as lesser functionality(i cant make setInfoWindowAdapter to work in it).So my question is should I be using Mapview within a fragment or MapFragment within in a fragment? which is the best practice? I've read through many articles but none them exactly mention which is the best option and why.



.

stackoverflow.comm

[android help] Cannot run android ui tests from command line


Can you confirm whether the adb push actually transfers the file correctly? There are a couple of ways to check this:


  1. Check the output of the adb push command e.g. adb push bin/UIAutomatorExample.jar /data/local/tmp/ In my case the output is 1011 KB/s (5854 bytes in 0.005s) (the evidence is the number of bytes transferred. Here we know something was sucessfully transferred somewhere).

  2. Use adb shell to check the file is available in the expected location: adb shell ls -l /data/local/tmp/*.jar Here is the output for my example -rw-rw-rw- shell shell 5854 2013-04-11 01:36 UIAutomatorExample.jar Note: the file size in bytes matched the figure from the first command output, 5854 bytes.

Once we know the jar file has been successfully deployed to the correct location the run command should work, provided the target device is running version 16 or later of Android APIs. (although in practice 17 is the first version of Android where UIAutomator seems to work reliably.)


adb shell uiautomator runtest LaunchSettings.jar -c com.uia.example.my.LaunchSettings


Of course you need to replace LaunchSettings.jar with TestProject.jar :)


PS: in your example I just noticed the 'missing file' has a different filename from the one you deployed to the device: You push TestProject.jar however the 'missing file' is shown as TerranovaTests.jar - perhaps you could double-check your commands to make sure they're using the same filename?



.

stackoverflow.comm

[android help] How to hold the selected value in the radio button?

android - How to hold the selected value in the radio button? - Stack Overflow



















I'M doing quiz app. I have set 50 questions and each question contains 4 options(radio group) with pervious and next button. What i need is when select the answer and goes for next question and again he comes to previous question that time what he select perviously that answer should be in selected state. But user selected value i getText() How to implement this ? Any one help me..


Thanks in advance..




ImageView previousbtn1 = (ImageView) findViewById(R.id.prv_btn);
previousbtn1.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
if (j < 1) {
Toast.makeText(Question.this, "First Question",Toast.LENGTH_SHORT).show();
} else {
--j;
--num;
--m;
TextView txtque = (TextView) findViewById(R.id.que_txt);
txtque.setText("Q" + num + ")" + ques1.get(j));
--k;
btn_practice1.setText(answ1.get((k*4)+0));
btn_practice2.setText(answ1.get((k*4)+1));
btn_practice3.setText(answ1.get((k*4)+2));
btn_practice4.setText(answ1.get((k*4)+3));
}
}
});
















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










default






.

stackoverflow.comm

[android help] Writting an image using NdefMessage


I am trying to write an image on a Ndef Tag, currently, i am able to write it, but when I try to read it with any market application, they treat it like a text message. here is my piece of code writing the image :



Bitmap mBitmap = Bitmap.createScaledBitmap(mPhoto, 100, 100, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
NdefRecord picRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, "image/png".getBytes(), null, byteArray);
String informations = "name: "+name + "\ntitle: " + title + "\naddress: "+ address + "\ncity: "+ city + "\nphone: "+ phone + "\nmail: "+mail;
NdefRecord textRecord = createTextRecord(informations);
NdefMessage message = new NdefMessage(new NdefRecord[]{picRecord, textRecord});


i also tryed writting the image this way :



NdefMessage msg = new NdefMessage(new NdefRecord[] {createMimeRecord("image/png", byteArray), textRecord});


with the method createMimeRecord :



public NdefRecord createMimeRecord(String mimeType, byte[]payload) {
byte[] mimeBytes = mimeType.getBytes(Charset.forName("USASCII"));
NdefRecord mimeRecord = new
NdefRecord(NdefRecord.TNF_MIME_MEDIA,
mimeBytes, new byte[0], payload);
return mimeRecord;
}


Here is the result i get when trying to read my image with applications like "TagInfo" :enter image description here


The text message is well writen and can be read normally. I've tried to use the "createMime(String mime type, byte[] data) but this method seems "undefined".I've tried to compress the bitmap image in Jpeg format with the same result. Also I've tried to find examples of sending images via NdefMessages, but didn't find any. Any suggestion ?



.

stackoverflow.comm

[android help] Chat between Android, Iphone and Windows Phone on same Network(No Server Interaction)?


I need to create an application which allows users on same network(wifi, no server interaction) to chat between iphone, android and windows phone application. My app is available in iphone, android and windows phone. Now, there is an requirement that my application users on same network(wifi) can chat together?



.

stackoverflow.comm

[android help] Android pull to refresh with ScrollView control

Android pull to refresh with ScrollView control - Stack Overflow




















I am using a ScrollView to display a list of items that are inflated on runtime. Like a feed of updates for the user. While thinking about the options i got to let the user update the view with new notifications I thought about the pull to refresh feature in the twitter app.


Anyone got any idea how and if can it be implemented with a ScrollView ?


Saw there are some implementations for that using ListView but I don't like the idea of changing all of my platform to gain this refresh effect.





























There is a solution introduced for implementing pull to refresh for various component which are scrollable like listview and scroollview. Look at ChangeLog link https://github.com/chrisbanes/Android-PullToRefresh


























ListView with just one element can be treated as a ScrollView. You can use the implementation for pull-to-refresh ListView and add just one item in it. I had used this trick in the past.






















You can do that. You can increase the top margin of the scrollview when the user moves the finger down and the scrollview it's on it's top. Then on release fire the update and decrease the margin with animation.(You have to create your own animation to pull that off). That's the idea. If you want more particular help ask what you cannot implement.




















default







.

stackoverflow.comm

[android help] android app with facebook login integrated, how to generate the release key?


I have read almost all the forums related to hask key generation on windows. This is wat i did afterwards and found out the correct hash key. Stay with me and i will take you to yours.


-- Where ever you see the path, always make sure that you put yours and not exactly mine.


-- First thing is to download ssl from: http://code.google.com/p/openssl-for-windows/downloads/list


--Make a openssl folder in C drive


--Extract Zip files into openssl folder


--a better practice is to copy your jdk1.6.0_31 folder from the c drive and paste it on the desktop.


--navigate to your location of jdk/bin folder.


--now run the following command in the cmd and enter the details. (Do not exactly copy the code as my files location can be different from yours.)


C:\Users\Arsalan\Desktop\JDK_JRE\jdk1.6.0_31\bin>keytool -genkey -v -keystore highwayrun.keystore -alias androiddebugkey -keyalg RSA -validity 999999


--It will ask some questions and in the end will generate a keystore.


--after entering all these details your own app keystore will be generated in the jdk/bin folder that resides on your desktop


--finally use the command shown below, put the password and generate the hash key!


C:\Users\Arsalan\Desktop\JDK_JRE\jdk1.6.0_31\bin>keytool -exportcert -alias androiddebugkey-keystore C:\Users\Arsalan\Desktop\JDK_JRE\jdk1.6.0_31\bin\highwayrun.keystore | C:\OpenSSl\bin\openssl sha1 -binary | C:\OpenSSl\bin\openssl base64


Enter keystore password: android


[HASH KEy=]


If it does not ask for password then something went wrong and the hash key is incorrect!



.

stackoverflow.comm

[android help] Removing common elements between two different Arraylist

java - Removing common elements between two different Arraylist - Stack Overflow



















Sorry If you are thinking that it is a repeated post. But the situation is different here. I have read several posts for it but not getting the exact thing I am looking for. I know How to develop a complex logic for this but please take a look this is for android and we can't expect too much processing on the device due to to limited resources available.


I have an ArrayList of an bean class objects consisting five fields as


Java Bean -- MyShares


  1. fileName

  2. filePath

  3. fileSize

  4. isShared

  5. Creator

I have another ArrayList of String which contains only filepaths. Now what I want is to remove all the common elements between the two arraylist means the file paths in seconds arraylist and file path in first arraylist objects are similar then I have to remove from both of the arraylist But I Don't want a new arraylist which contains the uncommon elemenst But I want to get my both arraylist only without their common elements.


Please help me.





























You can use an outer loop to scan over the Bean objects, and an inner loop to scan over the file paths.


pseudo code:



for(Bean i in beans){
for(String p in paths){
if(i.path.equals(p)){
beansToRemove.add(i);
pathsToRemove.add(p);
}
}
}
beans.removeAll(beansToRemove);
paths.removeAll(pathsToRemove);


I'm not sure if my extra arraylists to track the removed arraylists go against your question or not since the original arrays remain. If you presort both arrays on the path and keep track of the position in each area (not exhaustive search) you can improve it from n2 to nlgn























Rough Java code:



HashSet commonKeys = new HashSet();
for (Share share : shares) {
commonKeys.add(share.filePath);
}
commonKeys.retainAll(filePaths);
for (Iterator it = shares.iterator(); it.hasNext(); ) {
Share share = it.next();
if (commonKeys.contains(share.filePath)) {
it.remove();
}
}
filePaths.removeAll(commonKeys);



















lang-java






.

stackoverflow.comm

[android help] AsyncTask with readObject()

android - AsyncTask with readObject() - Stack Overflow



















util.concurrent.FutureTask.finishCompletion when i try to open a file in internal storage i don't know how to handle that if you have some advices help me please


My code:



protected String doInBackground(Hashtable... params) {
Hashtable ht=params[0];

String json=HelperHttp.getJSONResponseFromURL(url, ht);
System.out.println(json);

//some code

if(json!=null) {try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(new File(new File(getCacheDir(),"")+"cacheFile.srl")));
/*The problem is here*/ JSONObject jsonObject = (JSONObject) in.readObject();
in.close();


The stacktrace:


04-11 11:52:04.694: E/AndroidRuntime(1026): FATAL EXCEPTION: AsyncTask #1 04-11 11:52:04.694: E/AndroidRuntime(1026): java.lang.RuntimeException: An error occured while executing doInBackground() 04-11 11:52:04.694: E/AndroidRuntime(1026): at android.os.AsyncTask$3.done(AsyncTask.java:299) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.FutureTask.setException(FutureTask.java:219) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.FutureTask.run(FutureTask.java:239) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.lang.Thread.run(Thread.java:856) 04-11 11:52:04.694: E/AndroidRuntime(1026): Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject 04-11 11:52:04.694: E/AndroidRuntime(1026): at com.cgi.activity.ActivityListNews$GetDeptAyncTask.doInBackground(ActivityListNews.java:81) 04-11 11:52:04.694: E/AndroidRuntime(1026): at com.cgi.activity.ActivityListNews$GetDeptAyncTask.doInBackground(ActivityListNews.java:1) 04-11 11:52:04.694: E/AndroidRuntime(1026): at android.os.AsyncTask$2.call(AsyncTask.java:287) 04-11 11:52:04.694: E/AndroidRuntime(1026): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 04-11 11:52:04.694: E/AndroidRuntime(1026): ... 3 more



















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










default






.

stackoverflow.comm

[android help] How to get a photo of video playing inside FrameLayout in android?


If by photo you mean a thumbnail then the following code could be of use to you:



int id = **"The Video's ID"**
ImageView iv = (ImageView ) convertView.findViewById(R.id.imagePreview);
ContentResolver crThumb = getContentResolver();
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id,
MediaStore.Video.Thumbnails.MICRO_KIND, options);
iv.setImageBitmap(curThumb);


You then just have to link this code to a button press using the Android onClickListner. A simple example using a listener would be like this:



final Button button = (Button) findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
}
});


Finally to save the thumbnail to the SD card you should take a look at this answer:


Android Save images to SQLite or SDCard or memory



.

stackoverflow.comm

[android help] External library jar incomplete

android - External library jar incomplete - Stack Overflow



















I'm trying to add an external jar library to my Android project. It compiles and downloads to my device correctly but I'm getting the following logcat:



04-11 08:17:16.849: E/AndroidRuntime(16053): FATAL EXCEPTION: main
04-11 08:17:16.849: E/AndroidRuntime(16053): java.lang.NoClassDefFoundError: org.puredata.android.service.R$raw
04-11 08:17:16.849: E/AndroidRuntime(16053): at org.puredata.android.service.PdService.onCreate(PdService.java:184)
04-11 08:17:16.849: E/AndroidRuntime(16053): at android.app.ActivityThread.handleCreateService(ActivityThread.java:1951)
04-11 08:17:16.849: E/AndroidRuntime(16053): at android.app.ActivityThread.access$2500(ActivityThread.java:117)
04-11 08:17:16.849: E/AndroidRuntime(16053): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
04-11 08:17:16.849: E/AndroidRuntime(16053): at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 08:17:16.849: E/AndroidRuntime(16053): at android.os.Looper.loop(Looper.java:130)


The problem seems to be that the R class isn't included in the library compilation. Through this question I arrived here where this confusing text states



Important change: We have changed the way Library Projects generate and package R classes:



  • The R class is not packaged in the jar output of Library Projects anymore.

  • Library Project do not generate the R class for Library Projects they depend on. Only main application projects generates the Library R classes alongside their own.

    This means that library projects cannot import the R class from another library project they depend on. This is not necessary anyway, as their own R class includes all the necessary resources. Note that app projects can still import the R classes from referenced Library Projects, but again, this is not needed as their own R classes include all the resources





So, I'm kind of stuck. How do I/Can I force a library to include its needed resources? If not, how can I use the R class in a library which I want to make available without sharing my project code?
























Android library projects are different from normal libraries. For versions of Android before API level 14, you cannot compile them into standalone jar files and include into your projects. Instead, you need to include them as library projects with your own Android project. That means that you need to have the full source code of the library project. Without it, you cannot use it as a library project.


When you include it as a library project into your own Android project and compile your project, the build tools will combine the resource definitions (R classes) from the library projects and your own projects and create one R class. You will then have access to resources from both your own project and library projects.


Starting with API level 14 library projects can be compiled into standalone jars and you can find the info on how to do this on google's developer's documentation site. Have a read through Android Library Projects documentation for more information.























default






.

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...