目前分類:Android筆記 (435)

瀏覽方式: 標題列表 簡短摘要
Toast.makeText(Contantus.this, "請輸入投訴人", Toast.LENGTH_SHORT).show();

戮克 發表在 痞客邦 留言(0) 人氣()

final private String prefName = "GGHH";
宣告
SharedPreferences settings = Login_Activity.this.getSharedPreferences(prefName, Context.MODE_PRIVATE);                            
寫入
settings.edit().putString("login", "Yes").commit();
settings.edit().putString(KEY可以想像成變數名稱, 變數值).commit();
讀取
String login = settings.getString("login", "No");
String login = settings.getString(KEY可以想像成變數名稱 ,預設值若APP無此變數回傳得到預設值);

戮克 發表在 痞客邦 留言(0) 人氣()


 1
2
3
4
5
6
7
8
9

戮克 發表在 痞客邦 留言(0) 人氣()

a=10  b=3
int sum1=a/b;
int sum1=a%b;

sum1=3;
sum1=1;

戮克 發表在 痞客邦 留言(0) 人氣()

權限:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
程式碼:
 ConnectivityManager CM = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = CM.getActiveNetworkInfo();
if (info == null || !info.isAvailable()){ //判斷是否有網路
new AlertDialog.Builder(this)
.setMessage("沒")
.show();
}else{

戮克 發表在 痞客邦 留言(0) 人氣()


 1
2
3
4
5
6
7
8
9

戮克 發表在 痞客邦 留言(0) 人氣()

Java呼叫系統相機


callsystemcaream.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {

Log.d("ANDRO_CAMERA", "Starting camera on the phone...");
String fileName = "testphoto.jpg";
ContentValues values = new ContentValues();

戮克 發表在 痞客邦 留言(0) 人氣()

class ItemClickListener implements OnItemClickListener {   
        public void onItemClick(AdapterView<?> arg0,View arg1,int arg2,long arg3){   

                if(arg0.getId()==R.id.gridviewindex){
       
        }else if(arg0.getId()==R.id.gridviewindex02 ){
        
        }

戮克 發表在 痞客邦 留言(0) 人氣()

今天剛安裝完android studio 執行出現
Android studio was unable to find a valid JVM
最後發現是設定檔案預設的JDK1.6版
我電腦是1.8版本
解決方式是到ECLIPSE目錄下
開啟Info.plist檔案
修改JVMVersion屬性...把它改成跟你電腦相同的版本就可以執行了

戮克 發表在 痞客邦 留言(0) 人氣()

權限有些資訊需要加權限才有辦法獲得
<uses-permission android:name="android.permission.READ_PHONE_STATE" />




import android.os.Build;   // 主機版名稱 String board = Build.BOARD;   // 品牌名稱 String brand = Build.BRAND;   // CPU + ABI String cpu = Build.CPU_ABI;   // 設備名稱 String device = Build.DEVICE;   // 版本號碼 String display = Build.DISPLAY;   // 設備識別碼 String fingerprint = Build.FINGERPRINT;   // HOST String host = Build.HOST;   // 版本號碼 String id = Build.ID;   // 製造商 String manufacturer = Build.MANUFACTURER;   // 模組號碼 String model = Build.MODEL;   // 產品名稱 String product = Build.PRODUCT;   // 設備描述 String tags = Build.TAGS;   // 設備類別; user or eng String type = Build.TYPE;   // USER String user = Build.USER;



戮克 發表在 痞客邦 留言(0) 人氣()

首先加權限
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

程式碼參考如下:

TelephonyManager mTelManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

//取得手機號碼 ,因哭狗隱私政策問題現在無法獲取只會得到null
String mNumber = mTelManager.getLine1Number();

戮克 發表在 痞客邦 留言(0) 人氣()

public static Bitmap getBitmapFromURL(String src) {
   try {
       URL url = new URL(src);
       HttpURLConnection connection = (HttpURLConnection) url.openConnection();
       connection.setDoInput(true);
       connection.connect();
       InputStream input = connection.getInputStream();
       Bitmap myBitmap = BitmapFactory.decodeStream(input);
       return myBitmap;
   } catch (IOException e) {

戮克 發表在 痞客邦 留言(0) 人氣()

OnItemClickListener itemListener = new OnItemClickListener() {
   
       @Override
       public void onItemClick(AdapterView<?> parent, View view,
               int position, long id) {
    Intent intent = new Intent(getActivity(), GCMMessageView.class);
    intent.putExtra("message",URLS[ position]);
    startActivity(intent);
       }
    };

戮克 發表在 痞客邦 留言(0) 人氣()



未解決之前問題可能的方法
在<application>裡面
加上android:largeHeap="true"
有圖檔處理過大或其他原因發生OOM的朋友試試看吧

缺點:系統所沛羽的空間越大,在GC(資源回收)上會越慢。

說明___________________________________________________________________________
android:largeHeap
Whether your application's processes should be created with a large Dalvik heap. This applies to all processes created for the application. It only applies to the first application loaded into a process; if you're using a shared user ID to allow multiple applications to use a process, they all must use this option consistently or they will have unpredictable results.
Most apps should not need this and should instead focus on reducing their overall memory usage for improved performance. Enabling this also does not guarantee a fixed increase in available memory, because some devices are constrained by their total available memory.
To query the available memory size at runtime, use the methods getMemoryClass() orgetLargeMemoryClass().

戮克 發表在 痞客邦 留言(0) 人氣()

import dalvik.system.VMRuntime;
這方法可以直接設定ANDROID
但在"android SDK API 9"之後版本就刪掉了"無法使用"...
之後的版本要使用需引用額外的JAR
至於要引入哪了還在測試


最後發現可以試試這個android:largeHeap="true"

戮克 發表在 痞客邦 留言(0) 人氣()

發生原因是照片的解析度太好檔案太大,導致記憶體不足。壓縮圖檔就可以解決...但我目前正在嘗試不壓縮的方法還在研究。


錯誤訊息----------------------------------------------------------------
FATAL EXCEPTION: main
Process: com.global_trade.iFeet01, PID: 18793
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)

戮克 發表在 痞客邦 留言(0) 人氣()

android最討厭的東西就是只要是使用到硬體相關的程式碼,經過不同版本的SDK或手機廠商就可能會出錯甚至是死當。今天寫一個APP使用到拍照功能的程式泡了HTC ONE  、SONY  Z、小米NOTE都沒事在三星的NOTE 4跑當了跑出以下錯誤。

最後解決方式是參考別人寫的
刪掉這段程式碼
parameters.setPictureSize(mPreviewSize.width, mPreviewSize.height);

去掉之後都可以順利執行了。是否會再遇到其他機種執行當掉的問題...有遇到再說了


錯誤訊息-------------------------------------------------------

戮克 發表在 痞客邦 留言(0) 人氣()

今天使用JAVA要呼叫WEBVIEW上的javascript時出現
錯誤訊息:
Uncaught ReferenceError: sumToJava is not defined at null:1
但是我有定義了sumToJava的javascript函式

原因是網頁尚未載入完成
因而導致找不到javascript凾式
解決方式等待網頁載入完成,可以使用載入完成來啟動
myBrowser.setWebViewClient(new WebViewClient() {

戮克 發表在 痞客邦 留言(0) 人氣()

如果一個Activity開啟新的必且等待他要回傳的值那寫法如下

M0101要呼叫M0102並等待他回傳值要使用startActivityForResult並且宣告onActivityResult來處理Activity返回時所帶的參數

startActivityForResult(intent, 給Activity一個編號型態為int);
當值回傳再以requestCode來判斷.



呼叫M0102的寫法
Intent intent = new Intent(M0101.this, M0102.class);
// intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

戮克 發表在 痞客邦 留言(0) 人氣()

路徑格式如下
file:///android_asset/mobileWeb/index.html
要注意的是asset下的資料夾不能有 "   _  " 字元,不然系統會無法讀取。

戮克 發表在 痞客邦 留言(0) 人氣()