Android實習筆記----調用撥號器,郵件短信和Google 地圖

  1. ./adb -s MX1CA16BLCYPDA1959 shell     當有多個調試設備時需要用s選項指定設備
  2. 在使用ImageView時要注意到android:srcandroid:background的不同, 前者可以在保持比例的條件下調整圖像,後者則會使圖像變形以完全充滿背景;android:scaleType可以設置圖像的調整方式,如居中或者全部填充等;android:adjustViewBounds=true可以使imageview調整自己的邊界去適應圖像
  3. 在Android下調用撥號程序或Google地圖等比想象的要容易很多,使用Intent即可;
Intent geoIntent = new Intent(Intent.ACTION_VIEW);
geoIntent.setData(Uri.parse('geo:0,0?q=你的地址"));
try{startActivity(geoIntent);
} catch(ActivityNotFoundException e) {
    Toast.makeText(GeneratorActivity.this,R.string.noMapException, Toast.LENGTH_SHORT).show();
}


參見這一網頁

http://developer.android.com/guide/appendix/g-app-intents.html

其他的操作如調用email,電話,短信等也基本同理,並不複雜:

//action="http://www.baidu.com";                //action="tel:df1234";                //action="sms:12334";                //action="mail:[email protected]";                //action="geo:48.849242,2.293024";                //action="geo: Société Néréide, 3b Les Isles 37270 Veretz, France";                if(action != null ) {                        if(action.startsWith("tel:")){                            Intent callIntent = new Intent(Intent.ACTION_DIAL);                            callIntent.setData(Uri.parse(action));                            startActivity(callIntent);                        }else if(action.startsWith("sms:")){                             Intent callIntent = new Intent(Intent.ACTION_SENDTO);                            callIntent.setData(Uri.parse(action));                            startActivity(callIntent);                        }else if (action.startsWith("mail:")){                            Intent emailIntent = new Intent(Intent.ACTION_SEND);                             emailIntent.setType("message/rfc822");                            emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{action.substring(5)} );                             emailIntent.putExtra(Intent.EXTRA_SUBJECT, "my subject");                             emailIntent.putExtra(Intent.EXTRA_TEXT, "body text");                             try {                                startActivity(Intent.createChooser(emailIntent, "Send mail..."));                            } catch (android.content.ActivityNotFoundException ex) {                                Toast.makeText(GeneratorActivity.this, R.string.noEmailClientException, Toast.LENGTH_SHORT).show();                            }                        }                        else if (action.startsWith("geo")){                            if( !action.startsWith("geo:0,0?q=")) {                                action = action.replaceFirst("geo:", "geo:0,0?q=");                            }                            Log.d(TAG, action);                            Intent geoIntent = new Intent(Intent.ACTION_VIEW);                            geoIntent.setData(Uri.parse(action));                            try{startActivity(geoIntent);                            } catch(ActivityNotFoundException e) {                                Toast.makeText(GeneratorActivity.this,                                         R.string.noMapException, Toast.LENGTH_SHORT).show();                            }                        }



發佈了73 篇原創文章 · 獲贊 101 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章