Java應用JDBC銜接Oracle_MSSQL實例代碼。本站提示廣大學習愛好者:(Java應用JDBC銜接Oracle_MSSQL實例代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是Java應用JDBC銜接Oracle_MSSQL實例代碼正文
1、獲得裝置包信息
/**
* 獲得apk包的信息:版本號,稱號,圖標等
* @param absPath apk包的相對途徑
* @param context
*/
public void apkInfo(String absPath,Context context) {
PackageManager pm = context.getPackageManager();
PackageInfo pkgInfo = pm.getPackageArchiveInfo(absPath,PackageManager.GET_ACTIVITIES);
if (pkgInfo != null) {
ApplicationInfo appInfo = pkgInfo.applicationInfo;
/* 必需加這兩句,否則上面icon獲得是default icon而不是運用包的icon */
appInfo.sourceDir = absPath;
appInfo.publicSourceDir = absPath;
String appName = pm.getApplicationLabel(appInfo).toString();// 獲得運用名
String packageName = appInfo.packageName; // 獲得包名
String version = pkgInfo.versionName; // 獲得版本信息
/* icon1和icon2實際上是一樣的 */
Drawable icon1 = pm.getApplicationIcon(appInfo);// 獲得圖標信息
Drawable icon2 = appInfo.loadIcon(pm);
String pkgInfoStr = String.format("PackageName:%s, Vesion: %s, AppName: %s", packageName, version, appName);
Log.i(TAG, String.format("PkgInfo: %s", pkgInfoStr));
}
}
2、在APK裝置的時刻,我們可以獲得裝置包、版本、包名等信息。
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String archiveFilePath="sdcard/jb51.net.apk";//裝置包途徑
PackageManager pm = getPackageManager();
PackageInfo info = pm.getPackageArchiveInfo(archiveFilePath, PackageManager.GET_ACTIVITIES);
if(info != null){
ApplicationInfo appInfo = info.applicationInfo;
String appName = pm.getApplicationLabel(appInfo).toString();
String packageName = appInfo.packageName; //獲得裝置包稱號
String version=info.versionName; //獲得版本信息
// Toast.makeText(TestActivity.this, , Toast.LENGTH_LONG).show();
Drawable icon = pm.getApplicationIcon(appInfo);//獲得圖標信息
TextView tv = (TextView)findViewById(R.id.tv);
tv.setText("appName:"+appName+"---packageName:"+packageName);
//顯示圖標
ImageView tu=(ImageView)findViewById(R.id.imageView1);
tu.setBackgroundDrawable(icon);
}
}
}
}
}