0

i am working on the project named AutoUpdate with package name:com.example. and the apk i am having in my sd card also having same package name :com.example this is my method which is called for instaling the apk.the apk file is in sd card.my code is as:

private void installMarketApk() {
        // TODO Auto-generated method stub
        String fileName = Environment.getExternalStorageDirectory() + "/myapp.apk";
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
        startActivity(intent);
    }

my manifest file looks like this:

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk android:minSdkVersion="8" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:label="@string/app_name"
        android:name="com.custom.activity.mspresentation.AutoUpdateDemoActivity" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

when i run this application i am prompted to Replace application dialog "The application you are trying will replace another another application".so i just click ok for installing application. now i got do you want to install this application .this will change to : 1.Storage
2.network communication
3.phone calls ....... with install and cancel options. now i choose install,a progress bar appears with initialising and APPLICATION NOT INSTALLED.
if i have to give some permissions in manifest file? ANY SUGGESTION ?

maddy
  • 4,001
  • 8
  • 42
  • 65
  • uninstall previous app with same package name and then try again..because sometimes you can't override existing app with same package but different signature – Maneesh Nov 15 '11 at 10:28
  • @Maneesh thanks for your reply!yes packages are same what do you mean by signature? – maddy Nov 15 '11 at 10:34
  • An app is uniquely identified by its package name and the key by which is signed, by default android default key is used to sign the app, and a signature will embed in apk file which identify the app – Maneesh Nov 15 '11 at 10:38
  • @PadmaKumar thanks for pointing out the error !still not able to install it. – maddy Nov 15 '11 at 10:39
  • @Maneesh thanks for this information,however the apks i am working on are simple binaries not any involvement from market. – maddy Nov 15 '11 at 10:48
  • try changing the apk. may be some time copying the apk to external will be corrupted. Can u send the error log once. – Padma Kumar Nov 15 '11 at 10:49
  • thanks padam ,i dont know what the problem was there /or i was not able to.but i make a new apk and try,it worked thanks ! – maddy Nov 15 '11 at 11:53

2 Answers2

0

Try giving the following permissions in your Manifest file.

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

It will allow your code "Environment.getExternalStorageDirectory()" to access your SD card storage to access the api you are trying to install.

  • thanks for the reply but i dont thing any requirement for this permission because i am alredy getting apk version name,code number and package information programmatically using getPackageManager().getPackageArchiveInfo – maddy Nov 15 '11 at 10:50
  • If you have not solved this problem yet, have a look at the following links. I hope It explains how to install an app programatically. 1) . http://stackoverflow.com/questions/4604239/install-application-programmatically-on-android 2). http://stackoverflow.com/questions/4967669/android-install-apk-programmatically –  Nov 18 '11 at 09:22
  • thanks for the link ....my apk was corrupt !i just have to replace my apk with new one – maddy Nov 18 '11 at 09:57
0

may be it would be helping some one: the apk package names and target names should be shame,it was in my case.

i have deleted the previous .apk from sd card and put a new apk(may be currupted or project properties was not matching).

dont be confuse from installMarketApp here.i just put apk manually in sd card.

private void installMarketApk() { // TODO Auto-generated method stub String fileName = Environment.getExternalStorageDirectory() + "/myapp.apk";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent); }

maddy
  • 4,001
  • 8
  • 42
  • 65