Android原生接口静默安装

    protected Context mContext;
     public void setContext(Context context) {
        mContext = context;
    }
     @Override
    protected void onCreate(Bundle savedInstanceState) {
    	//do something....
		setContext(this);
		//do something....
	}     
 String ResourcePath = Environment.getExternalStorageDirectory().getAbsolutePath();   //内部存储设备路径
                String apkPath =ResourcePath  + "/Download/";
                File apkFile = new File("/sdcard/Download/tc22_sign.apk");

                Intent intent = new Intent(Intent.ACTION_VIEW);
                Uri apkUri = FileProvider.getUriForFile(mContext.getApplicationContext(), mContext.getPackageName() + ".provider", apkFile);
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(intent);

========================AndroidManifest.xml==============
 <application>
        <!--            android:name="androidx.core.content.FileProvider"-->
<!--        android:name="android.support.v4.content.FileProvider"-->
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="br.com.phoebus.mistore.client.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>
    </application>
===================res/xml/=================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <external-path name="name" path="Download" />
</resources>

=================================build.gralde(app)==============
android {
    compileSdkVersion 26
//    buildToolsVersion "28.0.3"
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "br.com.phoebus.mistore.client"/*"com.example.liuw.camera2demo"*/
        minSdkVersion 19
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
=====================同步一个编译问题 build.gradle新增代理================
buildscript {
//    ext.kotlin_version = '1.5.0'

    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }

        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }
        jcenter()
//        google()
//        maven{ url 'https://maven.aliyun.com/repository/google' }
//        maven{ url 'https://maven.aliyun.com/repository/jcenter' }
//        maven{url 'http://maven.aliyun.com/nexus/content/groups/public'}

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
//        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }

        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }
//        google()
        jcenter()
//        maven{ url 'https://maven.aliyun.com/repository/google' }
//        maven{ url 'https://maven.aliyun.com/repository/jcenter' }
//        maven{url 'http://maven.aliyun.com/nexus/content/groups/public'}
    }
}

你可能感兴趣的:(android)