Android实现资料收藏

1,调web浏览器
Uri myBlogUri = Uri.parse("http://xxxxx.com");
returnIt = new Intent(Intent.ACTION_VIEW, myBlogUri);
2,地图
Uri mapUri = Uri.parse("geo:38.899533,-77.036476");
returnIt = new Intent(Intent.ACTION_VIEW, mapUri);
3,调拨打电话界面
Uri telUri = Uri.parse("tel:100861");
returnIt = new Intent(Intent.ACTION_DIAL, telUri);
4,直接拨打电话
Uri callUri = Uri.parse("tel:100861");
returnIt = new Intent(Intent.ACTION_CALL, callUri);
5,卸载
Uri uninstallUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri);
6,安装
Uri installUri = Uri.fromParts("package", "xxx", null);
returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);
7,播放
Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");
returnIt = new Intent(Intent.ACTION_VIEW, playUri);
8,掉用发邮件
Uri emailUri = Uri.parse("mailto:xxxx@gmail.com");
returnIt = new Intent(Intent.ACTION_SENDTO, emailUri);
9,发邮件
returnIt = new Intent(Intent.ACTION_SEND);
String[] tos = { "xxxx@gmail.com" };
String[] ccs = { "xxxx@gmail.com" };
returnIt.putExtra(Intent.EXTRA_EMAIL, tos);
returnIt.putExtra(Intent.EXTRA_CC, ccs);
returnIt.putExtra(Intent.EXTRA_TEXT, "body");
returnIt.putExtra(Intent.EXTRA_SUBJECT, "subject");
returnIt.setType("message/rfc882");
Intent.createChooser(returnIt, "Choose Email Client");
10,发短信
Uri smsUri = Uri.parse("tel:100861");
returnIt = new Intent(Intent.ACTION_VIEW, smsUri);
returnIt.putExtra("sms_body", "yyyy");
returnIt.setType("vnd.android-dir/mms-sms");
11,直接发邮件
Uri smsToUri = Uri.parse("smsto://100861");
returnIt = new Intent(Intent.ACTION_SENDTO, smsToUri);
returnIt.putExtra("sms_body", "yyyy");
12,发彩信
Uri mmsUri = Uri.parse("content://media/external/images/media/23");
returnIt = new Intent(Intent.ACTION_SEND);
returnIt.putExtra("sms_body", "yyyy");
returnIt.putExtra(Intent.EXTRA_STREAM, mmsUri);
returnIt.setType("image/png");
最后一步:
startActivity(returnIt)

如何把Button或者ImageButton的背景设为透明或者半透明?
android:background=”@android:color/transparent”
or
android:background="@null"
or
半透明<Button android:background="#e0000000"/>
透明<Button android:background="#00000000"/>

如何在TextView显示HTML?
TextView tv=(TextView)findViewById(R.id.tv);
Spanned text = Html.fromHtml("<a href='http://www.baidu.com'>baidu</a>");
tv.setText(text);
如果html中有图片,请参考这篇文章:
http://da-en.iteye.com/blog/712415


如何修改软键盘默认为数字输入?
EditText editText = (EditText) findViewById(R.id.et);
editText.setInputType(InputType.TYPE_CLASS_NUMBER); 

13.如何阻止EditText自动弹出输入法? 
editText.setOnTouchListener(new OnTouchListener() {  
                  
    public boolean onTouch(View v, MotionEvent event) {  
      
        //记住EditText的InputType现在是password   
        int inType = editText.getInputType(); // backup the input type  
        editText.setInputType(InputType.TYPE_NULL); // disable soft input      
        editText.onTouchEvent(event); // call native handler      
        editText.setInputType(inType); // restore input type     
        editText.setSelection(editText.getText().length());  
        return true;  
                      
    }  
});  

14.如何自定义标题栏? 
    //首先需要请求对FEATURE_CUSTOM_TITLE操作  
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  
    view = new SnakeView(this);  
    setContentView(view);  
    //然后设置  
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);  
R.layout.title对应的布局文件: 
    <?xml version="1.0" encoding="UTF-8"?>  
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:orientation="horizontal"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"     >  
        <TextView  
        android:id="@+id/title"  
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content"  
        android:layout_weight="1"  
        android:layout_gravity="center"  
        android:gravity="center"   
        android:text="Snake"  
        android:textColor="@color/red"  
        />  
    </LinearLayout>  
这里需要注意,最好不要修改背景色,否则会出现标题栏不会被充满的问题(会露马脚啦:)),如果确实需要修改背景色又不漏马脚,那么请看这篇文章:
http://www.iteye.com/topic/760314 

15.如何隐藏标题栏?
即:应用程序名称的那一栏 
    //注意:2行代码的先后顺序不能颠倒  
    requestWindowFeature(Window.FEATURE_NO_TITLE);  
    setContentView(R.layout.main);  
    //同时使用隐藏状态栏可以使可视面积最大化!  
    或者也可以在Manifest文件中这样设置:  
    <application android:icon="@drawable/icon"  
      android:label="@string/app_name"  
      android:theme="@android:style/Theme.NoTitleBar">
一、如何控制Android  LED等?(设置NotificationManager的一些参数) 代码如下:
final int ID_LED=19871103;   
NotificationManager nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);  
Notification notification = new Notification();   
notification.ledARGB = 0xFFFFFF;  //这里是颜色,我们可以尝试改变,理论上0xFF0000是红色,0x00FF00是绿色  
notification.ledOnMS = 100;   
notification.ledOffMS = 100;   
notification.flags = Notification.FLAG_SHOW_LIGHTS;   
nm.notify(ID_LED, notification);   
nm.cancel(ID_LED);

如何获取APK文件安装时间?
很多Android开发者想设计一个APK管理程序,获取APK文件的安装日期很多网友不是很明白。在早期Android123使用的方法是通过 PackageManager类的getInstalledApplications方法返回一个ApplicationInfo数 组,ApplicationInfo类中sourceDir可以获取APK的文件路径,从而使用File类读取文件的上次修改时间而实现。但这可能导致:
1. 无法获取原始的创建时间,可能很早就被创建了,之后被替换了。
2. 如果这个APK在一个私有的位置,比如app-private目录,使用Market付费购买的应用在这个位置,如果没有Root的Android手机是没有权限读取的,也导致获取时间失败。
在Android 2.3 API Level为9中,ApplicationInfo类新增的firstInstallTime和lastUpdateTime这两个字段,可以直接获取到APK的创建或上次修改的时间,即使是付费软件也能正常的获取。

如何区别单位px和dp以及sp?
px (pixels)像素 -- 一般我们HVGA代表320x480像素,这个用的比较多。
dip或dp (device independent pixels)设备独立像素 -- 这个和设备硬件有关,一般我们为了支持WVGA、HVGA和QVGA cwj推荐使用这个,不依赖像素。
sp (scaled pixels — best for text size)放大像素-- 主要处理字体的大小。
下面的几个是不常用的,大家也知道这里android123就不再过多的赘述。
in (inches)英寸
mm (millimeters)毫米 
pt (points)点


二、如何动态改变ImageView大小?
很多网友可能发现在layout.xml文件中定义了ImageView的绝对大小后,无法动态修改以后的大小显示,其实Android平台在设 计UI控件时考虑到这个问题,为了适应不同的Drawable可以通过在xml的相关ImageView中加入 android:scaleType="fitXY" 这行即可,但因为使用了缩放可能会造成当前UI有所变形。使用的前提是限制ImageView所在的层,可以使用一个内嵌的方法限制显示。

三、如何在Android中最简单的播放GIF动画?
GIF动画的原理就是逐帧播放,在Android中提供了AnimationDrawable类可以实现,有的网友写过GIF89A的解码方法在 过去的J2ME平台移植到Android平台也能用,其实在Google Android上面开发目前2.2以后的固件支持的方法除了Flash Player外,更好的兼容方法就是使用万能的webkit浏览器了,我们直接在工程中内嵌一个webView,html中只要写上类似img src="http://android123.com.cn/cwj.gif" 这样的就可以了,当然了路径大家可以换成本地的,对于浏览器使用本地资源url为file://开头。 不过webView的资源消耗也不小,开个webView对象可能占用了至少8MB的RAM吧,保守估计,当然更多的要看插件和以及html的复杂程度所 决定的。

四、如何判断手机有无网络?


    ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);  
            if (cwjManager.getActiveNetworkInfo() != null) {  
                if (cwjManager.getActiveNetworkInfo().isAvailable()) {  
                    String type = cwjManager.getActiveNetworkInfo().getTypeName();  
                    System.out.println("_____________________-" + type);  
                }  
                ;  
            }else {  
                System.out.println("_____________________-" + cwjManager.getActiveNetworkInfo());  
            }  



如果拟开发一个网络应用的程序,首先考虑是否接入网络,在Android手机中判断是否联网可以通过 ConnectivityManager 类的isAvailable()方法判断,首先获取网络通讯类的实例,使用 cwjManager.getActiveNetworkInfo().isAvailable(); 来返回是否有效,如果为True则表示当前Android手机已经联网,可能是WiFi或GPRS、HSDPA等等,具体的可以通过 ConnectivityManager 类的getActiveNetworkInfo() 方法判断详细的接入方式,需要注意的是有关调用需要加入<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> 这个权限,在真机上Market和Browser程序都使用了这个方法,来判断是否继续,同时在一些网络超时的时候也可以检查下网络连接是否存在,以免浪 费手机上的电力资源。

 

五、drawable- hdpi、drawable- mdpi、drawable-ldpi的区别:
在之前的版本中,只有一个drawable,而2.1版本中有drawable-mdpi、drawable-ldpi、drawable-hdpi三个,这三个主要是为了支持多分辨率。
(1)drawable-hdpi里面存放高分辨率的图片,如WVGA (480x800),FWVGA (480x854)
(2)drawable-mdpi里面存放中等分辨率的图片,如HVGA (320x480)
(3)drawable-ldpi里面存放低分辨率的图片,如QVGA (240x320)
    系统会根据机器的分辨率来分别到这几个文件夹里面去找对应的图片。在开发程序时为了兼容不同平台不同屏幕,建议各自文件夹根据需求均存放不同版本图片。
原文地址:https://www.cnblogs.com/tyjsjl/p/3267181.html