android学习笔记Word文档格式.docx

上传人:b****5 文档编号:16884759 上传时间:2022-11-26 格式:DOCX 页数:31 大小:723.60KB
下载 相关 举报
android学习笔记Word文档格式.docx_第1页
第1页 / 共31页
android学习笔记Word文档格式.docx_第2页
第2页 / 共31页
android学习笔记Word文档格式.docx_第3页
第3页 / 共31页
android学习笔记Word文档格式.docx_第4页
第4页 / 共31页
android学习笔记Word文档格式.docx_第5页
第5页 / 共31页
点击查看更多>>
下载资源
资源描述

android学习笔记Word文档格式.docx

《android学习笔记Word文档格式.docx》由会员分享,可在线阅读,更多相关《android学习笔记Word文档格式.docx(31页珍藏版)》请在冰豆网上搜索。

android学习笔记Word文档格式.docx

*@paramenableturewillbeenableaapp,falsewillbedisableaapp

*@describeenable/disablesomeapplication

*/

privatebooleanenableApp(Contextctx,StringpName,booleanenable){

booleanrslt=false;

try{

Log.d(ctx.getClass().getSimpleName()+"

pmenableapp:

"

+pName+"

"

+enable);

inttargetState;

if(enable){

targetState=PackageManager.COMPONENT_ENABLED_STATE_ENABLED;

}else{

targetState=PackageManager.COMPONENT_ENABLED_STATE_DISABLED;

}

intnewState=pm.getApplicationEnabledSetting(pName);

if(newState!

=targetState){

pm.setApplicationEnabledSetting(pName,targetState,PackageManager.DONT_KILL_APP);

Log.d(ctx.getClass().getSimpleName()+"

newState=pm.getApplicationEnabledSetting(pName);

if(newState==targetState){

rslt=true;

}catch(Exceptione){

returnrslt;

3获取app的签名信息

PackageInfofromPageInfo;

fromPageInfo.signatures[i].toCharsString()

4网络判断

*checknetworkisactiveornot,Threadwillbenotwait

*@return

publicstaticbooleannetWorkConnectCheck(Contextctx){

booleanrslt=false;

ConnectivityManagerconnectivityManager=

(ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfoactiveNetInfo=connectivityManager.getActiveNetworkInfo();

if(activeNetInfo!

=null){

rslt=true;

Log.d("

ActiveNetworkType:

"

+activeNetInfo.getTypeName());

}else{

Networkclosed"

);

returnrslt;

publicstaticbooleancheckURLReachable(StringURL){

URLurl=newURL(URL);

HttpURLConnectionurlc=(HttpURLConnection)url.openConnection();

urlc.setConnectTimeout(5000);

//mTimeoutisinseconds

urlc.connect();

if(urlc.getResponseCode()==200){

rslt=true;

}

}catch(Exceptione){

Log.d("

can'

tReachable:

+URL);

}

}

【注意】还有Android系统自带API可以进行判断;

5单例实现

publicstaticGetTokenSynObjTYgetInstance(){

if(instance==null){

synchronized(GetTokenSynObjTY.class){

if(instance==null)

instance=newGetTokenSynObjTY();

returninstance;

6System权限获取

1.在应用程序的AndroidManifest.xml中的manifest节点中加入android:

sharedUserId="

android.uid.system"

这个属性。

2.使用eclipse编译出apk文件,但是这个apk文件是不能用的。

3.用压缩软件打开apk文件,删掉META-INF目录下的CERT.SF和CERT.RSA两个文件。

4.使用目标系统的platform密钥来重新给apk文件签名。

这步比较麻烦,首先找到密钥文件,在Android源码目录中的位置是"

build/target/product/security"

,下面的platform.pk8和platform.x509.pem两个文件。

然后用Android提供的Signapk工具来签名,signapk的源代码是在"

build/tools/signapk"

下,用法为"

java-jarsignapk.jar-wplatform.x509.pemplatform.pk8input.apkoutput.apk"

.

获取地址

文件/android开发笔记/常用组件/SignApk/

7获取APk签名信息工具

Location:

/android开发笔记/常用组件/SignApk_getSigns/

Usage:

java-jarSignatureTool.jarapkpath(Forexample'

C:

\test\test.apk'

8隐藏软键盘

 

if(imm.hideSoftInputFromWindow(this.getWindowToken(), 

0)){ 

·

//imm.showSoftInput(textView,0);

return 

true;

9FlingGallery

可以是图片或者page等等

文件/android开发笔记/常用组件/FlingGallery/

10GalleryFlow

文件/android开发笔记/常用组件/GalleryFlow/

这个Demo实现了类似iOS上面的CoverFlow功能。

主要有两个功能

1,实现图片的倒影效果

2,重写gallery的一些方法实现Y轴上的旋转,Z轴上的缩放。

11AndroidScroller简单用法

文件android开发笔记\常用组件\ScrollerDemo\

Android里Scroller类是为了实现View平滑滚动的一个Helper类。

通常在自定义的View时使用,在View中定义一个私有成员mScroller=newScroller(context)。

设置mScroller滚动的位置时,并不会导致View的滚动,通常是用mScroller记录/计算View滚动的位置,再重写View的computeScroll(),完成实际的滚动。

相关API介绍如下 

Java代码 

1.mScroller.getCurrX() 

//获取mScroller当前水平滚动的位置 

2.mScroller.getCurrY() 

//获取mScroller当前竖直滚动的位置 

3.mScroller.getFinalX() 

//获取mScroller最终停止的水平位置 

4.mScroller.getFinalY() 

//获取mScroller最终停止的竖直位置 

5.mScroller.setFinalX(int 

newX) 

//设置mScroller最终停留的水平位置,没有动画效果,直接跳到目标位置 

6.mScroller.setFinalY(int 

newY) 

//设置mScroller最终停留的竖直位置,没有动画效果,直接跳到目标位置 

7. 

8.//滚动,startX, 

startY为开始滚动的位置,dx,dy为滚动的偏移量, 

duration为完成滚动的时间 

9.mScroller.startScroll(int 

startX, 

int 

startY, 

dx, 

dy) 

//使用默认完成时间250ms 

10.mScroller.startScroll(int 

dy, 

duration) 

11. 

12.mSputeScrollOffset() 

//返回值为boolean,true说明滚动尚未完成,false说明滚动已经完成。

这是一个很重要的方法,通常放在VputeScroll()中,用来判断是否滚动是否结束。

举例说明,自定义一个CustomView,使用Scroller实现滚动:

1.import 

android.content.Context;

2.import 

android.util.AttributeSet;

3.import 

android.util.Log;

4.import 

android.view.View;

5.import 

android.widget.LinearLayout;

6.import 

android.widget.Scroller;

8.public 

class 

CustomView 

extends 

LinearLayout 

9. 

10. 

private 

static 

final 

String 

TAG 

Scroller"

;

12. 

Scroller 

mScroller;

13. 

14. 

public 

CustomView(Context 

context, 

AttributeSet 

attrs) 

15. 

super(context, 

attrs);

16. 

mScroller 

new 

Scroller(context);

17. 

18. 

19. 

//调用此方法滚动到目标位置 

20. 

void 

smoothScrollTo(int 

fx, 

fy) 

21. 

dx 

fx 

mScroller.getFinalX();

22. 

dy 

fy 

mScroller.getFinalY();

23. 

smoothScrollBy(dx, 

dy);

24. 

25. 

26. 

//调用此方法设置滚动的相对偏移 

27. 

smoothScrollBy(int 

28. 

29. 

//设置mScroller的滚动偏移量 

30. 

mScroller.startScroll(mScroller.getFinalX(), 

mScroller.getFinalY(), 

31. 

invalidate();

//这里必须调用invalidate()才能保证computeScroll()会被调用,否则不一定会刷新界面,看不到滚动效果 

32. 

33. 

34. 

@Override 

35. 

computeScroll() 

36. 

37. 

//先判断mScroller滚动是否完成 

38. 

if 

(mSputeScrollOffset()) 

39. 

40. 

//这里调用View的scrollTo()完成实际的滚动 

41. 

scrollTo(mScroller.getCurrX(), 

mScroller.getCurrY());

42. 

43. 

//必须调用该方法,否则不一定能看到滚动效果 

44. 

postInvalidate();

45. 

46. 

puteScroll();

47. 

48.} 

12欢迎界面

文件android开发笔记\常用组件\WelcomPage/

关于Android 

ViewGroup的一点介绍:

这里有个地方要注意,那就要明白ViewGroup的绘图流程:

ViewGroup绘制包括两个步骤:

1.measure2.layout

在两个步骤中分别调用回调函数:

1.onMeasure() 

2.onLayout()

1.onMeasure()在这个函数中,ViewGroup会接受childView的请求的大小,然后通过childView的measure(newWidthMeasureSpec,heightMeasureSpec)函数存储到childView中,以便childView的getMeasuredWidth()andgetMeasuredHeight()的值可以被后续工作得到。

2.onLayout()在这个函数中,ViewGroup会拿到childView的getMeasuredWidth()andgetMeasuredHeight(),用来布局所有的childView。

3.View.MeasureSpec与LayoutParams这两个类,是ViewGroup与childView协商大小用的。

其中,View.MeasureSpec是ViewGroup用来部署childView用的,LayoutParams是childView告诉ViewGroup我需要多大的地方。

4.在View的onMeasure的最后要调用setMeasuredDimension()这个方法存储View的大小,这个方法决定了当前View的大小。

效果图:

13程序退出处理

1)Finish所有Activity,

2)stop所有Services

3)killProcess,

android.os.Process.killProcess(android.os.Process.myPid());

System.exit(0);

14使用提醒管理器延迟发送广播

PendingIntentdd=PendingIntent.getBroadcast(activity,0,intent,0);

AlarmManagermgr=(AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);

mgr.set(AlarmManager.RTC,System.currentTimeMillis()+2000,dd);

15xUtils简介

∙xUtils包含了很多实用的android工具。

∙xUtils最初源于Afinal框架,进行了大量重构,使得xUtils支持大文件上传,更全面的http请求协议支持(10种谓词),拥有更加灵活的ORM,更多的事件注解支持且不受混淆影响...

∙详情

16android常用调用系统功能

16.1从google搜索内容

Intentintent=newIntent();

intent.setAction(Intent.ACTION_WEB_SEARCH);

intent.putExtra(SearchManager.QUERY,"

searchString"

startActivity(intent);

16.2浏览网页

Uriuri=Uri.parse("

Intentit=newIntent(Intent.ACTION_VIEW,uri);

startActivity(it);

16.3显示地图

Uriuri=Uri.parse("

geo:

38.899533,-77.036476"

Intentit=newIntent(Intent.Action_VIEW,uri);

16.4路径规划

Intentit=newIntent(Intent.ACTION_VIEW,URI);

16.5拨打电话

tel:

xxxxxx"

Intentit=newIntent(Intent.ACTION_DIAL,uri);

16.6调用发短信的程序

方法1:

Intentit=newIntent(Intent.ACTION_VIEW);

it.putExtra("

sms_body"

"

TheSMStext"

it.setType("

vnd.android-dir/mms-sms"

16.7发送短信

方法2:

smsto:

0800000123"

Intentit=newIntent(Intent.ACTION_SENDTO,uri);

方法三:

Stringbody="

thisissmsdemo"

Intentmmsintent=newIntent(Intent.ACTION_SENDTO,Uri.fromParts("

smsto"

number,null));

mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);

mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);

mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);

startActivity(mmsintent);

16.8发送彩信

content:

//media/external/images/media/23"

Intentit=newIntent(Intent.ACTION_SEND);

sometext"

it.putExtra(Intent.EXTRA_STREAM,uri);

image/png"

Str

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 小学教育 > 数学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1