0
我在我的活動中打開了一個webview。當我加載url時,我將aff_id和developer_public_key發送給服務器(在doInBackground方法中)。我也必須發送設備的寬度。 如何獲取設備的寬度併發送到服務器?獲取設備的寬度並將其發送到服務器?
我的活動是:
public class InterestitialAds extends Activity {
private WebView webView;
private ProgressDialog dialog;
Context context;
ImageView imageView;
RelativeLayout parentV;
private static String PREF_NAME = "gallectica_pref_adstuck";
private static SharedPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.interestitial_ads);
interAds(InterestitialAds.this);
imageView = (ImageView) findViewById(R.id.interAd);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
private void interAds(final Context ctx) {
new AsyncTask<Void, Void, Boolean>() {
private String developer_public_key, aff_id;
private String bannerUrl, clickUrl;
protected void onPreExecute() {
super.onPreExecute();
prefs = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
prefs.edit().putString("android_id", Settings.Secure.getString(ctx.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID)).commit();
developer_public_key = prefs.getString("developer_public_key", "23/89533a6f4248873b08ce52ce680f29e7");
aff_id = prefs.getString("android_id", "");
}
protected Boolean doInBackground(Void... arg0) {
String json = "";
HttpURLConnection connection = null;
InputStream is = null;
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("aff_id", aff_id));
params.add(new BasicNameValuePair("developer_public_key", developer_public_key));
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://a.nextput.com/api/single-offer/" + developer_public_key + "https://stackoverflow.com/a/fs?aff_id=" + aff_id);//YOUR URL ?aff_id
HttpResponse httpResponse = httpClient.execute(httpPost);
json = EntityUtils.toString(httpResponse.getEntity());
JSONObject jObj = new JSONObject(json);
boolean isSuccess = jObj.getBoolean("success");
System.out.println("success : " + isSuccess);
/* JSONObject jsonObject = new JSONObject(json);
boolean state = jsonObject.getBoolean("success");*/
JSONObject jo = jObj.getJSONObject("offer");
bannerUrl = jo.getString("banner_url");
clickUrl = jo.getString("click_url");
return isSuccess;
} catch (Exception e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return false;
}
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
// ImageLoader.getInstance().displayImage(bannerUrl,);
webView = (WebView) findViewById(R.id.webView3);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(bannerUrl);
parentV = (RelativeLayout) findViewById(R.id.parentRL);
parentV.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(clickUrl));
startActivity(browserIntent);
return false;
}
});
}
}.execute();
}
}
這是工作完全搞定。謝謝!!! –
也接受答案,如果有幫助 –
這是一個完美的活動。如果我有一門課,那麼如何獲得設備寬度?在類的情況下,它說無法解決'getwindowmanager()'。 –