Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 8    Views: 56

yenael
Aspiring developer
Profile
Posts: 100
Reg: Sep 17, 2013
Detroit
2,950
05/21/14 09:50 PM (10 years ago)

Altering Source Code for different android devices

Hello all, I would like to know how to modify the code in eclipse so that additional devices can work. My app works on various devices. However, on the Samsung Galaxy Note 8.0(wi-fi tablet) it closes when I click on anything within the app once it started. It works well on Samsung Exhibit and Samsung Prevail 2 as well as Alcatel Evolve. What could be the problem?
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
05/21/14 10:01 PM (10 years ago)
what does the logcat say?
 
Susan Metoxen
buzztouch Evangelist
Profile
Posts: 1706
Reg: May 01, 2011
Hopkins, Minnes...
26,260
like
05/21/14 10:09 PM (10 years ago)
If it's a memory error, try putting the images in all the drawable folders.
 
yenael
Aspiring developer
Profile
Posts: 100
Reg: Sep 17, 2013
Detroit
2,950
like
05/21/14 11:37 PM (10 years ago)
No, it's not a memory error, I already put the files in the drawable folder and nope I did not do the logcat. I figured since it worked on the other phones, it probably wouldn't show up in the logcat. Plus, if some screens were needed on a phone that weren't on a tablet, how can I make it so that the tablet shows the features it has and not the other options that would only pertain to a phone?
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
05/22/14 12:37 AM (10 years ago)
There are a few nuggets of good information in this document... http://developer.android.com/guide/practices/compatibility.html but basically it 'sounds' like 'if' you want to accomodate a phone 'and' a tablet, you create different layout files, and provide access (or deny access) with the layout for each type of device. Then, in your code you 'test' for the kind of device (usually an 'if' statement) and direct the app to utilize the 'correct' layout for the type/resolution of the device... That, and you can edit your Play Store app 'profile' to be compatible, or not, with a host of devices... Cheers! -- Smug
 
krompa
Lost but trying
Profile
Posts: 257
Reg: Jun 14, 2013
Bristol
8,820
like
05/22/14 02:56 AM (10 years ago)
I have some code which Smug helped me with that allows you to load different .xml layout files using an IF statement. I'll post the code in a few hours when I'm back to my laptop.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
05/22/14 05:39 AM (10 years ago)
I built a BT3 app that didn't seem to work on several Samsung devices, but was fine on everything else. The same app on BT 2 is not a problem, so I 'downgraded' to that until I get to the bottom of the BT 3 issue. I'm very keen to see if there is a solution.
 
krompa
Lost but trying
Profile
Posts: 257
Reg: Jun 14, 2013
Bristol
8,820
like
05/22/14 06:10 AM (10 years ago)
ok, referring to Smug's point about using different .xml files for different devices - somewhere in the .java file for the screen you are using is some code that "inflates" (or loads) the appropriate .xml file. It should look something like this (taken from the interactive quiz screen): //inflate this screens layout file... LayoutInflater vi = (LayoutInflater)thisActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View thisScreensView = vi.inflate(R.layout.screen_quiz, null); and replace this with the code below which allows you to select different .xml files based on whatever criteria you wish (e.g. screen width, android version etc) whatever it may be. The example below is for 3 different .xml files, but you could alter it for any number of .xml files. //Alternative statement to inflate correct layout file from 3 options ... LayoutInflater vi = (LayoutInflater)thisActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View thisScreensView; if (yourcriteriahere) { thisScreensView = vi.inflate(R.layout.screen_quiz_alternative1, null); } else if (yourcriteriahere) { thisScreensView = vi.inflate(R.layout.screen_quiz_alternative2, null); } else { thisScreensView = vi.inflate(R.layout.screen_quiz, null); } Replace the "yourcriteriahere" with your criteria. Make sure your original .xml file is the last one in the IF statement (in my example, the original screen_quiz.xml file is the last one in the IF statement with the 2 alternatives above it.
 
yenael
Aspiring developer
Profile
Posts: 100
Reg: Sep 17, 2013
Detroit
2,950
like
05/23/14 06:11 AM (10 years ago)
Thanks everybody, I appreciate the responses, I will try later on down the road to implement a tablet plan. Its what we do, build upon things, lol
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.