Android小知识集合
总结一些
Android
方面的调用,会不断的持续更新这个文章
系统调用
拨打电话
1.权限
<uses-permission android:name="android.permission.CALL_PHONE" />
2.拨打电话(直接拨打电话)
/**
* 拨打电话(直接拨打电话)
* @param phoneNum 电话号码
*/
public void callPhone(String phoneNum){
Intent intent = new Intent(Intent.ACTION_CALL);
Uri data = Uri.parse("tel:" + phoneNum);
intent.setData(data);
startActivity(intent);
}
3.拨打电话(跳转到拨号界面,用户手动点击拨打)
/**
* 拨打电话(跳转到拨号界面,用户手动点击拨打)
*
* @param phoneNum 电话号码
*/
public void callPhone(String phoneNum) {
Intent intent = new Intent(Intent.ACTION_DIAL);
Uri data = Uri.parse("tel:" + phoneNum);
intent.setData(data);
startActivity(intent);
}
注解使用
注解替代 Enum Class
注解替代 Enum Class 理由,主要是为了 Save Memory ,过由于在android平台上,枚举占用内存过多的问题,一般不推荐使用枚举
import android.support.annotation.IntDef;
//...
public abstract class ActionBar {
//...
// Define the list of accepted constants and declare the NavigationMode annotation
@Retention(RetentionPolicy.SOURCE)
@IntDef({NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
public @interface NavigationMode {}
// Declare the constants
public static final int NAVIGATION_MODE_STANDARD = 0;
public static final int NAVIGATION_MODE_LIST = 1;
public static final int NAVIGATION_MODE_TABS = 2;
// Decorate the target methods with the annotation
@NavigationMode
public abstract int getNavigationMode();
// Attach the annotation
public abstract void setNavigationMode(@NavigationMode int mode);
}
import android.support.annotation.IntDef
//...
// Define the list of accepted constants and declare the NavigationMode annotation
@Retention(AnnotationRetention.SOURCE)
@IntDef(NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS)
annotation class NavigationMode
// Declare the constants
const val NAVIGATION_MODE_STANDARD = 0
const val NAVIGATION_MODE_LIST = 1
const val NAVIGATION_MODE_TABS = 2
abstract class ActionBar {
// Decorate the target methods with the annotation
// Attach the annotation
@get:NavigationMode
@setparam:NavigationMode
abstract var navigationMode: Int
}