简体   繁体   English

如何编写前端程序以通过android设备安装和卸载应用程序?

[英]How can I write a front end program to install and uninstall an app over android device?

By "Program", I mean a desktop front end for installing/uninstalling apps on a phone.Can u please help me out from this? 所谓“程序”,是指用于在手机上安装/卸载应用程序的台式机前端。您能帮我这个忙吗? I am not clear what to do ? 我不清楚该怎么办?

Thnx, Praween Thnx,Praween

First copy your apk file on to your device.suppose you copy your apk fie on download folder on sd card. 首先将apk文件复制到设备上。假设您将apk文件复制到sd卡的下载文件夹中。

 String vsName=Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/";
//your path 
 File file = new File(vsName, "aaa.apk");//put here your apk file      
 System.out.println(":"+file);//checking your path is correct or not   
 Intent install=new Intent(Intent.ACTION_VIEW);
 install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");       
 install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
 startActivity(install);

for uninstall 卸载

Intent intent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("package",
getPackageManager().getPackageArchiveInfo(apkUri.getPath(), 0).packageName,null));
startActivity(intent);

Let me comments if any issue. 如果有任何问题,请让我发表评论。

You should edit your original question to clarify ( How can I write a program to install and uninstall an app over android device? ). 您应该编辑原始问题以澄清问题( 我该如何编写程序来通过android设备安装和卸载应用程序? )。 Anyhow here's my answer again: 无论如何,这是我的答案:

You can write a simple shell script that executes the following commands. 您可以编写一个简单的Shell脚本来执行以下命令。 I'm assuming you have the Android SDK installed, as it's required. 我假设您已根据需要安装了Android SDK。

To install example.apk located somewhere on your desktop hard drive: 要安装位于台式机硬盘驱动器某处的example.apk,请执行以下操作:

cd location_of_sdk\tools
adb.exe install path_to_apk\example.apk

To uninstall the app: 卸载应用程序:

cd location_of_sdk\tools
adb shell

Inside the adb shell execute: 在adb shell内执行:

cd /data/app
ls

This will display the apps installed on the device. 这将显示设备上安装的应用程序。 Look for the .apk associated with the app you want to uninstall. 查找与您要卸载的应用程序关联的.apk。 It'll look something like "com.abc.xyz.apk" - then execute: 看起来像“ com.abc.xyz.apk”-然后执行:

rm com.abc.xyz.apk
exit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM