Thursday, June 16, 2011

How to : Set Android WebView HTTP Referrer programmatically

In Android, you may use the webview.LoadData to show html. using the following code,

public class WebViewTestActivity extends Activity {

WebView wv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainbrownser);
wv = (WebView) findViewById(R.id.wv);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadData(
"<img src='http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif'>",
"text/html", "UTF-8");
}

}


When you run the app, you can see the google logo there,
image

however, if you try to access some image whose server will check the referrer, you will be in trouble to viewing the image.
by default, the webview doesn’t setup the referrer when fetching html resouces,
image

I searched a lot, there is no explicit way to setup the referrer . after checking the webview source code, here is the trick to setup the referrer, using the loaddatawithbaseurl, the baseurl will be the referrer picked by webview

imageCode,

wv.loadDataWithBaseURL("http://wwwgoogle.com/myreferrer",
"<img src='http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif?a=1'>",
"text/html", "UTF-8","");


Hope it helps,

Monday, June 13, 2011

No provisioned iOS devices are available. Connect an iOS device or choose an iOS simulator as the destination.

One day, I want to write a Iphone app for my son, then Just download the latest Xcode, and plug my Iphone to the Mac, supposedly,XCode should run the profile provisioning, I just click to Run the app. However, I get an error,
image

here, it’s a versioning issue, First, Click Window->Organizer, check Iphone OS

image

So for the Phone, It runs on 4.2.1,then make sure project building setting, using the same base level of SDK

image

by default, Xcode use the lastest sdk , that’s why you see the error.
Switch it to 4.2, then you will see you device in the target list,
image

Wednesday, June 8, 2011

How to: Test if an object is of a specified type. instanceof JAVA, C# and Objective C

In Java, just using the instanceof keyword.
image
In C#, it has the similar syntax, Just called IS

image

In Objective-C, using keyword iskingofclass,
image

Thursday, June 2, 2011

How to get the SOS.DLL for silverlight 4.0.60310.0 for windbg

If you want to do the Silverlight debugging using windbg, the first thing is you have to get the sos extension for Silverlight.
When I try to run the command ‘.loadby sos coreclr’
image
get the error , it can’t find the sos.dll, in the silverlight folder,
image

I try to google “how to get the sos.dll for silverglight4.’, nothing is helpful, then I spend a little time to figure out how to get the sos.dll. So here is the answer,

1. Install visual studio 2010, if you are a developer, you probably have already installed the IDE
2. this is important, Download and install the Microsoft Silverlight 4.0 SDK

that’s IT.
image

#1 is very important, if you skip it and install the SDK only, it wont install the sos.dll for you.

 
Locations of visitors to this page