admin 管理员组文章数量: 1086019
2024年2月20日发(作者:java安装与环境变量配置)
Android 命令:实现启动一个apk
1、产生背景:为了调试方便,常常希望通过知道apk的路径,直接去启动它,所以就写了这个命令2、使用方法:adb push launch /data/
adb push /data/
adb shell
launch复制代码其实放到/system/下面也可以,把jar包放到/system/framework/下面,把launch命令放到/system/bin/下面,然后adb shell 进去,直接执行launch就可以了,传入apk的路径参数。3、eg:launch /data/app/复制代码4、代码::
# Copyright 2008 The Android Open Source Project #
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_MODULE := launch include
$(BUILD_JAVA_LIBRARY)
launch:
# Script to start "launch" on the device, which has a very
rudimentary # shell. # export
CLASSPATH=/system/framework/ exec
app_process /system/bin
$* #export
CLASSPATH=/data/ #exec app_process /data/
$*
:
/* * Copyright (C) 2007 The Android Open Source Project *
* Licensed under the Apache License, Version 2.0 (the
"License"); * you may not use this file except in compliance
with the License. * You may obtain a copy of the License at
* * /licenses/LICENSE-2.0 * *
Unless required by applicable law or agreed to in writing,
software * distributed under the License is distributed on
an "AS IS" BASIS, * WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. *
See the License for the specific language governing
permissions and * limitations under the License. */
package ;
import tyManager;
import tyManagerNative;
import ityController;
import ityManager;
import umentationWatcher;
import mentation;
import entName;
import t;
import tReceiver;
import ;
import geManager;
import eInfo; import
;
import ;
import FileDescriptor;
import Exception;
import eManager;
import Properties;
import ndle;
import dException;
import y;
import wManager;
import edReader;
import ;
import tFoundException;
import ption;
import treamReader;
import tream;
import taxException;
import t;
import ;
import ;
import ationInfo;
import eInfo;
import eManager;
import eUserState;
import eParser;
import yMetrics;
/** * Launch */
public class Launch
{
private static final String TAG = "Launch";
private IPackageManager mPM;
private IActivityManager mAm;
/** * Command-line entry point. * * @param args The
command-line arguments */
public static void main(String[] args){
(new Launch()).run(args); }
private void init(){
IPackageManager mPM =
rface(vice("package"));
mAm = ault();
}
private void run(String[] args) {
init();
if ( < 1) {
showUsage(); return; }
String command = args[0];
if( == 1){
PackageInfo info = getPackageArchiveInfo(command,
_ACTIVITIES);
if(info != null){
ApplicationInfo appInfo = ationInfo;
String packageName = eName;
String className = ties[0].name;
log("-->packageName=" + packageName);
log("-->className=" + className);
log("-->all activities:");
for(int i = 0; i < ; i++){
log(ties); }
startApp(packageName, className);
//String execCmd= "am start -n " + packageName + "/" +
className;
//log(execCmd);
//runLinuxCmd(execCmd);
} return ;
}
n("Error: Invalid arguments for command:
" + command);
showUsage(); }
private PackageInfo getPackageArchiveInfo(String
archiveFilePath, int flags) {
PackageParser packageParser = new
PackageParser(archiveFilePath);
DisplayMetrics metrics = new DisplayMetrics();
efaults();
final File sourceFile = new File(archiveFilePath);
e pkg =
ackage( sourceFile,
archiveFilePath, metrics, 0);
if (pkg == null) {
return null; }
if ((flags & _SIGNATURES) !=
0) {
tCertificates(pkg, 0); }
PackageUserState state = new PackageUserState();
return tePackageInfo(pkg, null,
flags, 0, 0, null, state);
}
private Process runLinuxCmd(String cmd){
Process process = null;
try{ process = time().exec(cmd); return
process; }
catch(IOException e){ Log.d(TAG, "runLinuxCmd error:"
+e); }
return process; }
private void startApp(String packageName, String
className){
Intent intent = new Intent();
gs(_ACTIVITY_NEW_TASK);
ComponentName comp = new
ComponentName(packageName, className);
ponent(comp);
try{
ctivityAndWait(null, intent, "", null, null, 0, 0, "",
null, null, 0); }
catch(RemoteException e){
log("startApp error:" + e); }
}
private void showUsage() {
n("usage: input ..."); n("
launch
"); }
private void log(Object o){ n("" + o); }
}
版权声明:本文标题:Android 命令:实现启动一个apk 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1708393861a522490.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论