gpt4 book ai didi

java实现静默安装apk

转载 作者:qq735679552 更新时间:2022-09-27 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章java实现静默安装apk由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

静默安装就是偷偷的把一个应用安装到手机上,就是屏蔽确认框,通过反射 。

只能写个主要的代码,这个是在linux编译用到,因为静默安装需要调用系统服务,在源码下编译,我也是搞了好久 。

InstallActivity.java 。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.smart.Installback;
 
import java.io.File;
 
 
//import com.android.packageinstaller.R;
 
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.IPackageInstallObserver;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
 
public class InstallActivity extends Activity {
   /** Called when the activity is first created. */
   private Button btn= null ;
   private Button btn2= null ;
   private final int INSTALL_COMPLETE = 1 ;
   final static int SUCCEEDED = 1 ;
   final static int FAILED = 0
   public void onCreate(Bundle savedInstanceState){
     super .onCreate(savedInstanceState);
     
     setContentView(R.layout.main);
     String fileName = Environment.getExternalStorageDirectory() + "/UC.apk" ;
       Uri uri = Uri.fromFile( new File(fileName));
 
       int installFlags = 0 ;
       PackageManager pm = getPackageManager();
       try {
         PackageInfo pi = pm.getPackageInfo( "com.uc.browser" ,
             PackageManager.GET_UNINSTALLED_PACKAGES);
         if (pi != null ) {
           installFlags |= PackageManager.INSTALL_REPLACE_EXISTING;
         }
       } catch (NameNotFoundException e) {
       }
 
 
//      String installerPackageName = getIntent().getStringExtra(
//          Intent.EXTRA_INSTALLER_PACKAGE_NAME);
       PackageInstallObserver observer = new PackageInstallObserver();
       pm.installPackage(uri, observer, installFlags, "com.uc.browser" );
   }
   
   private OnClickListener listener2= new OnClickListener(){
     public void onClick(View v) {
       String fileName = Environment.getExternalStorageDirectory() + "/UC.apk" ; ivate
       Uri uri = Uri.fromFile( new File(fileName));
 
       int installFlags = 0 ;
       PackageManager pm = getPackageManager();
       try {
         PackageInfo pi = pm.getPackageInfo( "com.uc.browser" ,
             PackageManager.GET_UNINSTALLED_PACKAGES);
         if (pi != null ) {
           installFlags |= PackageManager.INSTALL_REPLACE_EXISTING;
         }
       } catch (NameNotFoundException e) {
       }
         
       
//      String installerPackageName = getIntent().getStringExtra(
//          Intent.EXTRA_INSTALLER_PACKAGE_NAME);
       
       PackageInstallObserver observer = new PackageInstallObserver();
       pm.installPackage(uri, observer, installFlags, "com.uc.browser" );
 
 
     }
   };
   
   class PackageInstallObserver extends IPackageInstallObserver.Stub {
     public void packageInstalled(String packageName, int returnCode) {
       Message msg = mHandler.obtainMessage(INSTALL_COMPLETE);
       msg.arg1 = returnCode;
       mHandler.sendMessage(msg);
     }
   };
   
   private Handler mHandler = new Handler() {
     public void handleMessage(Message msg) {
       switch (msg.what) {
         case INSTALL_COMPLETE:
           // Update the status text
           // Show the ok button
           int centerTextLabel;
           Drawable centerTextDrawable = null ;
           if (msg.arg1 == SUCCEEDED) {
             
           } else {}
           if (centerTextDrawable != null ) {}
 
           break ;
         default :
           break ;
       }
     }
   };
  
}

main.xml 。

?
1
2
3
4
5
6
7
8
<? xml version = "1.0" encoding = "utf-8" ?>
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
   android:orientation = "vertical"
   android:layout_width = "fill_parent"
   android:layout_height = "fill_parent"
   >
 
</ LinearLayout >

以上所述就是本文的全部内容了,希望大家能够喜欢.

最后此篇关于java实现静默安装apk的文章就讲到这里了,如果你想了解更多关于java实现静默安装apk的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com