當前位置:首頁 » 安卓系統 » android獲取當前應用

android獲取當前應用

發布時間: 2023-05-22 11:14:33

Ⅰ android怎麼獲取當前應用程序所佔用的內存空間

File root = Environment.getRootDirectory();
StatFs sf = new StatFs(root.getPath());
long blockSize = sf.getBlockSize();
long blockCount = sf.getBlockCount();
long availCount = sf.getAvailableBlocks();
Log.d("TAG", "block大小:" + blockSize + ",block數目:" + blockCount + ",總大小:"+ blockSize * blockCount / (1024 * 1024) + "MB");
Log.d("TAG","可用的block數目::" + availCount + ",可用大小:" + availCount * blockSize / (1024 * 1024)+ "MB");

Ⅱ android 怎麼獲取當前應用的版本號

/**
2 * 獲取版本號
3 * @return 當前應用的版本號
4 */
5 public String getVersion() {
6 try {
7 PackageManager manager = this.getPackageManager();
8 PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
9 String version = info.versionName;
10 return this.getString(R.string.version_name) + version;
11 } catch (Exception e) {
12 e.printStackTrace();
13 return this.getString(R.string.can_not_find_version_name);
14 }
15 }

Ⅲ Android6.0以後,怎樣獲取當前運行的app

你可以進入開發者模式,點擊正在運行的服務裡面查看在後台中運行的應用程序。

Ⅳ android怎樣獲取正在運行的應用

打開設置,點擊應用,會出現正在運行,這一欄就是正在運行的應用了

Ⅳ 使用adb查看android應用信息

以下命令可以獲取當前應用的包名,以及當前頁面所在的 Activity

Ⅵ android 如何獲取手機當前的Activity實例

獲取activity實例有兩種辦法:
1、通過context來獲取,簡單方便:
private String getRunningActivityName() {
String contextString = context.toString();
return contextString.substring(contextString.lastIndexOf(".") + 1, contextString.indexOf("@"));
}
2、通過特定許可權獲取
<uses-permission android:name="android.permission.GET_TASKS" />

private String getRunningActivityName(){
ActivityManager activityManager=(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
String runningActivity=activityManager.getRunningTasks(1).get(0).topActivity.getClassName();
return runningActivity;
}

Ⅶ android利用adb命令,獲取當前界面(當前Task的棧頂).

開發項目中經常會遇到很多手機廠商製造的麻煩.如涉及許可權,程序授權(受信任應用),或service自啟動管理等.由於android手機種類繁多,廠商自製系統各自為王.弄得我們有時不得不針對固定的廠商或機型做定製開發.
本文就提供一種靠adb命令獲取手機當前activity的方法!
1.首先 要配置adb環境變數 這里就不多說了,自己網路就好了,非常簡單!
2.配置好環境變數後,就可以運用adb 命令了.
以OPPO r9S獲取自啟動管理界面為例:

將手機調好到指定界面後:打開cmd 輸入
1) adb devices //查看鏈接設備
adb shell mpsys activity top //獲取棧頂activity

![Q%T]T N0RQ0X{@ GP~TVZFG.png]( http://upload-images.jianshu.io/upload_images/3995903-d4895ea759168dc6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240 )
2) 1.cmd命令中輸入:adb shell 進入shell命令模式
2.shell中輸入:logcat | grep ActivityManager 真機運行應用,可以實時 查看當前正在運行的Activity;
或者也可以用第二種方法.
至於用那種,看界面吧,這里第二種就不貼圖了.讀者自己去嘗試吧!

補充:已測試手機(為service開啟自啟動或設置受保護程序);

Ⅷ Android中如何獲取應用版本號

應用場景:1、在界面中顯示應用程序的版本號; 2、用戶啟動該應用,後台判斷該應用是否是最新版本。 上述情景都需要在程序中自動獲取到應用的版本號。 思路簡介:在Android中,應用程序的版本號是在AndroidManifest.xml文件中進行配置的,而PackageInfo類則封裝了從該配置文件中獲取的所有信息,描述了包內容的整體信息,因此,可以使用PackageInfo對象的versionName屬性獲取應用的版本號。 要怎麼獲取PackageInfo對象呢?可以通過PackageManager對象來獲取。PackageManager是一個檢索當前已安裝在設備上的相關應用程序包的各種信息的類。PackageManager對象中的getPackageInfo方法可以獲取PackageInfo對象,該方法需要傳遞兩個參數:應用包名和條件。通常情況下,應用程序的包名可以通過Activity或Context(Activity繼承自Context)的getPackageName()方法獲取,而添加可以有很多設置,通常設置為0。 最後是PackageManager對象的獲取,Context對象提供了getPackageManager()方法來獲取該對象。 綜上, 模板代碼如下:(注意,此處封裝的方法位於某個Activity中,因此直接使用this來代替Context對象)1/**2* 獲取版本號3*@return當前應用的版本號4*/5publicString getVersion() {6try{7PackageManager manager =this .getPackageManager();8PackageInfo info = manager.getPackageInfo(this .getPackageName(), 0);9String version = info.versionName;10returnthis .getString(R.string.version_name) +version;11}catch(Exception e) {12

Ⅸ Android應用內瀏覽器如何獲取當前應用的登錄狀態

這里主要是用戶名與密碼的判斷:
先用sharedpreferences方式存儲數據,包含用戶名和密碼:username,password
然後在登錄的時候進行判斷:代碼如下:
String name = et_username.getText().toString();
String password = et_password.getText().toString();

if (name.length()<=0 && password.length()<=0) {

Toast.makeText(LoginActivity.this, "用戶名或密碼為空", 0).show();
} else if (name.length()<=0) {
Toast.makeText(LoginActivity.this, "用戶名不能為空", 0).show();
} else if (password.length()<=0) {
Toast.makeText(LoginActivity.this, "密碼不能為空", 0).show();
} else if (name != null && password != null) {

// 獲取存儲的數據
SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);
String savename = sp.getString("username", "");
int savepassword = sp.getInt("password", 0);

//判斷用戶名與密碼是否和保存的數據一致,進行提醒或者登錄
if (savename.equals(name)&& savepassword == Integer.parseInt(password)) {
//實現界面的跳轉
Intent intent = new Intent(LoginActivity.this,HomeActivity.class);
startActivity(intent);
//關閉當前界面
finish();
}else{
Toast.makeText(LoginActivity.this, "用戶名或密碼錯誤", 0).show();
}
擴展:其中判斷用戶名或密碼是否為空時還可以使用name.isEmpty()判斷是否為空,但是這個方法好像在JDK1.5以下版本是不能用的。

Ⅹ Android 怎麼獲取所有正在運行的應用程序

在framework中想添加這個功能,所以寫了個appliction來實現一下獲取正在運行的應用程序: 還是先看圖吧: 這個app主要是簡單的實現了獲取非系統的應用程序和一些常用的系統應用程序,顯示在一個listview中,並添加了點擊(回復到你打開的界面)和長按事件(關閉應用程序)。 看看代碼吧: 直接貼出來再加上注釋吧(直接寫在一個文件里): package andorid/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="40dip" android:layout_height="40dip" /> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" /> <TextView android:id="@+id/info" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> main: <?xml version="1/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/list_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" ></ListView> </LinearLayout> 在manifest文件中要加以個許可權: <uses-permission android:name="android.permission.RESTART_PACKAGES" /> 主要是前面的am.killBackgroundProcesses(packageName);方法要這個許可權。

熱點內容
pow在c語言中什麼 發布:2025-02-12 21:07:24 瀏覽:320
php查詢mysql連接 發布:2025-02-12 21:05:45 瀏覽:632
linuxc當前時間 發布:2025-02-12 21:03:32 瀏覽:28
雲鎖神伺服器 發布:2025-02-12 21:03:29 瀏覽:487
c語言int和float 發布:2025-02-12 21:03:24 瀏覽:20
我的世界有什麼好玩的大伺服器 發布:2025-02-12 21:01:59 瀏覽:98
方舟手游如何解鎖自己的伺服器 發布:2025-02-12 20:54:09 瀏覽:657
貓影視源碼 發布:2025-02-12 20:42:05 瀏覽:923
區域網如何訪問其他電腦 發布:2025-02-12 20:39:06 瀏覽:378
新平板電腦的數字密碼如何知道 發布:2025-02-12 20:31:19 瀏覽:345