搜尋此網誌

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

2014年9月20日 星期六

[問題] 解決 Eclipse 新建Android Project 專案時出現 Errors running builder 'Android Resource Manager' on project '專案名稱'


最近入手2014  MacBookPro Retina,在建置android 開發專案時碰到了下列狀況

1.create android project 出現 Errors running builder 'Android Resource Manager' on project '專案名稱'

2.Project has no default.properties file! Edit the project properties to set one.

原因:
我使用的 eclipse 是 Kepler,在安裝Google ADT Plugin發現eclipse Marketplace 有提供於是我就安裝了,悲劇開始

解決方法:
用Install new software方式安裝,開新專案後,該自動產生的檔案都產生了
https://dl-ssl.google.com/android/eclipse/





2012年7月13日 星期五

[問題] import jar 檔

我是在 ADT Plugin 20 才發現這個問題的,也許這已經改很久只是我不知道

最近新開的一個 Android Project  因為要 import jar 所以從 Java Bulid Path 中的 Libraries tab 中的

Add JARs , 來 import jar 檔

但在執行過程中會發生 java.lang.NoClassDefFoundError 這個問題

找了很久,一直找不到問題出在那,後來發現新增了一個 "libs"的資料夾

於是我試著把要 import 的 jar 要放到這裡面,結果就可以了正常執行




2011年4月12日 星期二

[Android] 使用 getResources 讀取 res/ 下的檔案(ex: .jpg or .xml)

把資源檔案放到eclipse android專案的/res/drawable下,那麼就可以在程式中使用getResources,以openRawResource方法讀取在/res/drawable/view_1.jpg,經過R.java編碼後會以R.drawable.view_1來代表view_1.jpg

下面這個範例是,利用InputStream讀取/res/drawable/view_1.jsp,轉存成rename.jsp到/sdcard下面

InputStream is = getResources().openRawResource(R.drawable.view_1);
File myTempFile = new File("/sdcard/", "rename.jpg");
 
FileOutputStream fos = new FileOutputStream(myTempFile);
 
byte buf[] = new byte[1024];
 
do {
 
  int numread = is.read(buf);
  if (numread <= 0) {
    break;
  }
  fos.write(buf, 0, numread);
 
} while (true);

is.close();

2011年4月11日 星期一

[Android] 發送簡訊sms含Receiver

//---sends a SMS message to another device---
public void sendSMS(String phoneNumber, String message){      
     
   String SENT = "SMS_SENT";
   String DELIVERED = "SMS_DELIVERED";
     
   PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
        
   PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);
     
   //---when the SMS has been sent---
   registerReceiver(new BroadcastReceiver(){
   @Override
   public void onReceive(Context arg0, Intent arg1) {
    switch (getResultCode()){
    
        case Activity.RESULT_OK: //傳送成功
         Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).show();
         break;
         

[Android] Android下使用 Properties 來當設定檔始使用

需要import下面這些class
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

讀取Properties,如果properties傳回null代表檔案不存在
public Properties loadConfig(Context context, String file) {
  Properties properties = null;
  
  try {
   
   File f = new File(file);
   
   if(f.exists()){    
    FileInputStream fis = new FileInputStream(file); 
    properties = new Properties();
    properties.load(fis); 
   }
   
  } catch (Exception e) {
   Log.e(TAG, e.getMessage(), e);   
  }
  
  return properties;
 }

2011年3月17日 星期四

[Android] Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE

在 Eclipse 啟動Android 程式要在實體機器執行時, 出現以下訊息

[2011-03-17 10:57:52 - Sarina] Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE
[2011-03-17 10:57:52 - Sarina] Please check logcat output for more details.
[2011-03-17 10:57:52 - Sarina] Launch canceled!

解決方式: 設定 => 應用程式 => 管理應用程式, 將該程式先手動移除, 在重新發佈即可

2010年12月29日 星期三

[Android] 檢測網路是否存在

使用下面的判斷網路是否存在,需先加入一個permission


<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>

ConnectivityManager connManager =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connManager.getActiveNetworkInfo(); if (info == null || !info.isConnected()) { //網路沒有連線 } else { if (!info.isAvailable()) { //網路沒有連線 } else { //網路連線 } }

2010年12月27日 星期一

[Android] adb 檔案位置

adb.exe 新位置 <sdk>/platform-tools/
<sdk>為 android-sdk-windows 目錄位置

2010年11月26日 星期五

[Android] 讓 Activity 全螢幕的方法

import android.view.Window;
import android.view.WindowManager;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    //應用程式的Title(名稱)
    requestWindowFeature(Window.FEATURE_NO_TITLE);   
    //Android 的系統狀態列 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                           WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.viewer);

    .......................
}

2010年11月18日 星期四

[Android]標題欄進度指示器使用方法

瀏覽器在載入網頁時等待時間可能會在標題欄的右上角有一個小圓圈在不斷旋轉,其不包含具體進度
作為標題欄進度指示器其實屬於Activity類的方法,在使用時我們首先需要在setContentView之前聲明requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
在需要顯示進度時用setProgressBarIndeterminateVisibility(true);
停止時用setProgressBarIndeterminateVisibility(false);


import android.view.Window;
import android.view.WindowManager;

@Override
public void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);

   //顯示標題欄進度指示器
   requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

   //需要顯示進度時用 true 停止時用 false
   setProgressBarIndeterminateVisibility(true);

   setContentView(R.layout.viewer);

   .......................
}


來源http://zhuyonghui116.blog.hexun.com.tw/48417668_d.html

2010年11月12日 星期五

[Android] uses-permission 備註

AndroidManifest.xml 的 uses-permission 意義

頭尾是用"<"uses-permission">"包起來

android:name=”android.permission.INTERNET”
允許程式存取 internet

android:name="android.permission.ACCESS_NETWORK_STATE"
照字面的意思應該是允許程式存取網路的狀態吧!

android:name="android.permission.RESTART_PACKAGES"
以經不被支援了(This constant is deprecated. The restartPackage(String) API is no longer supported)
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
(Allows mounting and unmounting file systems for removable storage.)
允許安裝和卸載在可移動存儲設備上吧

android:name="android.permission.WRITE_EXTERNAL_STORAGE"
寫入外部的儲存設備(應該是指SD Card)

android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"
(Allows an application to change whether an application component (other than its own) is enabled or not.)
允許一個程式是否改變一個組件或其他的啟用或禁用

android:name="android.permission.WRITE_CONTACTS"
(Allows an application to write (but not read) the user's contacts data.)
允許這個AP寫入(但不會讀出)用戶的聯絡人

android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"
(Allows an application to access extra location provider commands)
允許應用程式訪問額外的位置提供命令

標籤