こんにちは、ご協力ありがとうございます。Eclipse で API 17 に対してコンパイルするアプリがあります。
アプリは、いくつかの簡単なインターネット接続を実行します。
現在、API 17 を使用してエミュレーターでテストすると、すべて正常に動作します。
API 8を使用してエミュレーターに対してテストすると、アプリは明らかにネットワーク接続を実行できません(adMobは表示されず、HttpGetは明らかに何も取得していません...)アプリから(エミュレーターのWebブラウザーは正常に動作し、正常にロードされます)。
また、adMob も API 8 または 10 のエミュレータではロードされません (API 17 エミュレータではロードされます)。
どんな助けでも大歓迎です!!!
これは私の主な活動です:
public class QuotesActivity extends Activity implements MyInterface {
private String url2;
public static ArrayList<Stock> lt;
public static ArrayList<Stock> favQ;
public MyAdapter myAdap;
public Intent intent;
public ListView lv;
public FavManager fm;
private AdView adView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
AdRequest request = new AdRequest();
// request.addTestDevice(AdRequest.TEST_EMULATOR);
request.setGender(AdRequest.Gender.MALE);
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
// Create the adView
adView = new AdView(this, AdSize.SMART_BANNER, "a151388079e47d1");
} else {
// Create the adView
adView = new AdView(this, AdSize.BANNER, "a151388079e47d1");
}
// Lookup your LinearLayout assuming it's been given
// the attribute android:id="@+id/mainLayout"
LinearLayout layout = (LinearLayout) findViewById(R.id.ad);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(request);
lt = new ArrayList<Stock>();
favQ = new ArrayList<Stock>();
fm = new FavManager(getApplicationContext());
favQ.clear();
favQ.addAll(fm.ritiraFav());
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
lt.clear();
// ////////////
try {
InputStream in = getResources().openRawResource(R.raw.markets3);
if (in != null) {
InputStreamReader tmp = new InputStreamReader(in);
BufferedReader reader = new BufferedReader(tmp);
String str;
String str1 = null;
String str2 = null;
boolean flag = true;
while ((str = reader.readLine()) != null) {
if (flag) {
str1 = str;
flag = false;
} else {
str2 = str;
lt.add(new Stock(str1, str2, "0", "0"));
flag = true;
}
}
in.close();
}
}
catch (Throwable t) {
// Log.e("", "Exception: " + t.toString());
}
// ///////
Collections.sort(lt, new Comparator<Stock>() {
public int compare(Stock s1, Stock s2) {
return s1.nome.compareToIgnoreCase(s2.nome);
}
});
lv = (ListView) findViewById(android.R.id.list);
lv.setScrollbarFadingEnabled(false);
Button favourites = (Button) findViewById(R.id.favoritesbtn);
favourites.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(QuotesActivity.this,
QuotesActivityFavourites.class);
startActivity(intent);
}
});
Button search = (Button) findViewById(R.id.googsearch);
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Log.e("", "Chiamo onSearchRequested()");
onSearchRequested();
}
});
myAdap = new MyAdapter(lt, this, this);
myAdap.l = lt;
lv.setAdapter(myAdap);
Button preference = (Button) findViewById(R.id.preferencebutton);
preference.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(QuotesActivity.this,
SettingsActivity.class);
startActivity(intent);
}
});
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
final int position, long id) {
for (Stock item : favQ) {
if (item.simbolo.equals(lt.get(position).simbolo)) {
AlertDialog.Builder builder = new AlertDialog.Builder(
QuotesActivity.this);
builder.setPositiveButton("Yes", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
deleteFromFavorites(lt.get(position));
}
});
builder.setNegativeButton("No", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Quotes.layoutSchermo(2);
}
});
builder.setMessage("Stock Already in Portfolio. Delete from it?");
builder.setTitle(lt.get(position).nome);
AlertDialog dialog = builder.create();
builder.show();
return;
}
}
AlertDialog.Builder builder = new AlertDialog.Builder(
QuotesActivity.this);
final int pos = position;
builder.setPositiveButton("Yes", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
addToFavorites(lt.get(pos));
}
});
builder.setNegativeButton("No", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Quotes.layoutSchermo(2);
}
});
builder.setMessage("Add to Portfolio?");
builder.setTitle(lt.get(position).nome);
AlertDialog dialog = builder.create();
builder.show();
// dialog.show();
}
});
}
@Override
public void onResume() {
super.onResume();
RelativeLayout focuslayout = (RelativeLayout) findViewById(R.id.RequestFocusLayout);
focuslayout.requestFocus();
favQ.clear();
favQ.addAll(fm.ritiraFav());
}
public void addToFavorites(final Stock toadd) {
fm.addFav(toadd);
favQ.clear();
favQ.addAll(fm.ritiraFav());
return;
}
public void deleteFromFavorites(Stock todel) {
fm.removeFav(todel);
favQ.clear();
favQ.addAll(fm.ritiraFav());
return;
}
public void UpdateLine(Integer position) {
UpdateTask up = new UpdateTask();
up.execute(position, null, null);
}
public class UpdateTask extends AsyncTask<Integer, Void, Void> {
@Override
protected void onProgressUpdate(Void... progress) {
}
@Override
protected void onPostExecute(Void result) {
myAdap.l = lt;
myAdap.notifyDataSetChanged();
}
@Override
protected Void doInBackground(Integer... position) {
DefaultHttpClient client = new DefaultHttpClient();
String srt = "";
// ///////////API SEGRETO DI GOOGLE ORIGINARIO
// String url
// =getString(R.string.dettaglio1).concat("'"+fav.get(i).simbolo+"'").concat(getString(R.string.dettaglio2));
// ///////////API ALTERNATIVO
String url = getString(R.string.urlaternativo).concat(
lt.get(position[0]).simbolo);
HttpGet getMethod = new HttpGet(url);
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
srt = client.execute(getMethod, responseHandler);
int inizio = srt.indexOf("<last data=\"");
int fine = srt.indexOf("\"/>", inizio + 12);
lt.get(position[0]).setPrezzo(srt.substring(inizio + 12, fine));
inizio = srt.indexOf("<perc_change data=\"");
fine = srt.indexOf("\"/>", inizio + 19);
lt.get(position[0]).setCambiamento(
srt.substring(inizio + 19, fine));
} catch (Throwable t) {
// Log.e("ERRORE INTERNET", "ERRORE INTERNET", t);
}
return null;
}
}
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
これは私のマニフェストです:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.quotes" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:debuggable="true" >
<activity
android:name=".QuotesActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:icon="@drawable/ic_launcher"
android:label="Markets in your pocket !" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value=".QuotesActivitySearch" />
</activity>
<activity
android:name=".QuotesActivitySearch"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:icon="@drawable/ic_launcher"
android:label="Markets in your pocket !" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
<activity
android:name=".QuotesActivityFavourites"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:icon="@drawable/ic_launcher"
android:label="Markets in your pocket !" >
</activity>
<activity
android:name=".SettingsActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:label="Settings" >
</activity>
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
これは私のLogCatです:
03-15 14:16:05.554: D/dalvikvm(1466): GC_EXPLICIT freed 909K, 43% free 4716K/8135K, external 1170K/1682K, paused 7ms
03-15 14:16:07.185: E/ActivityThread(1466): Failed to find provider info for com.google.plus.platform
03-15 14:16:07.185: D/szipinf(1466): Initializing inflate state
03-15 14:16:07.185: D/szipinf(1466): Initializing zlib to inflate
03-15 14:16:07.214: I/Ads(1466): To get test ads on this device, call adRequest.addTestDevice("6EA1DCF3A944D7B947BC304C7A9E933D");
03-15 14:16:07.268: D/dalvikvm(1466): GC_CONCURRENT freed 395K, 36% free 5315K/8263K, external 1121K/1603K, paused 1ms+0ms
03-15 14:16:07.290: I/Ads(1466): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script> <script>AFMA_getSdkConstants();AFMA_buildAdURL({"preqs":3,"session_id":"1145804483122245265 2","seq_num":"4","slotname":"a151388079e47d1","u_w":320,"msid":"com.marketsinyourpocket","cap":"m,a","js":"afma-sdk-a- v6.3.0","bas_off":0,"net":"ed","app_name":"1.android.com.marketsinyourpocket","hl":"en","gnt":3,"cust_gender":1,"carrier":"310260","u_audio":1,"u_sd":1.5,"ms":"Qqlgt9Kwv7BZOnio6PfLHi5mVs5ayp77VGIIyJ3Y7sojTNwIZfi0LHn2PZquoJTqpJx8NtOvTzGKWYlbxvU8fOjXkArCoqoQnGrLKZ57CTZOOt2WWrL9k8pyN4P-nBwIvuZDvijR0reHDyhcqwAoMtPdOeUV_cwIe3jk-6BMm_IgvGs8EKWVZESeqrSuExAStQMMsUYcC6p-XkB8KegxEX4FS2Q2CibdMk3CMKoAzfF58Sxp6DvRObm662IVwImzFWGdQ22UVx4ViQqz_ensdg1bXk5jgpyBOpV0jMFHgoEv5SwD5zpoeJfo-a1f0d5GR35f2bDAb3iXucuGB723lA","isu":"6EA1DCF3A944D7B947BC304C7A9E933D","format":"320x50_mb","oar":0,"ad_pos":{"height":0,"visible":0,"y":0,"x":0,"width":0},"u_h":533,"pt":1,"bas_on":0,"ptime":143736});</script></head><body></body></html>
03-15 14:16:07.358: W/webcore(1466): Can't get the viewWidth after the first layout
03-15 14:16:07.448: D/dalvikvm(1466): GC_CONCURRENT freed 338K, 33% free 6141K/9031K, external 1121K/1603K, paused 1ms+0ms
03-15 14:16:13.494: V/URL I USE(1466): http://www.google.com/ig/api?stock=SHY
03-15 14:16:33.614: E/EXCEPTION I GET(1466): java.net.UnknownHostException: www.google.com
編集 編集 編集 編集
API 10 Intel アクセラレーション エミュレータでも試してみましたが、うまくいきませんでした
プロキシが正しく設定されている、
データ転送が有効になっています
…ちょっと必死!
編集 編集 編集
アクティビティ全体を投稿
編集 編集 編集
このアプリは、API 10 を搭載した実際の電話で正しく動作します (API 10 を搭載した私のエミュレータではありません)!!!
私がキャッチするエラーは
03-15 13:14:43.299: E/Exception(1318): java.net.UnknownHostException: www.google.com
実際、私は Google REST サービスを使用しています
ご協力いただきありがとうございます!