Skip to main content

Posts

Showing posts from April 10, 2012

Long press on UITableView

I would like to handle a long press on a UITableViewCell to print a "quick access menu". Does someone already did this ? Particularly the gesture recognize on UITableView ? Source: Tips4all

iPhone MP4 Video Playlist

I have a library of footage encoded as H.264/AAC inside MP4 containers. Right now I can successfully stream the footage to the iPhone using Apache and mod_h264. What I'd like to be able to do is tell the iPhone to play three clips back to back. The natural solution seems to be to create a .m3u8 playlist and point the player at that, however when I do I get audio and no video. I'm not sure if this is because the iPhone only supports playlist video thats encoded as an Mpeg2 Transport Stream (.ts) or if I'm doing something wrong. Has anyone had any experience streaming MP4 files to the iPhone in a playlist? Source: Tips4all

Like button in iOS application

Does anybody know how to place Facebook "like" button into iOS application? I've tried the method described in this blog post . But I do not really like this method, because its ugly Login dialog. And, what is more important, it makes user login twice. For example, user wants post a message to his wall if he isn't logged in I call standard FBLoginDialog, after that user posted a message he may want push "like" button and he have to login again - it is really bad user experience. How to be? How can I give user "like" feature in my iOS app? Source: Tips4all

Compile PHP with GD for iPhone OS 4.1

The Goal: have a working version of PHP with the GD library working on an iPod Touch 4th Gen. The Status: PHP is working on the iPod (lighttpd + PHP 5.2.8 + sqlite3) without GD. When trying to compile PHP on the iPod I get this error: http://pastebin.com/kUmgq70G The Proposed Solution: Can anyone point me in the direction of how to compile PHP with GD and then package it up nicely as a .deb file for everyone else to use? The best situation I believe is to compile the latest version of PHP with the GD library included and enabled. Second best would be to settle for compiling GD as a module and then installing that into the currently working PHP that is available from Cydia. However to compile GD you would have to do this with the SAME source that was used to create the php_5.2.8-3_iphoneos-arm.deb available from Cydia - I think it would be easier and safer for everyone in the future to just compile a fresh PHP with GD already enabled and then pack it up as a .deb Here

What are some great iPhone questions for exercise?

In a small team where everyone is coding away on a project for a little while I want to encourage some different thinking to keep people increasing their iOS knowledge as well as to get a bit more variety in their daily activities. I'm not looking for interview questions involving manhole covers, nor very specific questions about whether drawRect: is part of UIView or UIViewController. I'm looking for questions more along the lines of UIImagePickerController, UIImage, Memory and More! - which has a lot of questions and a lot of great information. I voted it up. I'm thinking of sending out one of these topics about every week and then having a discussion about it towards the end of the week with some examples. Maybe assign a short presentation on a rotating basis so someone gets the job of delivering a 10-minute presentation about the topic, prizes awarded etc. - then when some task comes up involving that topic we may not have an expert but we at least have someone who

UIWebView - When (or how) does CFData get released?

after multiple days of banging my head against the wall and having sleepless nights I'm hoping to find some help here. I've gone through various posts here, but none of the answers seem to provide a resolution for me. In short, my problem is that my App crashes after heavy usage (>10min) of the UIWebView (e.g. opening larger news paper sites in series - one after the other). To give more details: I am writing an iPhone App and from the MainViewController I push a browserViewController on the navigationController. The browserViewController loads a nib which contains a UWebView (I do not create the WebView programatically). The UIWebView is wired up using Interface Builder. When going back to Main and then going again to the browserViewController, I only recreate the browserViewController if it is nil. (I want to keep the content that is loaded i the UIWebView - only if there is a memory warning shoud this view be unloaded and release all memory used). In both, MainV

How to print in iOS 4.2?

I want to integrate the print functionality in my app. The document I want to print will be in .doc or .txt format. I am not very experienced in iPhone development yet, so finding it difficult to implement it by following the Apple documentation. If someone could help me by posting some sample code, will be a great help. Thanks in advance. -iPhoneDev Source: Tips4all

Which Flurry library should I use for universal iPhone/iPad apps?

Flurry has a separate analytics SDK for iPad apps vs iPhone apps. If I'm building a universal app to run on the iPhone 4.0+ and iPad 3.2+ (iPad native, not compatibility mode), does anyone know which SDK/lib I should use? And is there any reason I shouldn't use the same SDK/lib for apps running on iPhone 4+ only? (Basically, I'm confused as to why there are separate SDKs at all.) Source: Tips4all

How to handle app URLs in a UIWebView?

I recently found that my UIWebView was choking on ITMS links. Specifically, from the UIWebView in my app, if I navigate to a site such as this one and click the "Available on the App Store" link, UIWebView would error out with "Error Domain=WebKitErrorDomain Code=101 The URL can't be shown." After a bit of Googling, I realized that I needed to catch requests for app links and have iOS handle them. I started out by looking to see if the scheme starts with "itms" in -webView:shouldStartLoadWithRequest:navigationType: , but realized that there might be other kinds of app links that the system can handle. So I came up with this, instead: - (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error { // Give iOS a chance to open it. NSURL *url = [NSURL URLWithString:[error.userInfo objectForKey:@"NSErrorFailingURLStringKey"]]; if ([error.domain isEqual:@"WebKitErrorDomain"] && error.code == 101

App crashes with 4.2 iPhone simulator "set start-with-shell off"

I'm writing application which perfectly works on 4.0/4.1 iPhone simulator, but not 4.2. I'm getting such warning: Detected an attempt to call a symbol in system libraries that is not present on the iPhone: fcntl$UNIX2003 called from function get_socket_nonblocking in image TestApp. If you are encountering this problem running a simulator binary within gdb, make sure you 'set start-with-shell off' first. How to set 'set start-with-shell off' on Xcode? I'm tried to add this line to .gdbinit but without luck. With 4.0/4.1 SDK iPhone Simulator prints warnings about attempt to call symbol that is not present on the iPhone in debug window, but app don't crashes. Using using 4.2 app crashes. How to prevent 4.2 crashes ? Thanks Source: Tips4all

iPhone Enterpise Deployment: Mobile Device Management

I was reading up on iPhone in the enterprise and saw something about Mobile Device Management servers. As far as I can tell, there are a few 3rd party MDM vendors, but Apple says that one could implement their own. The iPhone Configuration Utility allows you to set up a Server URL, Check in URL, Topic, Identity, and some other things for an MDM, but there's little information on how to build a server that hooks in with these. I've looked in the Enterprise Deployment, iPhone Configuration, and even the iPhone Mobile Device Management docs, but have found little aside from vague mentions or the occasional diagram. Is there a documented protocol somewhere? Source: Tips4all

Create text Stroke for UILabel iphone

I was wondering how can I create text stroke for UILabel in iOS4 ? I need some suggestion . I want something like this : EDITED : UIFont *font = [UIFont fontWithName:@"Arial" size:222]; CGPoint point = CGPointMake(0,0); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 0.7); CGContextSetRGBStrokeColor(context, 2, 2, 2, 1.0); CGContextSetTextDrawingMode(context, kCGTextFillStroke); CGContextSaveGState(context); // I change it to my outlet [label.text drawAtPoint:point withFont:font]; CGContextRestoreGState(context); Source: Tips4all

Inner shadow effect on UIView layer?

I have the following CALayer: CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = CGRectMake(8, 57, 296, 30); gradient.cornerRadius = 3.0f; gradient.colors = [NSArray arrayWithObjects:(id)[RGB(130, 0, 140) CGColor], (id)[RGB(108, 0, 120) CGColor], nil]; [self.layer insertSublayer:gradient atIndex:0]; I'd like to add an inner shadow effect to it, but I am not quite sure how to do this. I suppose I would be required to draw in drawRect, however this would add the layer on top of other UIView objects, since it's supposed to be a bar behind some buttons, so I am at a loss as to what to do? I could add another layer, but again, not sure how to achieve the inner shadow effect (like this: http://sublimeorange.com/uploads/2009/09/innershadow.png ) Help appreciated... Source: Tips4all

iOS Multi-Tasking Track GPS Location

I was just wondering if it was possible to make an iOS app that would track your location via GPS while it was in the background. I tried this with the built-in app "Maps", but to no avail. If this is possible, it would be great if you could refer me to some sample code, documentations, or tutorials! (if this is a duplicate, please let me know and I will remove it) Source: Tips4all

Android sqlite get boolean from database

was just wondering, how can I obtain the value of a boolean field in a sqlite database in android? I usually use getString() getInt() etc to get the values of my fields, but there does not seem to be a getBoolean() method. Any takers? Kev Source: Tips4all

Drawing waveform with AVAssetReader

I reading song from iPod library using assetUrl (in code it named audioUrl) I can play it many ways, I can cut it, I can make some precessing with this but... I really don't understand what I gonna do with this CMSampleBufferRef to get data for drawing waveform! I need info about peak values, how I can get it this (maybe another) way? AVAssetTrack * songTrack = [audioUrl.tracks objectAtIndex:0]; AVAssetReaderTrackOutput * output = [[AVAssetReaderTrackOutput alloc] initWithTrack:songTrack outputSettings:nil]; [reader addOutput:output]; [output release]; NSMutableData * fullSongData = [[NSMutableData alloc] init]; [reader startReading]; while (reader.status == AVAssetReaderStatusReading){ AVAssetReaderTrackOutput * trackOutput = (AVAssetReaderTrackOutput *)[reader.outputs objectAtIndex:0]; CMSampleBufferRef sampleBufferRef = [trackOutput copyNextSampleBuffer]; if (sampleBufferRef){/* what I gonna do with this? */} Please hel

Is there a way to make drawRect work right NOW?

The original question............................................... If you are an advanced user of drawRect on your ipop*, you will know that of course drawRect will not actually run until "all processing is finished." setNeedsDisplay flags a view as invalidated and the OS, in a word, waits until all processing is done. This can be infuriating in the common situation where you want to have: a view controller 1 starts some function 2 which incrementally 3 creates a more and more complicated artwork and 4 at each step, you setNeedsDisplay (wrong!) 5 until all the work is done 6 Of course, when you do that, all that happens is that drawRect is run once only after step 6. What you want is for the ^&£@%$@ view to be refreshed at point 5. This can lead to you smashing your ipops on the floor, scanning Stackoverflow for hours, screaming at the kids more than necessary about the dangers of crossing the street, etc etc. What

what does Invalid statement in fillWindow() in android cursor mean?

i sometimes see this error in my logcat output, Cursor: invalid statement in fillWindow(). it sometimes happens when i press the back key and then it goes to the default android listview before going to my custom listview. what does it mean? how do i solve it? Because it does not point to any line of code where the problem is coming from? Source: Tips4all

How to Get Android System Colors

I've seen references on how to SET system colours, but I need to find out how you GET them - how do you find out what they are? On the Samsung Galaxy S for example, the tab views, ListView highlights when you select an item, and the Summary text line on the preference screen are all blue. There are many apps which immitate this style and I want to do the same. Obviously I cannot just hard code and set the colour to Blue, as other handsets use different colours. The question is, is there a way to programmatically find out what colour the Preference Screen Summary Line, Tabs, or ListView selections are, so that you can then set that against a TextView elsewhere in your app? How do I get the android system colours? Source: Tips4all

Streaming Video From Android

I'm trying to stream video from the Android phone, which should be watched in an mediaplayer. I've been looking at http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system which seems to be a dead end since it send the raw file data, and not a streamable format. Then I tried using some code from SipDroid, more specific; parts of VideoCamera.java, RtpPacket.java and RtpSocket.java, which gives a stream on UDP, however these is not playable in i.e. mplayer(can't detect the codec). Wireshark tells that it is a UDP packet and not a RTP packet so something might be missing? I'm kind'a stuck, have you any suggestions how to get past this bump? Source: Tips4all

Android status bar expects icons of size 25x25dp while guidelines recommend 32x32dp. Who is wrong?

According to android icon design guidelines ( here , see table #1), developer needs to provide status bar icons of next sizes: Status Bar 24 x 24 px (LDPI) 32 x 32 px (MDPI) 48 x 48 px (HDPI) While my measurements show that status bar always has 25 dp in height and expects icons of 25x25dp. This translates to these sizes: Status Bar 19 x 19 px (LDPI) 25 x 25 px (MDPI) 38 x 38 px (HDPI) Here is how I get those size: 25dp * 0.75 = 18.75 => 19px (LDPI) 25dp * 1 = 25 => 25px (MDPI) 25dp * 1.5 = 37.5 => 38px (HDPI) I have confirmed calculated sizes on several Android phones and on emulators. The question basically is: why guidelines use sizes different from what is really used by status bar? P.S. I actually need to break guidelines due to precise pixel control requirements. And I just was confused by this state of affairs. So explanation of why this the way it is would really help me. Source: Tips4all

Is Hibernate an overkill for an Android application?

I'm looking for a good ORM for my android application and at first glance it seems like for a mobile device I would prefer to use something simpler maybe. The thing is I'm just assuming here with no real evidence, so I thought I would ask the community's opinion (maybe there's is someone that has been through the experience). It is a fairly large(for mobile) application and will be run on a dedicated tablet. What does everyone else think ? Is Hibernate too much for an android application ? Will there be performance problems ? What would you use instead if you think it is too much ? I am aware there are other questions asking for alternatives, but I decided to ask since most of those questions simply assumed it was an overkill and asked for other options and I started wondering "Is it really and overkill ? Why ?" Due to my lack of experience I simply think it it, but can't really provide an answer if I'm asked to explain why. Is it performance ?

Android. Content provider or Database?

Since I've seen a presentation from Google IO I'm a bit confused in the question, if it's better to use content providers or databases. Or it makes no difference if I don't want to share any data with other applications. If I've understood it right, content providers based on SQLite DBs and it's also possible that content of them is only accessable for my application. Can you give some explanations? Thank you very much, Mur Source: Tips4all

Is it really Impossible to Protect Android apps from Reverse Engineering?

As we know, Android apps are written in Java. In Java, no matter what you do , it is impossible to protect compiled code from decompilation or reverse-engineering, as the following thread suggests: How to lock compiled Java Classes to prevent decompilation My question is how one would go about protecting an app that contains algorithmic trade secrets from reverse-engineering? By "how" I mean not only software techniques but also other creative approaches. Source: Tips4all

How to make glow effect around a bitmap?

The following code is what I got so far. However, there are 2 issues: I want both inner and outer glow effects, which looking similar to the Photoshop's blending options. But I only managed to make the outer glow, if I set BlurMaskFilter.Blur.INNER or other value, the whole image is blocked, instead of just edges. Despite I set "FF" as alpha value, the glow color is still very dark. Bitmap alpha = origin.extractAlpha(); BlurMaskFilter blurMaskFilter = new BlurMaskFilter(5, BlurMaskFilter.Blur.OUTER); Paint paint = new Paint(); paint.setMaskFilter(blurMaskFilter); paint.setColor(0xffffffff); Canvas canvas = new Canvas(origin); canvas.drawBitmap(alpha, 0, 0, paint); return origin; Source: Tips4all

Android getSystemService inside custom ArrayAdapter

I was trying to write a custom ArrayAdapter referencing here My code is package com.example.AndTest; import java.util.ArrayList; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; public class CategoryAdapter extends ArrayAdapter<Category> { private ArrayList<Category> items; public CategoryAdapter(Context context, int textViewResourceId, ArrayList<Category> items) { super(context, textViewResourceId, items); this.items = items; } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.list, null); } Category c = items.get(position); if (c !=

How to create two views in Android that use 50% height each, unless one is smaller?

Imagine a full Android device screen, I want it split in to two sections: The upper half has text in it, which may be larger than the space available (or not) and so the text will scroll (i.e. TextView inside a ScrollView) The lower half contains a MapView control. Looking specifically at some scenarios: If the text is small, I want the map to take up more space, i.e. more than 50%. So perhaps 20% text, 80% map. If the text is larger, it only takes up a MAXIMUM of 50% of the screen space, and then scrolls. So 50% map, 50% text. At the moment I've assigned weights to the two parts, and that isn't too bad, but if the text is small, the map doesn't expand to take the space, and the layout has a wasted gap that the map could usefully use. I've tried loads of combinations but can't see how to make this happen. It seems to be a common experience for me that I know what I want, but can't see how to get the available views to deliver it. I'm

"Android library projects cannot be launched&rdquo;?

Now I am totally confused by this error message: Android library projects cannot be launched. I carefully checked the build path and library, everything is OK . And there is no error in Problems view. However, when I tried to run my application as an Android project, it failed and showed this message. What really happened in my code? Any ideas? Thank you in advance! Regards, Kariya Source: Tips4all

Android: ClassCastException when adding a header view to ExpandableListView

I'm trying to add a header to an ExpandableListView like so: headerView = View.inflate(this, R.layout.header, null); expandableListView.addHeaderView(headerView); expandableListView.setAdapter(new SectionedAdapter(this)); Which gives me the following error: 12-08 16:23:42.354: ERROR/AndroidRuntime(421): Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 12-08 16:23:42.354: ERROR/AndroidRuntime(421): at android.widget.ListView.clearRecycledState(ListView.java:504) 12-08 16:23:42.354: ERROR/AndroidRuntime(421): at android.widget.ListView.resetList(ListView.java:490) 12-08 16:23:42.354: ERROR/AndroidRuntime(421): at android.widget.ListView.setAdapter(ListView.java:422) 12-08 16:23:42.354: ERROR/AndroidRuntime(421): at android.widget.ExpandableListView.setAdapter(ExpandableListView.java:475) This is happening at the call to expandableListView.setAdapter(new SectionedAdapter(this)) , but I can't figure out why. Any ideas? Source: Tips4al

Android: trouble updating to Android SDK Tools, revision 7

Currently I have Android SDK 2.1 (+ tools revision 4). I'd like to upgrade to Android SDK 2.2. When I try to do it I'm informed I need to upgrade Android SDK Tools to revision 7 first. So I agree, the process starts and then I get an error: -= warning! =- A folder failed to be renamed or moved. On Windows this typically means that a program Is using that Folder (for example Windows Explorer or your anti-virus software.) Please momentarily deactivate your anti-virus software. Please also close any running programs that may be accessing the directory 'D:\Install\Programming\android-sdk-working-dir\android-sdk_r04-windows\android-sdk-windows\too!s'. When ready, press YES to try again. Downloading Android SDK Tools, revision 7 Installing Android SDK Tools, revision 7 Failed to rename directory D:\Install\Programming\android-sdk-working-dir\android-sdk_r04-windows\android-sdk-windows\tools to D:\Install\Programming\android-sdk-working-dir\android-sdk_

Java unknown host exception

I am trying to access textalertapp.com via HTTP Post request from my android application. But I am getting Unknown host error. Can anybody help me solve this issue. 12-13 01:30:16.058: WARN/System.err(473): java.net.UnknownHostException: textalertapp.com 12-13 01:30:16.088: WARN/System.err(473): at java.net.InetAddress.lookupHostByName(InetAddress.java:513) 12-13 01:30:16.088: WARN/System.err(473): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:278) 12-13 01:30:16.088: WARN/System.err(473): at java.net.InetAddress.getAllByName(InetAddress.java:242) 12-13 01:30:16.088: WARN/System.err(473): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136) 12-13 01:30:16.099: WARN/System.err(473): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 12-13 01:30:16.099: WARN/System.err(473): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(

Android ContentProvider Performance

I'm curious if anyone has done any performance testing on querying a ContentProvider via ContentResolver vs querying a SQLiteDatabase object in the same process. I'm guessing that a ContentResolver query passes back a Cursor that communicates with the database through a Binder (Android IPC). This means that if I read the contents of 100 records through the Cursor that would result 100 Binder method calls. Are my guesses correct and if so would that be significantly slower than accessing the database in the same process? Source: Tips4all

converting pixels to dp in android

I have created my application with the height and width given in pixel for a pantech device whose resolution is 480x800. I need to convert the the height and width for an G1 device. I thought converting it into dp will solve the prob and provide same solution for both the device. is there any easy way to convert the pixels to dp?? or any suggestions?? Source: Tips4all

Encryption of image files on Android &mdash; Cipher(Output|Input)Stream problems

I'm trying to encrypt image files on Android with password based encryption. To save the encrypted image I just do this: FileOutputStream fos = new FileOutputStream(thumbnailFile); CipherOutputStream cos = new CipherOutputStream(fos, encryptCipher); Bitmap thumbnail = Bitmap.createScaledBitmap(bm2, 140, 140, true); thumbnail.compress(Bitmap.CompressFormat.JPEG, 80, cos); and to read it, this: FileInputStream fis = new FileInputStream(f); CipherInputStream cis = new CipherInputStream(fis, decryptCipher); Bitmap b = BitmapFactory.decodeStream(cis); but the Bitmap ends up as null. The code works when I bypass the encryption; that is when I use the File(Input|Output)Streams rather than the Cipher(Input|Output)streams. My Ciphers are created as follows: public void initCiphers(char password[]) { PBEKeySpec pbeKeySpec; PBEParameterSpec pbeParamSpec; SecretKeyFactory keyFac; byte[] salt = { (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c, (byte)0x7e, (byte)0xc8, (byte)0xee, (

Android animation does not repeat

I'm trying to make simple animation that is repeated several times (or infinite). It seems that android:repeatCount does not work! Here is my animation resource from /res/anim/first_animation.xml : <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" android:repeatCount="infinite" > <scale android:interpolator="@android:anim/decelerate_interpolator" android:duration="500" android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="1.2" android:toYScale="1.2" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" /> <scale android:interpolator="@android:anim/accelerate_interpolator" android:s

Detect whether browser has keyboard/arrow keys in web page

I have a full-screen game in HTML+JavaScript, which uses the arrow keys as primary controls. This cannot be used on keyboardless Android devices (I haven't tested on iOS), and even if the soft keyboard had arrow keys it would take up unnecessary space. Therefore, I have added onscreen control buttons. However, the buttons are unnecessary (and absurdly large) on desktop browsers, so I would like them to not pop up unless they are needed. What heuristics can I use to decide whether they are needed — that is, whether it is impossible or awkward for the user to input arrow-key events — other than recognizing specific User-Agents (which is straightforward, but not future-proof)? I will of course allow the user to hide/show the buttons; I am looking for useful heuristics for choosing the default setting. Source: Tips4all

Known problems on various Android devices?

Is there a site that collects the various issues that exist in various Android devices that an Android developer should know about? Such as "There is a problem with the vibrate feature on phone X. A workaround would be ...". If not, it would be great if someone sets this up, and allow us developers to add known problems that we experience with our applications on various Android devices. Source: Tips4all