顯示具有 Android 標籤的文章。 顯示所有文章
顯示具有 Android 標籤的文章。 顯示所有文章

2014年1月27日 星期一

Developing for Android in Eclipse: R.java not generating

Solution

Make sure that anything the R. links to is not broken. Fix all errors in your XML files. If anything in the ADKs are broken, R will not regenerate.
If you somehow hit something and created import android.R in your activity, remove it.
Run Project -> Clean. This will delete and regenerate R and BuildConfig.
Make sure Project -> Build Automatically is ticked. If not, build it manually via Menu -> Project -> Build Project .
Wait a few seconds for the errors to disappear.
If it doesn't work, delete everything inside the /gen/ folder
If it still doesn't work, try right-clicking your project -> Android Tools -> Fix Project Properties.
Check your *.properties files (in the root folder of your app folder) and make sure that the links in there are not broken.
Right-click your project > properties > Android. Look at the Project Build Target and Library sections on the right side of the page. Your Build Target should match the target in your AndroidManifest.xml. So if it's set to target 17 in AndroidManifest, make sure that the Target Name is Android 4.2. If your Library has an X under the reference, remove and re-add the library until there's a green tick. This might happen if you've moved a few files and folders around.
What to do if R doesn't regenerate

This usually happens when you have a broken xml file.

Check errors inside your XML files, mainly within the /res/ folder
Common places are /layout/ and /values/ especially if you've changed one of them recently
Check AndroidManifest.xml, I find that often I change a string, and forget to change the string name from AndroidManifest.xml.
Check that Android SDK Build-tools is installed. Window->Android SDK Manager->Tools->Android SDK Build-tools
Make sure when you update the Android SDK Tools, you also update the Android SDK Platform-tools and Android ASK Build-tools. Build fails silently if they don't match.
If you can't find the issue, right click /gen/ -> Restore from local history... -> tick R.java -> click Restore. This doesn't solve the problem, but it will clear out the extra errors to make the problem easier to find.
I know there's already a lot of answers here, but this is the main link on Google, so I'm compiling all the advice here and hope it helps someone else new to this :)

android自带的base64编码

首先导入包
import android.util.Base64;
String 变量=android.util.Base64.encodeToString(字符串.getBytes(),Base64.DEFAULT);
也可简写为
String 变量=Base64.encodeToString(字符串.getBytes(),Base64.DEFAULT);
至于解码
byte b[]=android.util.Base64.decode(字符串,Base64.DEFAULT);
String 变量=new String(b);
byte b[]=android.util.Base64.decode(字符串,Base64.DEFAULT);

Export有關android手機的Database

有關android手機的Database (expoortDB.db) 目前可以Export 出來,
方法如下

1 open dos command


2 切換到 android sdk path

  ex: d:
      cd D:\adt-bundle-windows\sdk

3 輸入 adb shell  (確認Phone Device 是連線中狀能)
   ex: adb shell


4  輸入 run-as package-name
  ex: run-as tw.com.test
(ps 在AndriodManifest.xml 找的到pakcage name)

5  輸入 ls  有看到Databases 目錄

6  輸入 cd databases

7  輸入cat expoortDB.db > /sdcard/expoortDB.db

8 再到手機的APPs-> 我的檔案
  找到expoortDB.db 用分享經由 ( Gmail or 雲端硬碟) 把檔案滙出

9 由7~8 把想要的檔案滙出





再用SQLite Database Browser 軟体(free) 即可以看內容的Table 結構及資料

2014年1月20日 星期一

[Android]使用DDMS匯出sqlite資料庫

在Android中可以使用Eclipse外掛程式DDMS來查看,也可以使用Android工具包中的adb工具來查看。android專案中的sqlite資料庫位於/data/data/專案包/databases中。

使用DDMS匯出sqlite資料庫。
1、首先打開android專案的調試模式,然後找到顯示DDMS:
2011032809372684.png 

選擇DDMS
2011032809375743.png 

2、切換到DDMS,顯示File Explorer視窗,找到/data/data/
2011032809381481.png 

然後找到套裝程式的資料夾,打開databases,就能看到sqlite資料庫檔了。選擇將其匯出。

2011032809391535.png 
這樣就把sqlite資料庫檔以檔的方式匯出來了,然後使用sqlite介面管理工具如sqlite administrator、sqlite man或者firefox外掛程式sqlite manager等打開就可以了。

使用adb工具訪問sqlite資料庫

Android Debug Bridge(ADB)是Android的一個通用調試工具,它可以更新設備或模擬器中的代碼,可以管理預定埠,可以在設備上運行shell命令,我們知道android是基於Linux內核,它的內部檔結構也是採用linux檔組織方式,因此訪問它的檔結構需要使用shell。這次我們就會用shell來訪問android應用中的sqlite資料庫檔。

1、運行cmd,切換到android-sdk目錄,運行adb.exe,加上參數shell,出現#號就代表進入了shell命令模式,注意adb要在Android模擬器運行時才能進入shell:
2011032820381230.png 

2、shell命令記住兩個基本命令ls和cd,類似windows命令提示行中的dir和cd,代表列出目前的目錄下檔清單和進入到指定目錄。瞭解這兩個命令之後,就可以找到data/data/專案包名/databases:
2011032820435789.png 

找到資料庫檔:
2011032820464044.png 

接下來就是使用sqlite管理工具來進行操作了。鍵入sqlite3 資料庫名就進入了sqlite管理模式了。
2011032820531792.png 

在android的sdk中自帶了sqlite3.exe,這是sqlite的官方管理工具,它是一個命令列工具。為了使用方便,將其路徑註冊到系統環境變數path中,即將;%Android_Home%加在Path中,這樣只樣運行sqlite3,就能直接打開sqlite管理工具了。
2011032820505087.png 

sqlite管理資料庫篇
sqlite命令列工具預設是以;結束語句的。所以如果只是一行語句,要在末尾加;,或者在下一行中鍵入;,這樣sqlite命令才會被執行。

sqlite常用命令:

.tables--查看資料庫的表清單

.exit--退出sqlite命令列

其他命令可隨時.help查看説明。sql命令可直接在此命令列上執行即可:
2011032821043382.png