android 技术问题综合

来源:互联网 发布:js onload方法 编辑:程序博客网 时间:2024/06/05 12:43


1.view.inflate 从资源创建view 对象
ViewGroup view 对象容器类,提供对对数个view对象的显示支持
public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
              setTitle(R.string. activity_title);

               contentView = new FlipViewGroup(this);
               contentView.addFlipView(View.inflatethis, R.layout.second_pagenull));
               contentView.addFlipView(View.inflatethis, R.layout.first_pagenull));
              setContentView( contentView);
               contentView.startFlipping(); //make the first_page view flipping
       }

2.Intent 进行进程间的通信和调用
activity进行切换时,通过Intent进行调度,执行后,当前activity被存放入调度堆栈中,
以便于调度返回时程序可以执行,Intent也可以在两个activity之间传入参数,进行交互
如果调度Intent后,调用finish()接口,当前activity会被从堆栈中移出。
 Intent intent = new Intent();
 intent.setClass(Forwarding. this, ForwardTarget.class);
 intent.putExtra( "doubleparam" , 2.0);
 startActivity(intent);
 finish();

3.android 框架结构
 android 应用以activity为最基本的单元,一个独立的activity启动时OnCreate 处理中初始化
 一个window对象,而在该window对象中建立DecorView.(getDecorView()/peekDecorView())
window 对象的类为:PhoneWindow ,是对IWindow的实现。
DecorView为基本的ui窗口类,是依照Decorate设计模式定义的类型,
所以其本身也是ViewGroup对象,是view对象类的容器类。

当一个DecorateView对象被建立后,会被加入WindowServiceManager对象中,该对象中会建立一个
ViewRoot对象与其关联,然后,通过linux系统的binder与wsm通过ISession,和IWindow接口简历关联。
IWindow为wms的回调接口(callback interface )。

wsm将键盘和屏幕操作通过IWindow回调传递给ViewRoot,该类通过PerformTraverse() ?(视图结构是个树形结构)方法传递消息
给被操作的view视图对象,调用其对应的event handler接口。

4.thread messagequeue(Thread,Looper)
 a.Looper.Prepare()方法给线程建立一个独立的消息队列。
 b.activity 建立时,具有一个默认的messagequeue,其子线程如果自己没有
建立消息队列,此时调用Looper.getMainLooper(),获得主线程messagequeue,
如果有几个线程的话,获取的都是同样一个MessageQueue的句柄。
 c.MessageQueue和handle以及Thread的关联方法

Looper.Prepare();
Handle mHandle = new MessageHandle(Looper.getLooper());
Looper.myLooper()获得当前线程的Looper.

d. Handler 和Handler.Callback
CallBack::public boolean handleMessage(Message msg);
handleMessage为Handler必须要实现的Callback接口中唯一的虚函数
如果Looper已经成功建立,消息循环已经运行,默认可以在looper之上建立
Hanler 以获取Looper中消息的处理权利。
eg.
myActivity extends Acitivity implements Handler.Callback{...};
in someplace:
Hanlder myHander =  new Handler((Callback)myActivity.this);

d中说明如何使用Handler 发送一个自定义消息到特定的Activity,与window消息机制雷同的是,发送消息
的句柄(Handler),必须关联到具体的窗口(Activity),而该窗口中包含了消息的处理函数handMessage(window中为:WndProc)。
除了发送定义消息,默认情况下,Handler可以发送“执行体”(Runnable)完成特定操作,甚至可以决定
启动该Runnable的时间。
只是在常规消息处理队列理论上的一个重大创新.
mHandler.postDelayed( ... , 3000);
mHandler.post( new Runnable() {

            public void run() {
                mReady = true;
                WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                        LayoutParams. WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                        WindowManager.LayoutParams. TYPE_APPLICATION,
                        WindowManager.LayoutParams. FLAG_NOT_TOUCHABLE
                                | WindowManager.LayoutParams. FLAG_NOT_FOCUSABLE,
                        PixelFormat. TRANSLUCENT);
                mWindowManager.addView(mDialogText , lp);
            }});
这样一个默认的Handler处理加入 主Activity的 消息队列处理 流程中,获取消息执行权。

5.audio plug-in method
first in manifest file:

<uses-permission android:name="android.permission.RECORD_AUDIO" />
        <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

second implement BroadcastRecerver:

myHeadsetStateReceiver implements BroadcastReceiver{};

trip: declair ,and regist BroadcastRecerver:

public class BRHeadsetActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    myHeadsetStateReceiver receiver = new myHeadsetStateReceiver();
    registerReceiver( receiver, receiverFilter );

}

This is the part of "HeadsetObserver.java", Android SDK Source.

private final void sendIntent(int headset, int headsetState, int prevHeadsetState, String headsetName) {
    if ((headsetState & headset) != (prevHeadsetState & headset)) {
        //  Pack up the values and broadcast them to everyone
        Intent intent = new Intent(Intent.ACTION_HEADSET_PLUG);

        **intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);**

        int state = 0;
        int microphone = 0;

        if ((headset & HEADSETS_WITH_MIC) != 0) {
            microphone = 1;
        }
        if ((headsetState & headset) != 0) {
            state = 1;
        }
        intent.putExtra("state", state);
        intent.putExtra("name", headsetName);
        intent.putExtra("microphone", microphone);

        if (LOG) Slog.v(TAG, "Intent.ACTION_HEADSET_PLUG: state: "+state+" name: "+headsetName+" mic: "+microphone);
        // TODO: Should we require a permission?
        ActivityManagerNative.broadcastStickyIntent(intent, null);
    }
}

6.activity属性

A.应用的重力感应设置方法方法(xml)

<activity android:name="com.App.GHL.airposproject.ForgetKeyActivity"

android:theme="@style/Theme.Gray" android:screenOrientation="portrait"></activity>

 B.应用theme
  将背景定义成弹出式对话框
  styles.xml文件中:
  <style name="Theme.CustomDialog" parent= "android:style/Theme.Dialog" >
        <item name= "android:windowBackground" >@drawable/filled_box </item>
  </style >

  filled_box.xml文件中:
  <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color= "#f0600000"/>
    <stroke android:width= "3dp" color ="#ffff8080"/>
    <corners android:radius= "3dp" />
    <padding android:left= "10dp" android:top ="10dp"
        android:right="10dp" android:bottom= "10dp" />
  </shape>
 C.activity theme属性集合

7.modify titlebar
      requestWindowFeature(Window.FEATURE_ACTION_BAR);
      final ActionBar actionBar = getActionBar();
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
      actionBar.setContentView(...);

8.View 的 重要事件处理接口(“onXXXX”)

一般情况下当手机屏幕转屏时会调度onSizeChanged消息
a. protected void onSizeChanged(int w,int h,int oldw,int oldh);
b. protected boolean onTouchEvent(MotionEvent event);
c. protected void onDraw(Canvas canvas);
9.How to create activity in a thread ?
when main ui activity was blocked by a function call,how to create and display
a waiting activity ?
This isnt a problem,because can use Dialog  "no cancel model".
solution:Create ProgressDialog in HanderThread.
10.system service manager.

11.android activity Alert Dialog:

<activity android:name="com.order.FrmAddToMenu" android:theme="@android:style/Theme.Dialog" android:icon="@drawable/info" android:label="@string/cookInfo"></activity>

12.model pattern dialog
After clicking a button, displaying a modal dialog on the Android is easy, by using the classes android.app.AlertDialog and its helper, android.app.AlertDialog.Builder, with code such as:

new AlertDialog.Builder(v.getContext())
.setTitle("My Alert")
.setMessage("Blah")
.setPositiveButton(android.R.string.ok, null)
.show();

Alternatively, if there's a need to hold a reference to the newly created AlertDialog:

AlertDialog LDialog = new AlertDialog.Builder(v.getContext())
.setTitle("My Alert")
.setMessage("Blah")
.setPositiveButton(android.R.string.ok, null).create();
LDialog.show();

If no calls are made to setPositiveButton, or setNegativeButton, then no buttons are displayed and pressing the back button is the only way to dismiss the dialog.

13.Activity的重要事件接口

14.layout控件需要获得焦点
加入:
 <requestFocus />android 研究
或者在属性编辑框中设置

15.wifi
一.WIFI状态的获取和更改

适用于 SDK1.0 , SDK1.5

a.获取WIFI状态
方法1:通过WifiManager进行操作

view sourceprint?

WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
wifiManager.isWifiEnabled();

要求权限:android.permission.ACCESS_WIFI_STATE

方法2:通过Settings.System进行操作

view sourceprint?

Settings.System.getInt(getContentResolver(), Settings.System.WIFI_ON);

返回 “0″ “1″

b.通过 WifiManager 更改WIFI状态

view sourceprint?

WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled( false );
wifiManager.setWifiEnabled( true );

15.设置一个acivity为启动activity
  <intent-filter >
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>

16.创建启动新Application进程,设置环境异常句柄
public  class EmapApplication extends Application {
     public void onCreate() {
          super.onCreate();
          Handler handler = new Handler(Looper.getMainLooper());
          handler.post(new Runnable() {

               @Override
               public void run() {
                    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

                         @Override
                         public void uncaughtException(Thread thread, Throwable ex) {
                              Logger logger = Logger.getLogger(EmapApplication.class);
                              logger.fatal("Uncaught", ex);
                              //show custom dialog activity
                              Intent intent = new Intent(EmapApplication.this,
                                        UncaughtExceptionAct.class);
                              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                              EmapApplication.this.startActivity(intent);
                              android.os.Process.killProcess(android.os.Process.myPid());
                         }

                    });

               }

          });
     }

17.自带Looper,可以独立使用的线程 :HandlerThread

18.AlterDialog ,ProgressDialog ....可以锁定当前应用的对话框 。

19.TextView 和 String特殊用法
 a.format html
 b.SpannableString

20.android  activity生命周期图

21.建立漂浮窗体(float lay and window)
   mWindowManager = (WindowManager) getSystemService(Context. WINDOW_SERVICE );

 mDialogText = (TextView) LayoutInflater.from(this).inflate(R.layout. merchant_dialognull );
           mDialogText.setVisibility(View.INVISIBLE);

  WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                                      LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                                      WindowManager.LayoutParams.TYPE_APPLICATION,
                                      WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                                              | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                                      PixelFormat.TRANSLUCENT);
 mWindowManager.addView(mDialogText, lp);

22.listview default adaptor

appNameList:String [];

    ListView appListView = (ListView)mDialog.findViewById(R.id.appList);
    appListView.setAdapter(new ArrayAdapter<String>(MainActivity.this,
    R.layout.simple_list_item, appNameList));
    appListView.setOnItemClickListener(new OnItemClickListener() {
                      @Override
                      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                      }});
23.android 滚动条属性
android:fadeScrollbars ="false" //该设置滚动条始终显示

24.显示网页文本和图片的方式
 public void showFuWaImage() {                                            //显示福娃图片
          String html_fuwa = "<img src = 'beibei' />" +
                                                   "<img src = 'jingjing' />" +
                                                   "<a href = 'http://www.baidu.com'><img src = 'huanhuan' /></a>" +      //超链接“欢欢”图片到百度
                                                   "<img src = 'yingying' />" +
                                                   "<img src = 'nini' />";
          CharSequence charSequence_fuwa = Html.fromHtml(html_fuwa, new ImageGetter() {              //将图片加载到字符序列中
                 public Drawable getDrawable (String source) {
                     Drawable drawable = getResources().getDrawable(getResourceId(source));                   //获得图片资源信息
                     if (source.equals("beibei") || source.equals("nini")) {                             //将图片压缩到原图片尺寸的80%
                         drawable.setBounds(0, 0, drawable.getIntrinsicWidth()*4/5, drawable.getIntrinsicHeight()*4/5);
                     } else if (source.equals("huanhuan")) {                                                           //将图片放大到原图片尺寸的120%
                         drawable.setBounds(0, 0, drawable.getIntrinsicWidth()*5/4, drawable.getIntrinsicHeight()*5/4);
                     } else {                                                                                       //其他图片保持原图片尺寸
                         drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
                     }
                     return drawable;
                 }
          }, null);
          textView_fuwaImage.setText(charSequence_fuwa);             //将字符序列加载到textView控件中
          textView_fuwaImage.setMovementMethod(LinkMovementMethod.getInstance());
      }

25.android 系统语言
  String str = Locale.getDefault().getLanguage();
                Log.i("my", "changed    "+str);

26.异步工作对象
 AsyncTask<Void, Void, String[]>

AsyncTask::protected String[] doInBackground(Void... params) //后台工作

AsyncTask::protected void onPostExecute(String[] result)//工作完成收尾

27.android布局中weight属性的作用
在线性逻辑布局中
a.weight属性,意味着布局将在所有非"weight"组件布局后,最后获得layout的空间。
b.如果一个布局空间中几个组件都具有"weight",意味着将按照weight的比例平分该空间。

28.android反射机制
Android CLASS对象中提供直接对声明 函数对象、接口 的查找替换机制:
  1. Field mField = ViewPager.class.getDeclaredField("mScroller");
  2. mField.setAccessible(true);
  3. 设置加速度 ,通过改变FixedSpeedScroller这个类中的mDuration来改变动画时间(如mScroller.setmDuration(mMyDuration);)
  4. mScroller = new FixedSpeedScroller(mViewPager.getContext(), new AccelerateInterpolator());
  5. mField.set(mViewPager, mScroller);
 29. android调集系统资源定义方法
eg:
Context.getResources().getColorStateList(android.R.color. white)

30.path measure :how to get points from path.

    PathMeasure pm = new PathMeasure(myPath, false);
    //coordinates will be here
    float aCoordinates[] = {0f, 0f};

    //get point from the middle
    pm.getPosTan(pm.getLength() * 0.5f, aCoordinates, null);

31. send email

Intent intent = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject of email");
intent.putExtra(Intent.EXTRA_TEXT, "Body of email");
intent.setData(Uri.parse("mailto:default@recipient.com")); // or just "mailto:" for blank
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this will make such that when user returns to your app, your app is displayed, instead of the email app.
startActivity(intent);

32.AsyncTask 问题

AyncTask使用时偶然发现放生 “thread no messagequeue ,need to prepare()”的exception,

这个盖因异步机制,是通过binder绑定一个公共工作线程所致,该线程没有 prepare()产生私有 queue.

解决方法是在 onBackground 中调用 Thread.Prepare(),但要注意处理 重复建立时,反生的异常。

33.调用网络模块遇到的失败异常(HttpUrlConnection)

应用已经配置了相应的 permission,但调用进行网络链接时仍然产生 线程异常行为,该线程发生在http模块中。

解决的方法 通过设置线程的 strict policy 解决该问题

 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().build());
 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .penaltyLog() .penaltyDeath().build());

34. Activity:onStart() 调用,
该过程在activity 建立时,和手机黑屏后,重新激活被调用。 是重入次数较多的方法。
onResume() 在每次hide状态的activity被激活时调用

35.Android :: Dynamically Add Table Row To Table Layout
Jul 8, 2010

When a button is clicked, the following method is run:

public void createTableRow(View v) {
TableLayout tl = (TableLayout) findViewById(R.id.spreadsheet);
TableRow tr = new TableRow(this);
LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
tr.setLayoutParams(lp);
TextView tvLeft = new TextView(this);
tvLeft.setLayoutParams(lp);......................

36.apk,package, version
  PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
  DeviceInfo. Instance().APPVersion.mVersionName = info.versionName;
  DeviceInfo. Instance().APPVersion.mVersion = info. versionCode;

37. android AsyncTask and net mode.
AsyncTask :this can't work with overlap mode net socket,
or will be badly crash.
pattern: Create service thread with no overlap mode socket api,this service port,option will be linear
and keep safe.

38. android property file

Properties prop = new Properties();
    String propertiesPath = this.getFilesDir().getPath().toString() + "/app.properties";

    try {

        File existFile = new File(propertiesPath);

        if(existFile.isFile())
        {
            FileInputStream inputStream = new FileInputStream(propertiesPath);
            prop.load(inputStream);
            inputStream.close();
        }

    } catch (IOException e) {
        System.err.println("Failed to open app.properties file");
        e.printStackTrace();
}

39. android 自动安装
app 自动安装需要权限:  android:sharedUserId ="android.uid.system" //系统级别权限才可以安装apk.
permission:< uses-permission android:name ="android.permission.INSTALL_PACKAGES" />

但执行这两个定义的程序,安装时会出现错误:INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
reason:程序级别被提升到“系统级”,此时安装该程序需要对应的系统签名。
将签名工具(signapk.jar)、签名证书(platform.pk8和platform.x509.pem)及编译出来的apk文件都放到同一目录
signapk.jar  platform.x509.pem  platform.pk8 *.apk signed*.apk
将apk安装即可

40.权限汇编

创建桌面快捷方式
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

蓝牙管理权限
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />

sd卡写权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.READ_CONTACTS" />

<uses-permission android:name="android.permission.WRITE_CONTACTS" />

<uses-permission android:name="android.permission.INSTALL_PACKAGES" />

<uses-permission android:name="android.permission.DELETE_PACKAGES" />

41. call adb with java

String cmd = "adb shell ls";
    String cmdreturn = "";
    Runtime run = Runtime.getRuntime();
    Process pr = run.exec(cmd);
    pr.waitFor();
    BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    while ((line=buf.readLine())!=null) {
        System.out.println(cmdreturn);
    }
42. time format translation
System.currentTimeMillis() 获得的是自1970-1-01 00:00:00.000 到当前时刻的时间距离,类型为long
public String refFormatNowDate() {
  Date nowTime = new Date(System.currentTimeMillis());
  SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyy-MM-dd");
  String retStrFormatNowDate = sdFormatter.format(nowTime);
  return retStrFormatNowDate;
}

43. android standard Timer and TimerTask
a.初始化计时器,和计时器处理handler
private final Timer timer = new Timer();
private TimerTask task;
Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        // TODO Auto-generated method stub
        // 要做的事情
        super.handleMessage(msg);
    }
};

b.初始化计时器任务
task = new TimerTask() {
    @Override
    public void run() {
        // TODO Auto-generated method stub
        Message message = new Message();
        message.what = 1;
        handler.sendMessage(message);
    }
};

c. 启动定时器
timer.schedule(task, 2000, 2000);

44.打开标准系统设置组件窗口(地理信息)
 Intent myIntent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS );
 AirPosInstOwner.s_CurUIContext.startActivity(myIntent);

45.系统版本号获取与比对

  int currentapiVersion=android.os.Build.VERSION.SDK_INT;
  if(currentapiVersion <= Build.VERSION_CODES.GINGERBREAD_MR1 ){}

46.系统存储结构
  .getActivity().getSharedPreferences (SHARED_PREFS_MAIN, 0).getBoolean(pStr, false);

47.锁屏事件
  1. <!-- 锁屏事件 -->
  2. <receiver android:name=".broadcast.LockScreenReceiver">
  3. <intent-filter>
  4. <action android:name="android.intent.action.SCREEN_ON" />
  5. <action android:name="android.intent.action.SCREEN_OFF" />
  6. <action android:name="android.intent.action.USER_PRESENT" />
  7. </intent-filter>
  8. </receiver>
48. android hash-256  ---MessageDigest

public byte[] getHash(String password) {
      MessageDigest digest=null;
    try {
        digest = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
      digest.reset();
      return digest.digest(password.getBytes());
}

49.InetAddress  --getHostByName

InetAddress.getHostByName( www.163.com);

50.   atctiviy 退出后返回参数给parent activity.

call:

Intent result = new Intent();
result.putExtra("address", address);
this.setResult(0, result);

this.finish();

back:@Override

        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
              super.onActivityResult(requestCode, resultCode, data);

              if (null != data) {
                    String mac = data.getStringExtra( "address");
                    Pos. POS_Open(mac);
             }
       }

51. start and call animation:

//show "shiver" animation
Animation ani = AnimationUtils.loadAnimation(mContext, R.anim.shake);
amoutinput.startAnimation(ani);

52. android 可指名call其它apk的class

当前apk: com.example.test;

Intent call = new Intent();

call.setClassName( "com.example.ghlpaytest", "com.example.ghlpaytest.MainActivity");

this.startActivity(call);

apk安装后,会在安装目录下建立对应namespace的的文件夹,其编译好的class和资源根据包名自动放入对应的位置。

而包含activity的class其实是一个完整的可以被dvm执行的程序单元,所以,在已知包名,类名的情况下,可以由另外一个

apk调用。安装后系统会根据manefest.xml文件中的 第一个Intent-Filter定义生成桌面icon.

53.如何安装apk桌面没有图标

APK程序,在所有的APK程序都安装完后系统会最后安装Luncher2.apk应用程序,Luncher2.apk就是我们的系统界面应用程序,它会检测系统已经安装的应用软件的包名,然后把这些应用软件的图标和名称给解析出来然后显示在应用程序列表里,用GridView显示了出来,这里如果我们不想让我们的应用程序的图标在Luncher里显示的话,有一个很简单的方法,就是仅修改AndroidManifest.xml文件即可。

<!--  <category android:name="android.intent.category.LAUNCHER" /> -->

54.如何判断android app已经安装

PackageInfo packageInfo;
      try {
          packageInfo = this.getPackageManager().getPackageInfo(
                  packagename, 0);
      } catch (NameNotFoundException e) {
          packageInfo = null;
          e.printStackTrace();
      }
      if(packageInfo ==null){
          System.out.println("not installed");
      }else{
          System.out.println("is installed");
      }

55.代码安装 apk
Intent i = new Intent(Intent. ACTION_VIEW);
i.setFlags(Intent. FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(Uri.fromFile(uriString), "application/vnd.android.package-archive" );
AirPosInstOwner. s_CurApplication.startActivity(i);

56.delete file ,directory
public void deleteFile(File file) {
if (file.exists()) { // 判断文件是否存在
if (file.isFile()) { // 判断是否是文件
file.delete(); // delete()方法 你应该知道 是删除的意思;
} else if (file.isDirectory()) { // 否则如果它是一个目录
File files[] = file.listFiles(); // 声明目录下所有的文件 files[];
for (int i = 0; i < files.length; i++) { // 遍历目录下所有的文件
this.deleteFile(files[i]); // 把每个文件 用这个方法进行迭代
}
}
file.delete();
} else {
Constants.Logdada("文件不存在!"+"\n");
}
}

57.android   severial  receiver 
 <receiver android:name= "com.tiny.poop.SmsReciver" > 
               <intent-filter android:priority="999" > 
                   <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
               </intent-filter>  
  </receiver>  
          
  <receiver android:name=".BroadcastReceiver" >
            <intent-filter >
               
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
  </receiver>
       
  <receiver
        android:name=" com.arui.framework.android.daemonservice.Alarmreceiver" > 
        <intent-filter>  
            <action android:name="arui.alarm.action" /> 
        </intent-filter>  
  </receiver >  

58. thread concurrence and async

BlockingQueue
Thread
Runnable
java.util.concurrent

59. Register bluetooth  filter
a. implement class :BroadcastReceiver.onReceive
BroadcastReceiver receiver = new BroadcastReceiver(){...};
b. get device name and action from Intent
BlueToothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
String devName = device.getName();
c. register
IntentFilter filter = new IntentFilter();
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
Context.registerReceiver(receiver,filter);


0 0
原创粉丝点击