Unable to instantiate application error which extends Application class - java

The below error occurs sometimes for some users.
I haven't seen it through android phones which I have for testing, but I got this crush via Google developer console.
[Error]
java.lang.RuntimeException: Unable to instantiate application com.***.***.MyApplication: java.lang.ClassNotFoundException: com.***.***.MyApplication
at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4253)
at android.app.ActivityThread.access$1400(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1301)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4950)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:997)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.***.***.MyApplication
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newApplication(Instrumentation.java:982)
at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
... 11 more
[MyApplication.java]
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
...
}
#Override
public void onTerminate() {
super.onTerminate();
}
...
}
[manifest.xml]
...
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
...
<application
android:name="com.***.***.MyApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
I've tried to find out to solve this problem.
I doubt it might be due to external SD card problem or 'public constructor'.
Because even I do not know how to reenact the situation, I can't be sure whether this is due to SD card or public constructor stuff.
I'm sure there's somebody who got this error and already know how to solve this.
Thus, please help me know what's wrong and how I can fix it.
Thanks.

add your class name in your manifest file. hope this solve your problem
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:name=".MyApplication">
........
for further reading , how to extends Application class, read here.

Related

Android WebView app crashing in emulator: null Application Context?

I'm developing a very simple Android app on a Mac in AndroidStudio and I've created an AVD based on the Nexus S. The app compiles with no issues, the emulator launches and then I get errors in logcat and the app crashes. In the emulator, an error dialog displays with the message "Unfortunately App has stopped"
Here's the logcat output (error level):
10-01 13:59:27.813 14114-14114/com.company.app E/SysUtils﹕ ApplicationContext is null in ApplicationStatus
10-01 13:59:27.832 14114-14114/com.company.app E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)
10-01 13:59:27.832 14114-14114/com.company.app E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)
10-01 13:59:27.832 14114-14114/com.company.app E/chromium﹕ [ERROR:gl_surface_egl.cc(327)] No suitable EGL configs found.
10-01 13:59:27.832 14114-14114/com.company.app E/chromium﹕ [ERROR:gl_surface_android.cc(23)] GLSurfaceEGL::InitializeOneOff failed.
10-01 13:59:27.832 14114-14114/com.company.app E/chromium﹕ [ERROR:browser_main_loop.cc(698)] GLSurface::InitializeOneOff failed
10-01 13:59:27.854 14114-14114/com.company.app E/DataReductionProxySettingListener﹕ No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
10-01 13:59:28.530 14114-14165/com.company.app A/chromium﹕ [FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
10-01 13:59:28.530 14114-14165/com.company.app A/libc﹕ Fatal signal 6 (SIGABRT), code -6 in tid 14165 (GpuThread)
I'm assuming that the first error related to ApplicationContext is the cause of the other errors, but I'm not sure about that. I've tried about 10 different methods for setting context, but the ApplicationContext error persists.
My main questions: Is the ApplicationContext error the root cause of the crash? If not, what is? What might I try to fix it?
Here's the complete application code for reference:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.app" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<uses-permission android:name="android.permission.INTERNET" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.company.app;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebSettings;
public class MainActivity extends AppCompatActivity {
private String appUrl = "http://company.com/mobile/index.php";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.setWebViewClient(new MyWebViewClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl(appUrl);
}
}
MyWebViewClient.java
package com.company.app;
import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MyWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("company.com")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
}
Here's the logcat output
That is not a Java stack trace, and therefore is not what you're looking for.
I'm assuming that the first error related to ApplicationContext is the cause of the other errors, but I'm not sure about that
That is some spurious message that you will see, even from apps that run fine.
If not, what is?
As ozbek notes, your <uses-permission> element needs to be moved outside of <application> and made a direct child of <manifest>. Your Java stack trace should mention a missing INTERNET permission.
It is possible that there are other problems, but that's definitely one.

ApplicationClass ClassNotFoundException

I'm using the application class , so I had to create the manifest file, as follows:
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
I have to work normally without problems when testing , often the error occurred in the Google Play Store error report.
But the error report is posted on the Android version 4.4 , I even tested at 4.4 operate normally.
If the person experiencing this problem help me.
java.lang.RuntimeException: Unable to instantiate application com.moonae.android.common.ApplicationClass: java.lang.ClassNotFoundException: Didn't find class "com.culturelandnew.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4524)
at android.app.ActivityThread.access$1500(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.moonae.android.common.ApplicationClass" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:993)
at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
... 11 more
<application
android.name="com.moonae.android.common.ApplicationClass"
android.icon="#drawble/ic_launcher"
android.largeHeap="true"
....>
<activity..../>
is this a typo? i have not seen this before i mean android.name to android:name..btw
quick suggestion, remove your application tag, and use the eclipse gui side to search the application class and reference it.. mostly it references the it without package name included.. like this.. =>
<application
android:name="ApplicationClass"
android:icon="#drawble/ic_launcher"
android:largeHeap="true"
....>

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo - NFC access

I have seen a number of questions similar to this one, but they seem to be specific to the classes and packages that they use. I tried some of the solutions, but did not help me. I get the following error:
03-27 14:30:08.604: D/AndroidRuntime(8057): Shutting down VM
03-27 14:30:08.604: W/dalvikvm(8057): threadid=1: thread exiting with uncaught exception (group=0x41c02c80)
03-27 14:30:08.604: E/AndroidRuntime(8057): FATAL EXCEPTION: main
03-27 14:30:08.604: E/AndroidRuntime(8057): Process: org.nick.nfc.seaccess, PID: 8057
03-27 14:30:08.604: E/AndroidRuntime(8057): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.nick.nfc.seaccess/org.nick.nfc.seaccess.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "org.nick.nfc.seaccess.MainActivity" on path: DexPathList[[zip file "/system/framework/com.android.nfc_extras.jar", zip file
Any idea, how I should address it?
Here is the beginning of the main activity:
public class MainActivity extends Activity implements OnClickListener {
private static final String TAG = MainActivity.class.getSimpleName();
private Button gpInfoButton;
private Button emvInfoButton;
private Button walletInfoButton;
private TextView infoText;
private Terminal terminal;
private CardConnection seConn;
#Override
public void onCreate(Bundle savedInstanceState) {
...
Here is my activity tag from my manifest. I have seem sometimes folks add the full package name to the manifest. Shall I do this and see what happens?
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|s mallestScreenSize"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I found a link that states the issue may be with how I have edited an xml file, which holds certificates. I have pasted the file below; removed the certs. Do you see any issue with it?
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Applications granted NFCEE access on user builds
See packages/apps/Nfc/etc/sample_nfcee_access.xml for full documentation.
-->
<!-- Google wallet release signature -->
<signer android:signature="308205bd852e" />
<!-- Sequent Wallet signature -->
<signer android:signature="30820243badc1df9d"/>
<!-- android-se-access signature-->
<signer
android:signature="3082044cbd852e">
<package android:name="org.nic.nfc.seaccess"/>
</signer>
</resources>
Here is a view of the project workspace
I just saw something in the logs, which I wanted to add to this thread. Seems like the is a "-1", and "-2" next to the package name. Is that supposed to be there, or is that the cause of my issue?
Here are the log messages I am talking about:
03-27 22:55:10.884: E/AndroidRuntime(9436): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.nick.nfc.seaccess.MainActivity" on path: DexPathList[[zip file "/system/framework /com.android.nfc_extras.jar", zip file "/data/app/org.nick.nfc.seaccess- 1.apk"],nativeLibraryDirectories=[/data/app-lib/org.nick.nfc.seaccess-1, /vendor/lib, /system/lib]]
03-27 22:58:02.104: E/AndroidRuntime(9880): Caused by: java.lang.ClassNotFoundException: Didn't find class "org.nick.nfc.seaccess.MainActivity" on path: DexPathList[[zip file "/system/framework /com.android.nfc_extras.jar", zip file "/data/app/org.nick.nfc.seaccess- 2.apk"],nativeLibraryDirectories=[/data/app-lib/org.nick.nfc.seaccess-2, /vendor/lib, /system/lib]]
From the trace: java.lang.ClassNotFoundException: Didn't find class "org.nick.nfc.seaccess.MainActivity"
This means the class org.nick.nfc.seaccess.MainActivity is undefined or can't be loaded.
Do you have a class org.nick.nfc.seaccess.MainActivity? What is the code? Does it have a default constructor? Is it declared in the manifest?

Activity is not assignable to Activity

I have read several posts for the last couple of days and i can not seem to figure out what my issue is. I have checked the Activity names and they are the same. I have also checked my manifest and I have the . in front of the activities as well.
Here is my logcat file:
02-23 16:48:22.438 1508-1508/com.pctoolman.planme.app E/AndroidRuntime﹕ FATAL
EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.pctoolman.planme.app/com.pctoolman.planme.app.PlanMeMainActivity}:
java.lang.ClassCastException: com.pctoolman.planme.app.PlanMeMainActivity cannot be
cast
to android.app.Activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.pctoolman.planme.app.PlanMeMainActivity
cannot
be cast to android.app.Activity
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pctoolman.planme.app" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.pctoolman.planme.app.PlanMeMainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.pctoolman.planme.app.NewEventSetupActivity"
android:label="#string/setup">
</activity>
</application>
PlanMeMainFragment.java
package com.pctoolman.planme.app;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class PlanMeMainFragment extends Fragment {
private Button mNewButton, mExistingButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.planme_main_fragment, parent, false);
mNewButton = (Button)v.findViewById(R.id.new_event_button);
mNewButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(getActivity(), NewEventSetupActivity.class);
getActivity().startActivity(myIntent);
}
});
return v;
}
}
PlanMeMainActivity.java
package com.pctoolman.planme.app;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
public class PlanMeMainActivity extends Fragment {
public Fragment createFragment() {
return new PlanMeMainFragment();
}
}
Change this line
public class PlanMeMainActivity extends Fragment {
to
public class PlanMeMainActivity extends FragmentActivity {
Here you can find all that you need to know about Activities and even more. Cheers
Where are you wrong?
<activity
android:name="com.pctoolman.planme.app.PlanMeMainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Why are you wrong?
The mistake is that you added the Fragment in the Manifest as
Activity. However Fragments are not activities
What you should do?
You should add the fragment in an activity and then define that activity in the
Manifest
Your PlanMeMainActivity isn't an Activity; it's a Fragment. Your activity needs to be an activity, and you can then add fragments to it.
Clean Project solved this error. The root cause of the error in my case was different, but I got the same "Activity is not assignable to Activity" error.
I faced this problem after copying existing (perfectly working) Android Project to create a new one.
After copying the project, the AppCompatActivity was not recognized causing all the activities in the Android Manifest file to show the error "activity-is-not-assignable-to-activity".
Which was solved by cleaning the project.
Your PlanMainActivity extends a Fragment. A fragment cannot be cast to an activity
Finally, I find out the solution is add following line in your dependencies:
compile 'com.android.support:support-v4:23.2.0'
just delete ".gradle" folder of your project
and press sync button .
its solved my problem
In my case the error was occurred by just installed plugin in Android Studio. So check your plugins and uninstall odd ones.
My problem was solved by Invalidating Caches and Restarting after having Cleaned the Project.

Inconsistent Parsing Error when trying to install an unsigned remote .apk file

I'm currently working on an app that will not go on the play store and needed some sort of update routine.
I got it working so when the user presses a button the app downloads an apk file hosted on one of our servers. That part works fine. Here's the interesting stuff...
When I try to start the intent to install the file, I get the following parse error:
"Parse Error There is a problem parsing the package"
This error happens everytime no matter what on android version 4.0.3. Here is the logcat:
10-03 18:36:05.212: D/asset(567): failed to open Zip archive '/mnt/sdcard/download/AMWireless.apk'
10-03 18:36:05.272: W/PackageParser(567): Unable to read AndroidManifest.xml of /mnt/sdcard/download/AMWireless.apk
10-03 18:36:05.272: W/PackageParser(567): java.io.FileNotFoundException: AndroidManifest.xml
10-03 18:36:05.272: W/PackageParser(567): at android.content.res.AssetManager.openXmlAssetNative(Native Method)
10-03 18:36:05.272: W/PackageParser(567): at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:487)
10-03 18:36:05.272: W/PackageParser(567): at android.content.res.AssetManager.openXmlResourceParser(AssetManager.java:455)
10-03 18:36:05.272: W/PackageParser(567): at android.content.pm.PackageParser.parsePackage(PackageParser.java:425)
10-03 18:36:05.272: W/PackageParser(567): at com.android.packageinstaller.PackageUtil.getPackageInfo(PackageUtil.java:74)
10-03 18:36:05.272: W/PackageParser(567): at com.android.packageinstaller.PackageInstallerActivity.onCreate(PackageInstallerActivity.java:277)
10-03 18:36:05.272: W/PackageParser(567): at android.app.Activity.performCreate(Activity.java:4465)
10-03 18:36:05.272: W/PackageParser(567): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-03 18:36:05.272: W/PackageParser(567): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-03 18:36:05.272: W/PackageParser(567): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-03 18:36:05.272: W/PackageParser(567): at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-03 18:36:05.272: W/PackageParser(567): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-03 18:36:05.272: W/PackageParser(567): at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 18:36:05.272: W/PackageParser(567): at android.os.Looper.loop(Looper.java:137)
10-03 18:36:05.272: W/PackageParser(567): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-03 18:36:05.272: W/PackageParser(567): at java.lang.reflect.Method.invokeNative(Native Method)
10-03 18:36:05.272: W/PackageParser(567): at java.lang.reflect.Method.invoke(Method.java:511)
10-03 18:36:05.272: W/PackageParser(567): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-03 18:36:05.272: W/PackageParser(567): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-03 18:36:05.272: W/PackageParser(567): at dalvik.system.NativeStart.main(Native Method)
10-03 18:36:05.272: W/PackageInstaller(567): Parse error when parsing manifest. Discontinuing installation
Yet, my updater works on my droid x2 running version 2.3.5. The intent to install the app goes great and once they confirm the app permissions it installs.
I was able to reproduce the parse error on version 2.3.5 here is how:
I normally just install the app through eclipse, by running it, but if I right-clicked on the package in the package explorer window used android tools to export an unsigned .apk, and tried to install the package manually it would not install.
If I use the .apk's that are in the project bin folder, it installs fine and updates fine on 2.3.5
Here is the asynctask class I use:
public class UpdateWireless extends AsyncTask<String,Void,String>{
private Context context;
public void setContext(Context contextf){
context = contextf;
}
#Override
protected String doInBackground(String... arg0) {
try {
URL url = new URL(arg0[0]);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/";
File oldFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/AMWireless.apk");
if(oldFile.exists())
{
oldFile.delete();
}
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file, "AMWireless.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
} catch (IOException e){
}
return "File Saved";
}
protected void onPostExecute(String result) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/download/"+"AMWireless.apk")), "application/vnd.android.package-archive");
startActivity(intent);
}
}
and yes I need to but something in the catch block but we will get there...
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wireless.wmaa"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.DELETE_PACKAGES"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity
android:label="#string/app_name"
android:name=".SelectServer"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>"
</activity>
<activity
android:name=".UpdateApp"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="landscape" >
<intent-filter>
</intent-filter>
</activity>
<activity
android:name=".WirelessActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:screenOrientation="landscape" >
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
Am I Exporting things from Eclipse wrong? Is it a manifest issue? Am I going about this right?
EDIT 1:
Alright narrowed it down a little more to a problem with this line on the android 4.0.3:
InputStream is = c.getInputStream();
This line throws a file not found exception, as in it can't see the file on my server and it is never downloads. Android 2.3.5 sees the file has no exceptions and downloads the and installs fine... Whats the problem here?
EDIT 2: RESOLVED
I was originally trying to host the file on a site that was served by IIS, and the old version of android didn't care, but the new version would not see the file. Once I moved the .apk to a web server running apache I had no issues. So, something is fishy with IIS or maybe my configuration of it....
Answered my own question. Was a problem with where I was hosting the file. IIS and android would not play nice together :( solution: move .apk file to apache server.

Categories