我想開發一個Android應用程序,但我真的沒有與它太多的經驗。 目前在App讀取所有的聯繫人信息,如姓名和電話號碼,並將數據寫入到存儲在內部存儲的XML文件。 從Android 4.1到Android 2.2的所有虛擬設備都可以正常工作。我正在使用eclipse。 但現在我想在真實設備上測試它。首先,我將它安裝在帶有Android 4.0的智能手機上。我設法安裝了應用程序並啓動它。該應用程序也寫了文件,但它是空的。之後,我將它安裝在Android 2.3的智能手機上。它也開始了,但我無法找到該文件。我使用AndroXplorer訪問內部存儲。Android應用程序的虛擬設備上運行,但不是真實設備
正如我從來沒有與Android應用工作過,有誰能夠給我一些想法,我怎麼能弄清楚爲什麼應用程序是對所有的虛擬設備,但沒有對以假亂真運行?
在此先感謝!
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create new file
File newxmlfile = new File(this.getFilesDir(), "newcontacts3.xml");
try {
newxmlfile.createNewFile();
} catch (IOException e) {
Log.e("IOException", "Exception in create new File(");
}
FileOutputStream fileos = null;
try {
fileos = new FileOutputStream(newxmlfile);
} catch (FileNotFoundException e) {
Log.e("FileNotFoundException", e.toString());
}
XmlSerializer serializer = Xml.newSerializer();
try {
serializer.setOutput(fileos, "UTF-8");
serializer.startDocument(null, Boolean.valueOf(true));
serializer.setFeature(
"http://xmlpull.org/v1/doc/features.html#indent-output",
true);
serializer.startTag(null, "root");
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String id = cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts._ID));
serializer.startTag(null, "ContactID");
serializer.attribute(null, "ID", id);
// GET ALL THE CONTACT DATA AND WRITE IT IN THE FILE
serializer.endTag(null, "ContactID");
}
}
cursor.close();
serializer.endTag(null, "root");
serializer.endDocument();
serializer.flush();
fileos.close();
} catch (Exception e) {
Log.e("Exception", "Exception occured in wroting");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
我的minSdkVersion是8,目標版本是15 我也加入了對互聯網和讀取聯繫人權限的權限。
當我在虛擬設備上運行它時,應用程序啓動,我的啓動屏幕出現,並在data/data/com.examples.anotherproject/files下創建文件「newcontacs3.xml」。
給我們一些細節。你的'min-sdk'和'target'是什麼? – NewUser
張貼您的清單 – Sathish
@ user1778772張貼更多信息或張貼一些代碼,以便我們可以幫助您更多。 –