`
文章列表
在上一篇文章(Service使用方式)中,介绍了Android进程间通信(IPC)的使用,并给出了一个示例。但并没有深入分析aidl是怎样可以做到进程间通信的,它的执行过程是怎样的? 这篇文章来分析IRemoteService.aidl的执行过程,并理解aidl是怎样跨进程通信的。   当我们创建IRemoteService.aidl文件时,IDE会为我们在gen目录中创建相应的文件。     /** This file is auto-generated. DO NOT MODIFY. * Original file: F:\\workspace\\AndroidImprov ...

Service使用方式

  使用Service的场合: 1.一个或多个Activity需要向同一应用中的Service发出执行某一操作的命令。 PS:不需要绑定       2.某个Activity需要同一应用中的Service为其单独服务,当此Activity消毁时,也将为其服务的Service一并消毁。 ...
有时候需要在onCreate方法中知道某个View组件的宽度和高度等信息,而直接调用View组件的getWidth()、getHeight()、getMeasuredWidth()、getMeasuredHeight()、getTop()、getLeft()等方法是无法获取到真实值的,只会得到0。这是因为View组件布局要在onResume回调后完成。下面提供实现方法,onGlobalLayout回调会在布局完成时自动调用   final LinearLayout imageViewContainer = (LinearLayout)findViewById(R.id.crop_photo_ ...
当从SD卡中获取图片时,如果图片太大,加载会出现溢出异常。因此,需要先获取到分辨率,再对大图片按分辨率比率缩小后加载,这样就能够防止溢出异常。 BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options);//没有加载图片,仅获取到图片分辨率 Log.i("CDH", ...

图片移动和缩放

import android.graphics.Matrix; import android.graphics.PointF; import android.util.FloatMath; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; public class MulitPointTouchListen ...

定时任务

 
定时任务有执行一次和重复执行两种 public class AlarmBroadcast extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, R.string.show_message, Toast.LENGTH_SHORT).show(); } } /** * 执行一次 */ public void oneShotAlarm() { Int ...
LayoutInflater layoutInflater; 1.layoutInflater = Context.getLayoutInflater(); 2.layoutInflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 3.layoutInflater = LayoutInflater.from(this);
判断当前是否有可用网络 public boolean checkNetworkAvailable() { boolean isNetworkAvailable = false; android.net.ConnectivityManager connManager = (android.net.ConnectivityManager)getApplicationContext().getSystemService(android.content.Context.CONNECTIVITY_SERVICE); if(connManager.getActiveNetworkInfo ...

设置全屏

1.编程方式 public void setFullScreenMethod1(boolean isFullScreen) { if (isFullScreen) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); //也可以用下面的清除Flag //getWindow().clearFlags(Windo ...
//转换dip为px public static int convertDIP2PX(Context context, int dip) { float scale = context.getResources().getDisplayMetrics().density; return (int)(dip*scale + 0.5f*(dip>=0?1:-1)); } //转换px为dip public static int convertPX2DIP(Context context, int px) { float scale = context.getRes ...
Display display = getWindowManager().getDefaultDisplay(); display.getWidth();//返回px值 display.getHeight();//返回px值 display.getRotation();返回0或1,0表示竖屏,1表示横屏 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); dm.density; dm.heightPixels; dm.widthP ...
public int getExternalStorageState() { int result;//0:不可读写 1:只读 2:读写 String state = android.os.Environment.getExternalStorageState(); if(android.os.Environment.MEDIA_MOUNTED.equals(state)){ result = 2; } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { result = 1; } el ...

SQLite数据类型

  一般数据采用的固定的静态数据类型,而SQLite采用的是动态数据类型,会根据存入值自动判断。SQLite具有以下五种数   据类型:   1.NULL:空值。 2.INTEGER:带符号的整型,具体取决有存入数字的范围大小。 3.REAL:浮点 ...
接着上一篇文章"使用WebView实现新浪微博OAuth登录",实现腾讯微博OAuth登录。     #腾讯官方下载SDK http://open.t.qq.com/resource.php?i=3,1   #申请应用KEY 登录腾讯微博,进入http://open.t.qq.com/申请应用,获取KEY和SECRET。   #准备 在项目中导入QWeiboSDK.jar、dom4j-1.6.1.jar(这两个包是由官方下载的SDK提供)     这里只给出腾讯OAuth登录代码,其它代码看上一篇文章   package com.oauth; ...
  #新浪官方下载SDK(weibo4android) http://open.weibo.com/wiki/index.php/SDK   #申请应用KEY 登录新浪微博,进入http://open.weibo.com/申请应用,获取KEY和SECRET。   #准备 在项目中导入commons-httpclient-3.x.jar并加入weibo4android、weibo4android.http、weibo4android.org.json、weibo4android.util包文件(这些都是官方下载的SDK提供的文件)   在跳转到新浪微博授权页面时会使用默认浏览器 ...
Global site tag (gtag.js) - Google Analytics