Как устранить ошибку синтаксического анализа пакета при установке файла apk в Android Nougat - PullRequest
0 голосов
/ 28 мая 2018

Я работаю над установкой APK файла, присутствующего в устройстве программно.Вот мой код.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        askForPermission(Manifest.permission.READ_EXTERNAL_STORAGE,0x4);
        askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,0x3);

        Button button = findViewById(R.id.install);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                Intent intent = new Intent();
                Uri photoURI = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", new File(Environment.getExternalStorageDirectory()+"/ExtractedApks/Airtel_TV_tv.accedo.airtel.wynk.apk"));
                //Uri photoURI = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", new File(Environment.getExternalStorageDirectory()+"/Download/Airtel_TV_tv.accedo.airtel.wynk.apk"));
                intent.setDataAndType(photoURI, "application/vnd.android.package-archive");
                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                startActivity(intent);



            }
        });

    }

    private void askForPermission(String permission, Integer requestCode) {
        if (ContextCompat.checkSelfPermission(MainActivity.this, permission) != PackageManager.PERMISSION_GRANTED) {
            if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, permission)) {
                ActivityCompat.requestPermissions(MainActivity.this, new String[]{permission}, requestCode);
            } else {
                ActivityCompat.requestPermissions(MainActivity.this, new String[]{permission}, requestCode);
            }
        } else {
            return;
            //Toast.makeText(this, "" + permission + " is already granted.", Toast.LENGTH_SHORT).show();
        }
    }


}


**MainActivity** - create a button to install apk file store in external memory.

/ **************************************************************************/

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.user.installapkfiles">

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:grantUriPermissions="true"
            android:exported="false"
            android:authorities="${applicationId}.provider">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_provider_paths"/>
        </provider>

    </application>

</manifest>

Manifest - Файловый провайдер, позволяющий установить другое приложение./ **************************************************************************** /

<?xml version="1.0" encoding="utf-8"?>
<paths>
<!--    <cache-path name="cache" path="." />
    <files-path name="files" path="."/>
    <external-path name="external_files" path="."/>-->

    <external-path path="Android/data/${applicationId}/" name="files_root" />
    <root-path name="root" path="/" />
    <!--<external-path path="." name="external_storage_root" />-->

</paths>

File_provider - провайдер файлов для указания внешнегоместо хранения./ **************************************************************************** /

I'm selecting package installer for installing the application. But, it is poping  "There was a problem while parsing the package".
How to resolve this error.

Thanks & Regards,
Gowtham M

1 Ответ

0 голосов
/ 28 мая 2018
1.File may be downloaded incompletely.
2.Application might be not suitable for your hardware or OS version.
3.Due to security issue settings
4.Corrupted APK file.

Чтобы устранить эту ошибку

  1.Go to the settings
  2.Scroll down & select option “security.”
  3.Check on the option “Unknown sources.”

Чтобы включить отладку по USB:

1. Go to the settings >> Scroll down then, at last, you will see
        option “About device” select it.
2. Look for option “build number.” Tap on “Build number” for 7 times.
3. You will see a message “you are now a developer.” Once you enable to
4.  go back to settings Choose “Developer options.” Tick mark "USB
            debugging."
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...