7

ターミナルを使用して、コンピューターに並列に接続されているすべてのAndroidフォンに.apkをインストールできるシェルスクリプトを作成しています。私の会社では多くのデバイスでテストを行っているため、インストール部分を高速化する必要があります。

質問:ある種のフィードバック/通知を介して、どの電話に.apkがインストールされているかをすばやく特定する方法を探しています。理想的には、.apkを確認するだけで(ある種の音や画面のフラッシュ)、またはデバイスのロックを解除するだけで(たとえば、新しくインストールしたアプリを開いた)、どの電話が.apkを受信したかを確認できるはずです。

これらのいずれかをどのように行うことができるかについてのアイデアはありますか?

アプリの起動について読んだことがありますが、それは.apkだけではできないようです(アクティビティも指定する必要があります...)。

どんなアイデアでも大歓迎です!

ありがとう!

4

5 に答える 5

6

私自身の解決策を見つけました!

私が使用していたもの:

aapt dump badging

これはパッケージ名を出力するだけだと思います。より多くの有用な情報を出力することがわかりました。私が出力したことに気付いた行の1つは、アプリの起動アクティビティです。この行をgrepで分離し、次のように起動アクティビティを切り取ることができました。

aapt dump badging $1 | grep launchable | cut -d "'" -f 2

次に、アプリのアクティビティの1つを知っている場合に、アプリを起動できるコマンドがあります。この行を追加すると、上記のコマンドを使用して取得されたアクティビティが起動します。

adb -s $deviceID shell am start -a android.intent.action.MAIN -n $packageName/$launchableActivity

インストールコマンドの直後に、この行をforループに配置しました。いいえ、アプリがインストールされた後、スクリプトは後でアプリを起動しようとします。とても便利な!

すべての助けをありがとう!:D

于 2012-07-09T15:38:09.583 に答える
3

パッケージマネージャーを使用して、APKがインストールされているかどうかを確認します。

pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [FILTER]

pm list packages: prints all packages, optionally only
  those whose package name contains the text in FILTER.  Options:
    -f: see their associated file.
    -d: filter to only show disbled packages.
    -e: filter to only show enabled packages.
    -s: filter to only show system packages.
    -3: filter to only show third party packages.
    -i: see the installer for the packages.
    -u: also include uninstalled packages.

例えば

$ adb shell pm list packages com.example.mypkg
于 2012-07-06T03:57:06.987 に答える
1

You can use the 'adb shell am start' with arguments you will need to look up to start your newly installed package.

If there's any concern about not being confused by a stale one, adb uninstall the old one before installing the new one, or better yet have your splash activity display versioning.

You can actually use am start to launch an activity which isn't known to the launcher, so you could use it to launch directly to an "about" activity which would display the current version. Your choice if you make that available in the ordinary course of the application, or only use it this one time as a splash.

You should also be able to parse the output of the adb install command - you'll have to see if it sends errors / success to stderr or stdout.

UPDATE: Here's how to make an activity which you can use to turn the screen on and display a message, like this:

adb shell 'am start -n com.example.testreport/.ReportActivity -e result PASS'

The code is heavily cribbed from the built in AlarmClock of an early android version, it will require:

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

in the manifest

package com.example.testreport;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;
import android.view.Gravity;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;
public class ReportActivity extends Activity {
    PowerManager.WakeLock sScreenWakeLock;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
         getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    }
    protected void onStart() {
        super.onStart();

        if (sScreenWakeLock == null) {
            PowerManager pm =
                    (PowerManager) getSystemService(Context.POWER_SERVICE);
            sScreenWakeLock = pm.newWakeLock(
                    PowerManager.FULL_WAKE_LOCK |
                    PowerManager.ACQUIRE_CAUSES_WAKEUP |
                    PowerManager.ON_AFTER_RELEASE, "ReportActivity Wakelock");
            sScreenWakeLock.acquire();
        }
        TextView tv=new TextView(this);
        tv.setTextSize(30);
        tv.setGravity(Gravity.CENTER);
        Intent i = getIntent();
        if ((i != null) && (i.hasExtra("result"))) 
            tv.setText(i.getStringExtra("result"));
        else 
            tv.setText("???");
        setContentView(tv);
    }
    protected void onStop() {
        if (sScreenWakeLock != null) {
            sScreenWakeLock.release();
            sScreenWakeLock = null;
        }
        super.onStop();
    }
}

It can probably use some cleanup and improvement; for example at the moment you can't turn the phone off with the power button unless you first stop the activity by navigating away to make it lose visibility.

于 2012-07-06T03:52:47.137 に答える
0

これが行われていることを確認する1つの方法は、アプリケーションのインストールを確認するアプリケーションです。具体的には、デバイスにインストールする必要があるアプリケーションのチェックリストであり、PackageManagerがインストールを完了すると、このブロードキャストに基づいて更新されます。

App層の外でそれを行うことを除けば、デバイスに接続されているUSBポートをスニッフィングし、コマンドとペイロードを識別してそれを理解しない限り、それは不可能だと思います(HACK)

于 2012-07-06T03:38:48.987 に答える
0

パッケージがインストールされているかどうかを実行して確認できます

adb shell pm list packages your-package-name-here

package:your-package-name-hereインストールされている場合は戻り値になるため、戻り値を変数に格納してから、変数がnullまたは「package:your-package-name-here」であるかどうかを確認できます。

呼び出す特定のアクティビティがない場合でも、デバイスにインストールされているアプリを開くには、次のコマンドを実行します。

adb shell monkey -p your-package-name-here -c android.intent.category.LAUNCHER 1
于 2021-12-21T19:30:30.720 に答える