When I press button to open the camera, my app crashes.
LogCat:
05-18 19:33:41.644 386-2041/? E/CameraService: Permission Denial: can't use the camera pid=18519, uid=10159
05-18 19:33:41.648 18519-18519/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: involved.pose9, PID: 18519
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.<init>(Camera.java:511)
at android.hardware.Camera.open(Camera.java:368)
at involved.pose9.CameraActivity$1.onClick(CameraActivity.java:48)
at android.view.View.performClick(View.java:5201)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Add this to your manifest:
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
Use this
To call the camera you can use:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivity(intent);
The image will be automatically saved in a default directory.
And you need to set the permission for the camera in your AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA"> </uses-permission>
Now using above approach Devices with no camera or devices only with front camera won't be able to find/install the app.
Add this to your manifest:
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
Related
I want to record my voice, store that to a file, then encode the file to base64 string. So I use the built in recorded using intent like this:
Intent recSound= new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(recSound, RESULT_CAPTURE_AUDIO);
The built in audio recorder pops up, and I record my voice, then when I exit the recorded, it goes back to my application calling this function:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ((resultCode == RESULT_OK) && (requestCode == RESULT_CAPTURE_AUDIO)) {
uri = data.getData();
File f = new File(uri.getPath());
try {
byte[] bytes;
bytes = FileUtils.readFileToByteArray(f); << < crashes here
String b64 = Base64.encodeToString(bytes, Base64.URL_SAFE + Base64.NO_WRAP);
} catch (IOException e) {
e.printStackTrace();
}
}
}
The URI looks fine and I can even play back the URI, but when I try to read the bytes from the URI converted to a path so that I can convert it to base64, there is an exception thrown telling that the file doesn't exist.
Here is my manifest, and I also get permission at the beginning of the MainActivity:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT"/>
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Here is the exception. The exact code is not shown above because it's complicated so it may not match what you see exactly in the exception.
07-16 19:38:37.854 W/System.err: java.io.FileNotFoundException: File '/internal/audio/media/37' does not exist
07-16 19:38:37.864 V/InputMethodManager: focusIn: android.support.v4.widget.DrawerLayout{41b3ee08 VFE..... .F...... 0,84-540,922 #7f0d0091 app:id/drawerLayout}
07-16 19:38:37.864 W/System.err: at org.apache.commons.io.FileUtils.openInputStream(FileUtils.java:136)
07-16 19:38:37.864 W/System.err: at org.apache.commons.io.FileUtils.readFileToByteArray(FileUtils.java:994)
07-16 19:38:37.864 W/System.err: at com.example.ns.app.MySendImageAsync.doInBackground(MySendImageAsync.java:88)
07-16 19:38:37.884 W/System.err: at com.example.ns.app.MySendImageAsync.doInBackground(MySendImageAsync.java:27)
07-16 19:38:37.894 W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-16 19:38:37.894 W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-16 19:38:37.894 W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-16 19:38:37.904 W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-16 19:38:37.904 W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-16 19:38:37.904 W/System.err: at java.lang.Thread.run(Thread.java:841)
getPath() on a Uri only has meaning if the scheme is file. Your scheme is content.
Use getContentResolver().openInputStream() to get an InputStream on the content. This works for both file and content schemes.
I want to read SMS using a content resolver. I've added permissions in the manifest file like this:
<uses-permission android:name="android.permission.READ_SMS"/>
Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null); //line that gives exception
cur.close();}
But it's giving an error:
02-22 02:55:36.429 18963-18963/inc.osi.imossis E/AndroidRuntime: FATAL EXCEPTION: main
Process: inc.osi.imossis, PID: 18963
java.lang.RuntimeException: Unable to start activity ComponentInfo{inc.osi.imossis/inc.osi.imossis.MainActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider uri content://sms/inbox from pid=18963, uid=10059 requires android.permission.READ_SMS, or grantUriPermission()
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.telephony.SmsProvider uri content://sms/inbox from pid=18963, uid=10059 requires android.permission.READ_SMS, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1599)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
at android.content.ContentResolver.query(ContentResolver.java:491)
at android.content.ContentResolver.query(ContentResolver.java:434)
at inc.osi.imossis.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
The complete manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="inc.osi.imossis">
<uses-permission android:name="android.permission.READ_SMS"/>
<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"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
How do I solve it?
Have you tried cleaning and re-building the project?
edit: Can you try checking and requesting the permission at run-time?
final private int REQUEST_READ_SMS_ID = 1; // A constant needed for callback
int hasReadSMSPermission = checkSelfPermission(Manifest.permission.READ_SMS);
if (hasReadSMSPermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[] {Manifest.permission.hasReadSMSPermission }, REQUEST_CODE_ASK_PERMISSIONS);
return;
}`
Uninstall the app and install again and try.
As manifest changes does not reflect on re-installations sometimes.
If I am not wrong, may be you have modifies the manifest file after installation.
Just try your luck, it may work.
So I found the problem after 2 days of Headbanging search for solution there is a bug in Emulator of API 23 if Any one Else faces this problem just run it on a different device or on emulator of api level 18 or 19 it'll work. Thanks
Here's a problem that's really getting to me, whenever I try to launch my application's main activity, I get the error in LogCat:
java.lang.RuntimeException: Unable to start activity ComponentInfo{me.kworden.atic/me.kworden.atic.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c00a9
The stack trace says that the problem is my super.onCreate(savedInstanceState) in my onCreate() method, which is frustrating me, because I can't control the superclass method.
The content layout I'm using is only a LinearLayout, so I don't think it is necessary for you all to see my xml file, although I will post on request.
I've seen the other similar problems on SO, but the only answers were "Clean/Rebuild the project" which hasn't done anything for me. I'm using Android Studio ver. 1.1.0 if this is a known problem, but I haven't seen any known bugs.
Here is my MainActivity, I've stripped out most of the code in order to pinpoint the problem, but now it seems that super.onCreate is the culprit; despite being extremely barebones, my app still fails to even start (i.e. I get "Unfortunately, app has stopped.").
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
// Create the activity and set the main content view //
super.onCreate(savedInstanceState); // This is line 17, per the stack trace //
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the main menu to the toolbar //
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if(id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is my full stack trace:
03-16 23:16:33.572 1494-1494/me.kworden.atic E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: me.kworden.atic, PID: 1494
java.lang.RuntimeException: Unable to start activity ComponentInfo{me.kworden.atic/me.kworden.atic.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c00a9
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f0c00a9
at android.content.res.Resources.getValue(Resources.java:1233)
at android.content.res.Resources.getDrawable(Resources.java:756)
at android.content.Context.getDrawable(Context.java:402)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3514)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3561)
at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1916)
at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:151)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
at me.kworden.atic.MainActivity.onCreate(MainActivity.java:17)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
If anyone stumbles on this in the future I want to make sure that you can get an answer...
The problem was that certain tags that are available only to Material and Android 5.0+ were being used in my styles. So I instead made a res/values-v21/styles.xml folder and put my appropriate settings in there. That fixed the issue.
Remove setContentView(R.layout.activity_main); method
after removing this method if it run successfully then your layout id cannot be gernerated.
and also make sure that your layout id is generated or not in R.java file
open manifest file check application package and activity. that is included or not included in file and also check style of application
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="yourapplicationpackage" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
If you using tag <view> on xml file just change tag <view> to <View>
How can I resolve this error?
Caused by: java.lang.illegalargumentexception
11-01 11:08:12.845: E/AndroidRuntime(28885): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the element:
google-play-services_lib Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gms"
android:versionCode="4030530"
android:versionName="4.0.30 (889083-30)" >
<uses-sdk android:minSdkVersion="8"/>
</manifest>
public void loginGooglePlus() {
aHelper.setup(this, GameHelper.CLIENT_APPSTATE | GameHelper.CLIENT_GAMES);
mHelper = aHelper.getAppStateClient();
//crash is here
mHelper.connect();
}
Full error log:
11-01 11:38:13.507: E/AndroidRuntime(31297): FATAL EXCEPTION: main
11-01 11:38:13.507: E/AndroidRuntime(31297): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.application.android.aja/com.company.application.android.aja.BeetleBattleAndroidActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
11-01 11:38:13.507: E/AndroidRuntime(31297): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2077)
11-01 11:38:13.507: E/AndroidRuntime(31297): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
11-01 11:38:13.507: E/AndroidRuntime(31297): at android.app.ActivityThread.access$600(ActivityThread.java:134)
11-01 11:38:13.507: E/AndroidRuntime(31297): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
11-01 11:38:13.507: E/AndroidRuntime(31297): at android.os.Handler.dispatchMessage(Handler.java:99)
11-01 11:38:13.507: E/AndroidRuntime(31297): at android.os.Looper.loop(Looper.java:154)
11-01 11:38:13.507: E/AndroidRuntime(31297): at android.app.ActivityThread.main(ActivityThread.java:4624)
11-01 11:38:13.507: E/AndroidRuntime(31297): at java.lang.reflect.Method.invokeNative(Native Method)
11-01 11:38:13.507: E/AndroidRuntime(31297): at java.lang.reflect.Method.invoke(Method.java:511)
11-01 11:38:13.507: E/AndroidRuntime(31297): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:965)
11-01 11:38:13.507: E/AndroidRuntime(31297): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:732)
11-01 11:38:13.507: E/AndroidRuntime(31297): at dalvik.system.NativeStart.main(Native Method)
11-01 11:38:13.507: E/AndroidRuntime(31297): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
11-01 11:38:13.507: E/AndroidRuntime(31297): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
11-01 11:38:13.507: E/AndroidRuntime(31297): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
11-01 11:38:13.507: E/AndroidRuntime(31297): at com.google.android.gms.internal.de.connect(Unknown Source)
11-01 11:38:13.507: E/AndroidRuntime(31297): at com.google.android.gms.appstate.AppStateClient.connect(Unknown Source)
11-01 11:38:13.507: E/AndroidRuntime(31297): at com.company.application.android.aja.BeetleBattleAndroidActivity.loginGooglePlus(BeetleBattleAndroidActivity.java:153)
11-01 11:38:13.507: E/AndroidRuntime(31297): at com.company.application.android.aja.BeetleBattleAndroidActivity.onCreate(BeetleBattleAndroidActivity.java:143)
11-01 11:38:13.507: E/AndroidRuntime(31297): at android.app.Activity.performCreate(Activity.java:4509)
11-01 11:38:13.507: E/AndroidRuntime(31297): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
11-01 11:38:13.507: E/AndroidRuntime(31297): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2041)
11-01 11:38:13.507: E/AndroidRuntime(31297): ... 11 more
You need to add the following in your manifest:
<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
...
</application>
EDIT:
This information can be found in the logcat error msg as well as on Setting Up Google Play Services (Thanks Brais Gabin)
#Benoit'a answer has exact solution i am answering with additional knowledge:
1. one way as Benoit answered is add following inside application tag of AndroidManifest.xml
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
2. we can directly add the version code like
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
4030500 is version code which is stored inside
google-play-services_lib>res>values>version.xml
Like
<integer name="google_play_services_version">4030500</integer>
Conclusion: Latest google play services requires a version name, which is to be mentioned using <meta-data .. /> inside AndroidManifest.xml
Note: I would strongly recommend to use 1st way
A few things changed since you asked that question. If you're using Google Play services 7.0 or newer, Gradle will automatically merge manifests and include the required meta-data for you.
Citing Ian Lake:
(...) Google Play services
7.0 also has one other time saving feature if you're using Gradle: it automatically includes the
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
entry in your AndroidManifest.xml for you - no need to manually add
it! Perfect example of simple Manifest merging where libraries can
add required meta-data, receivers, permissions, and anything else they
made need - one less thing to forget!
Note: this does not apply to the full play-services or
play-services-all-wear AARs - only the granular AARs have this built
in.
I did create a file "version.xml" in the res/values folder of the included copy of google services and pasted the code:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<integer name="google_play_services_version">4030500</integer>
</resources>
the original copy missed the file and it did solve my problem
Just make sure to add the below two meta-data tags to 'your' application's AndroidManifest.xml
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR_API_KEY"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
This solution worked for me.
I imported my existing project from Eclipse to Android Studio, In Eclipse project Integers.xml was containing hardcoded value as following
<integer name="google_play_services_version">5089000</integer>
causing version conflict with latest version of Play Services being built by Android Studio. after removing this line from Integers.xml it started working for me.
If you still having error try this one.
it worked for me
<meta-data
tools:replace="android:value"
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Add <meta-data>after closing <application> tag. This solved my problem
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.