編輯:關於Android編程
靜默安裝就是偷偷的把一個應用安裝到手機上,就是屏蔽確認框,通過反射
只能寫個主要的代碼,這個是在linux編譯用到,因為靜默安裝需要調用系統服務,在源碼下編譯,我也是搞了好久
InstallActivity.java
package com.smart.Installback; import java.io.File; //import com.android.packageinstaller.R; import android.app.Activity; import android.os.Bundle; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.IPackageInstallObserver; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; public class InstallActivity extends Activity { /** Called when the activity is first created. */ private Button btn=null; private Button btn2=null; private final int INSTALL_COMPLETE = 1; final static int SUCCEEDED = 1; final static int FAILED = 0; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); String fileName = Environment.getExternalStorageDirectory() + "/UC.apk"; Uri uri = Uri.fromFile(new File(fileName)); int installFlags = 0; PackageManager pm = getPackageManager(); try { PackageInfo pi = pm.getPackageInfo("com.uc.browser", PackageManager.GET_UNINSTALLED_PACKAGES); if(pi != null) { installFlags |= PackageManager.INSTALL_REPLACE_EXISTING; } } catch (NameNotFoundException e) { } // String installerPackageName = getIntent().getStringExtra( // Intent.EXTRA_INSTALLER_PACKAGE_NAME); PackageInstallObserver observer = new PackageInstallObserver(); pm.installPackage(uri, observer, installFlags, "com.uc.browser"); } private OnClickListener listener2=new OnClickListener(){ public void onClick(View v) { String fileName = Environment.getExternalStorageDirectory() + "/UC.apk"; ivate Uri uri = Uri.fromFile(new File(fileName)); int installFlags = 0; PackageManager pm = getPackageManager(); try { PackageInfo pi = pm.getPackageInfo("com.uc.browser", PackageManager.GET_UNINSTALLED_PACKAGES); if(pi != null) { installFlags |= PackageManager.INSTALL_REPLACE_EXISTING; } } catch (NameNotFoundException e) { } // String installerPackageName = getIntent().getStringExtra( // Intent.EXTRA_INSTALLER_PACKAGE_NAME); PackageInstallObserver observer = new PackageInstallObserver(); pm.installPackage(uri, observer, installFlags, "com.uc.browser"); } }; class PackageInstallObserver extends IPackageInstallObserver.Stub { public void packageInstalled(String packageName, int returnCode) { Message msg = mHandler.obtainMessage(INSTALL_COMPLETE); msg.arg1 = returnCode; mHandler.sendMessage(msg); } }; private Handler mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case INSTALL_COMPLETE: // Update the status text // Show the ok button int centerTextLabel; Drawable centerTextDrawable = null; if(msg.arg1 == SUCCEEDED) { } else {} if (centerTextDrawable != null) {} break; default: break; } } }; }
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > </LinearLayout>
以上所述就是本文的全部內容了,希望大家能夠喜歡。
在一篇博客中看到一篇文章,感覺描述的還可以:在前面的博客中介紹的都是使用java開發Android應用,這篇博客將介紹java通過使用jni調用c語言做開發為了更加形象的
(一)概述手勢是:連續觸碰的行為,比如左右上下滑動屏幕,又或者畫一些不規則的幾何圖形! Android對上述兩種手勢行為都提供了支持:Android提供手勢檢測,並為手勢
為什麼要使用多線程下載呢?究其原因就一個字:"快",使用多線程下載的速度遠比單線程的下載速度要快,說到下載速度,決定下載速度的因素一般有兩個:一個是客
Android圖表庫MPAndroidChart(十三)——簡約的底部柱狀圖。我們繼續上一講,今天還是說下柱狀圖,這個圖的話應該是用的比較多的,所