플레이 스토어 https://partner. 호스트였든 프롬프트합니다 실행하십시오 쉽게 설치할 수 있습니다.
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.parse("content:///path/to/your.apk"),
"application/vnd.android.package-archive");
startActivity(promptInstall);
또는
Intent goToMarket = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.package.name"));
startActivity(goToMarket);
그러나 user& , # 39 의 권한 없이 명시성 자파크스 설치할 수 없습니다. 해당 프로그램은 하지 않는 한 장치 및 뿌리 깊다.
File file = new File(dir, "App.apk");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
전 그 후, 이 같은 문제 및 여러 시도_횟수 협력했습니다 아웃해야 가져다줄래요 this way. # 39, t know why i don& 설정을 따로 있지만, 데이터 및 유형 망친 내 의도.
이 질문에 모두 적용할 수 있는 솔루션을 제공하는 '의 23 세 이하 타르제스데크버시온. 즉, 레벨 24 에 안드로이드 ᄂ씨 apiu 잔인하니, 그러나, 다음 idfsysobject. 및 중단 작동하지 않습니다.
android.os.FileUriExposedException: file:///storage/emulated/0/... exposed beyond app through Intent.getData()
이 때문에 '열린우리당' 을 시작으로 안드로이드 24, 이 사실을 다운로드한 파일을 주소지정에 변경되었습니까. 예를 들어 '기본 외부 app 에 저장된 파일 시스템 설치 파일 이름이' 아파나기스파크 패키지 이름 '와' 로 코맥렉사 플레스테스트 약간만이라도
'file:///storage/emulated/0/Android/data/com.example.test/files/appName.apk'
반면, '아래' 와 같은 일이 위한 API 23
content://com.example.test.authorityStr/pathName/Android/data/com.example.test/files/appName.apk
'24' 의 apiu 잔인하니.
이에 대한 자세한 내용은 korea. here and I am not going to go through it.
이 질문에 대한 답을 얻을 수 있다 ',' 24 '의' 타르제스데크버시온 잔인하니 한 다음 단계: 안드로이드마니페스트리스메르 다음을 추가합니다.
<application
android:allowBackup="true"
android:label="@string/app_name">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.authorityStr"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths"/>
</provider>
</application>
xml 버전을 = " < 1.0";;? 인코딩입니다 = " utf-8" >;;? 안드로이드 (http://schemas.android.com/apk/res/android") = " >;;; 패스 < xmlns 를: 외부 경로 <. name = " pathName"; 경로 = " pathValue" />;; < /paths>;
이 '와' 열린우리당 '에 나와 있는 대표적인 컨텐트입니다 경로명입니다 에로남이네 위 예제 파스발루' 은 실제 시스템 상의 경로. 하고, ." " 것이 좋습니다. (작은 따옴표 제외) 의 하위 파스발루 위 않으려면 별도의 추가.
파일 디렉토리 = 콘테스트롬게테스터날피레스트리 (null). = 새 파일을 파일 (디렉토리, 파일_이름); Uri fileUri = 우리스프롬필레 (파일). if (= 24, Build.VERSION.SDK_INT >) { fileUri = 필리프로비드리게투리퍼필레 (컨텍스트로 콘테스트롬제팩건임 (), 파일). } 의도 의도 = new Intent (Intent.ACTION_VIEW, fileUri); 베르트랑롬푀테스트라 (Intent.EXTRA_NOT_UNKNOWN_SOURCE, 진정한 의미의). 베르트랑.세다타란티페 (fileUri, " application/vnd.android"; + " .package-archive";). 베르트랑.세플라그스 (Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flag_activity_new_task); 베르트랑드라데플라그스 (Intent.FLAG_GRANT_READ_URI_PERMISSION); 콘테스트리스타르타스티비티 (의도). 스티비티스피니시 ();
나는 기록되었으므로 오버클로킹된 AutoUpdate 라이브러리란 here 내가 있는 사용해야만 한다.
글쎄, 난 더 팠 프라카제인스탈러 애플리케이션에서 발견되는 것으로, 안드로이드 소스.
https://github.com/android/platform_packages_apps_packageinstaller
내가 찾은 것이 분명한 에서 권한이 필요합니다.
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
확인 후 테스트타사의 설치 및 실제 프로세스
Intent newIntent = new Intent();
newIntent.putExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO, mPkgInfo.applicationInfo);
newIntent.setData(mPackageURI);
newIntent.setClass(this, InstallAppProgress.class);
String installerPackageName = getIntent().getStringExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME);
if (installerPackageName != null) {
newIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, installerPackageName);
}
startActivity(newIntent);
난 그냥 내 apk 파일을 공유할 수 있는 것은 내 앱 " 절약되었습니까 Data"; 디렉토리이며 apk 파일을 읽을 수 있는 권한을 변경하십시오 데 필요한 것을 내가 할 수 있도록 하기 위해 설치된 세계 이쪽요, 그렇지 않으면 이 제도가 " 던지기, 구문 분석 오류: 분석 Package" 문제가;; 그래서 할 수 있는 솔루션을 이용해 @Horaceman 에서:
File file = new File(dir, "App.apk");
file.setReadable(true, false);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
따라서 다른 많이유!
private static final String APP_DIR = Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyAppFolderInStorage/";
private void install() {
File file = new File(APP_DIR + fileName);
if (file.exists()) {
Intent intent = new Intent(Intent.ACTION_VIEW);
String type = "application/vnd.android.package-archive";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri downloadedApk = FileProvider.getUriForFile(getContext(), "ir.greencode", file);
intent.setDataAndType(downloadedApk, type);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
intent.setDataAndType(Uri.fromFile(file), type);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
getContext().startActivity(intent);
} else {
Toast.makeText(getContext(), "ّFile not found!", Toast.LENGTH_SHORT).show();
}
}
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="ir.greencode"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths" />
</provider>
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="your_folder_name" path="MyAppFolderInStorage/"/>
</paths>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
>. 응용 프로그램 패키지를 설치하기 요청할 수 있습니다. 이 권한을 갖고 25 이상의 애플리케이션을 사용하기 위해 Intent.ACTION_INSTALL_PACKAGE. api 를 대상으로 한다.
>. >. 당국은 >, # 있는지 확인하십시오 공급자입니다 같은!
[1]: https://developer.android.com/reference/android/support/v4/content/FileProvider # 필리프로비더
market://details?id=package.name
예:
int uriIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);
String downloadedPackageUriString = cursor.getString(uriIndex);
File mFile = new File(Uri.parse(downloadedPackageUriString).getPath());
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.fromFile(mFile), "application/vnd.android.package-archive")
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
appContext.startActivity(promptInstall);
이 시도하시겠습니까
String filePath = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_FILENAME));
String title = filePath.substring( filePath.lastIndexOf('/')+1, filePath.length() );
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
MainActivity.this.startActivity(intent);
업다테노데 에서 Android App APK 설치 패키지 안에 다른 API 를 제공한다. < br> < br>;;; 온라인 및 통합하십시오 apiu 앱 업데이트 됩니다 - that& # 39 를 정의하고, s it. < br>; Api 는 현재 베타 테스트를 할 수 있지만, 이미 일부 yourself.< br> < br> 스테이드;;; 또한 그 옆에 표시되어도 시스템 - 꽤 유용한 스케쳐내 디스플레이하여 업다테노데 제공사항 메시지를 사용자에게 어떤 중요한 알 수 있습니다. < br> < br>;;; 나는 부분은 적어도 내 스스로 안드로이드 앱 개발 팀 및 사용하고 클라이언트입니다 메시지 기능을 사용할 수 있습니다.
먼저 안드로이드마니페스트리스메르 다음 줄을 추가합니다.
<uses-permission android:name="android.permission.INSTALL_PACKAGES"
tools:ignore="ProtectedPermissions" />
Apk 설치 후 다음 코드를 사용합니다.
File sdCard = Environment.getExternalStorageDirectory();
String fileStr = sdCard.getAbsolutePath() + "/MyApp";// + "app-release.apk";
File file = new File(fileStr, "TaghvimShamsi.apk");
Intent promptInstall = new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(promptInstall);
권한만으로 요청할 것을 잊지 마십시오.
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
android.Manifest.permission.READ_EXTERNAL_STORAGE
여기에 안드로이드마니페스트리스메르 사업자 및 권한.
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
...
<application>
...
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
Xml 파일을 생성 res/xml/provider_paths.xml 공급자입니다.
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>
아래 사용 예제 코드:
public class InstallManagerApk extends AppCompatActivity {
static final String NAME_APK_FILE = "some.apk";
public static final int REQUEST_INSTALL = 0;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// required permission:
// android.Manifest.permission.WRITE_EXTERNAL_STORAGE
// android.Manifest.permission.READ_EXTERNAL_STORAGE
installApk();
}
...
/**
* Install APK File
*/
private void installApk() {
try {
File filePath = Environment.getExternalStorageDirectory();// path to file apk
File file = new File(filePath, LoadManagerApkFile.NAME_APK_FILE);
Uri uri = getApkUri( file.getPath() ); // get Uri for each SDK Android
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.setData( uri );
intent.setFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK );
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
intent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, getApplicationInfo().packageName);
if ( getPackageManager().queryIntentActivities(intent, 0 ) != null ) {// checked on start Activity
startActivityForResult(intent, REQUEST_INSTALL);
} else {
throw new Exception("don`t start Activity.");
}
} catch ( Exception e ) {
Log.i(TAG + ":InstallApk", "Failed installl APK file", e);
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG)
.show();
}
}
/**
* Returns a Uri pointing to the APK to install.
*/
private Uri getApkUri(String path) {
// Before N, a MODE_WORLD_READABLE file could be passed via the ACTION_INSTALL_PACKAGE
// Intent. Since N, MODE_WORLD_READABLE files are forbidden, and a FileProvider is
// recommended.
boolean useFileProvider = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
String tempFilename = "tmp.apk";
byte[] buffer = new byte[16384];
int fileMode = useFileProvider ? Context.MODE_PRIVATE : Context.MODE_WORLD_READABLE;
try (InputStream is = new FileInputStream(new File(path));
FileOutputStream fout = openFileOutput(tempFilename, fileMode)) {
int n;
while ((n = is.read(buffer)) >= 0) {
fout.write(buffer, 0, n);
}
} catch (IOException e) {
Log.i(TAG + ":getApkUri", "Failed to write temporary APK file", e);
}
if (useFileProvider) {
File toInstall = new File(this.getFilesDir(), tempFilename);
return FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID, toInstall);
} else {
return Uri.fromFile(getFileStreamPath(tempFilename));
}
}
/**
* Listener event on installation APK file
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQUEST_INSTALL) {
if (resultCode == Activity.RESULT_OK) {
Toast.makeText(this,"Install succeeded!", Toast.LENGTH_SHORT).show();
} else if (resultCode == Activity.RESULT_CANCELED) {
Toast.makeText(this,"Install canceled!", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this,"Install Failed!", Toast.LENGTH_SHORT).show();
}
}
}
...
}
이 시도하시겠습니까
안드로이드 이름 = " 사용 권한 android.permission.install_packages"; 도구: = " 무시하시겠습니까 ProtectedPermissions";
기록하십시오 코드:
File sdCard = Environment.getExternalStorageDirectory();
String fileStr = sdCard.getAbsolutePath() + "/Download";// + "app-release.apk";
File file = new File(fileStr, "app-release.apk");
Intent promptInstall = new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(promptInstall);