I am developing an application that will randomly set a ringtone from a list of tones user has already selected.
While my code works for Android N and above, I am facing problems with Android M and below. I've search a lot for the solution. But could not find any.
Here is my code snippet that is setting the ringtone.
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),
RingtoneManager.TYPE_RINGTONE,
uri);
Here is the link to entire file.
Here is my manifest file.
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
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>
</application>
Here is the error log that is generated while the application is running
11-11 09:09:32.914 3292-3292/? W/Binder_1: type=1400 audit(0.0:32): avc: denied { read } for path="/storage/emulated/0/iphone6.mp3" dev="fuse" ino=23 scontext=u:r:system_server:s0 tcontext=u:object_r:fuse:s0 tclass=file permissive=0
11-11 09:09:32.935 1611-3697/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 336)
11-11 09:09:32.935 1611-3697/system_process I/ActivityThread: Removing dead content provider:android.content.ContentProviderProxy#b69350e
11-11 09:09:32.937 1611-3697/system_process W/ActivityManager: unstableProviderDied: caller 1000 says ContentProviderConnection{ca0b2f/com.android.externalstorage/.ExternalStorageProvider->1611:system/1000 s0/0 u1/1 +23ms} died, but we don't agree
11-11 09:09:32.934 3292-3292/? W/Binder_1: type=1400 audit(0.0:33): avc: denied { read } for path="/storage/emulated/0/iphone6.mp3" dev="fuse" ino=23 scontext=u:r:system_server:s0 tcontext=u:object_r:fuse:s0 tclass=file permissive=0
11-11 09:09:32.954 1611-3697/system_process E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 336)
11-11 09:09:32.954 1611-3697/system_process W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: Failed opening content provider: content://com.android.externalstorage.documents/document/primary%3Aiphone6.mp3
11-11 09:09:32.963 1611-3697/system_process W/ActivityManager: Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from (null) (pid=1328, uid=1013) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
11-11 09:09:32.964 1328-1680/? E/MediaPlayerService: Couldn't open fd for content://com.android.externalstorage.documents/document/primary%3Aiphone6.mp3
11-11 09:09:32.965 1611-3697/system_process E/MediaPlayer: Unable to create media player
11-11 09:09:32.965 1611-3697/system_process D/Ringtone: Problem opening; delegating to remote player
11-11 09:09:32.954 3293-3293/? W/Binder_2: type=1400 audit(0.0:34): avc: denied { read } for path="/storage/emulated/0/iphone6.mp3" dev="fuse" ino=23 scontext=u:r:system_server:s0 tcontext=u:object_r:fuse:s0 tclass=file permissive=0
Please help me solve this issue. Thanks in advance
I've searched for how to get android.permission.MANAGE_DOCUMENTS permission. What I have gathered is it's security level is of signature and only applications that come with android can have that permission.
Please check your error properly
Here i can see requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
and also you have to use runtime permission for those permission
Related
So I am currently trying to import multidex into my project, I have followed the provided documentations/QnA
Android Application using Firebase database keeps crashing when launching?
https://developer.android.com/studio/build/multidex#java
and have done the following amends to my build.gradle app file:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.finalyearprojectapp"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
multiDexKeepFile file('multidex-config.txt')
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation "androidx.multidex:multidex:2.0.1"
//implementation 'com.android.support:multidex:1.0.3'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-firestore:22.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
I have followed the documentation until it has mentioned that I am needed to implement the following code into my android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="androidx.multidex.MultiDexApplication" >
...
</application>
</manifest>
I have added this to the manifest, my XML:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.finalyearprojectapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="androidx.multidex.MultiDexApplication" >
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainScreen" />
<activity android:name=".RegisterActivity" />
<activity android:name=".LoginActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
But now I run across this error
Failed to parse XML in C:\Users\jabze\Desktop\FinalApp\app\src\main\AndroidManifest.xml
ParseError at [row,col]:[11,43]
Message: expected start or end tag
Affected Modules: app
I have done literally every tutorial out there and I just cannot figure out the issue, i feel like giving up on this project.
I have tried extending it from each class as mentioned in documentation and all my code has errors to resolve, some with no context.
I have tried extending it using a base class which uses multidex and then trying to add it into the android manifest like this,
android:name=".BaseApp"
Then creating a class to extend from multidex
import androidx.multidex.MultiDexApplication;
public class BaseApp extends MultiDexApplication {
#Override
public void onCreate() {
super.onCreate();
}
}
This has solved the configuration problem, but now i recieve a error when trying to open my app, logcat
2021-03-29 00:28:45.035 31916-31916/? I/lyearprojectap: Not late-enabling -Xcheck:jni (already on)
2021-03-29 00:28:45.054 31916-31916/? I/lyearprojectap: Unquickening 12 vdex files!
2021-03-29 00:28:45.055 31916-31916/? W/lyearprojectap: Unexpected CPU variant for X86 using defaults: x86
2021-03-29 00:28:45.150 31916-31916/com.example.finalyearprojectapp D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar
2021-03-29 00:28:45.395 31916-31916/com.example.finalyearprojectapp D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-03-29 00:28:45.395 31916-31916/com.example.finalyearprojectapp D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-03-29 00:28:45.398 31916-31916/com.example.finalyearprojectapp I/MultiDex: VM with version 2.1.0 has multidex support
2021-03-29 00:28:45.398 31916-31916/com.example.finalyearprojectapp I/MultiDex: Installing application
2021-03-29 00:28:45.399 31916-31916/com.example.finalyearprojectapp I/MultiDex: VM has multidex support, MultiDex support library is disabled.
2021-03-29 00:28:45.419 31916-31916/com.example.finalyearprojectapp W/ComponentDiscovery: Class com.google.firebase.dynamicloading.DynamicLoadingRegistrar is not an found.
2021-03-29 00:28:45.435 31916-31916/com.example.finalyearprojectapp I/FirebaseApp: Device unlocked: initializing all Firebase APIs for app [DEFAULT]
2021-03-29 00:28:45.529 31916-31977/com.example.finalyearprojectapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
2021-03-29 00:28:45.564 31916-31916/com.example.finalyearprojectapp D/FirebaseAuth: Notifying id token listeners about user ( v9NWiRcvjMTz4y8V8kXy6f7RZdQ2 ).
2021-03-29 00:28:45.566 31916-31916/com.example.finalyearprojectapp D/AndroidRuntime: Shutting down VM
2021-03-29 00:28:45.567 31916-31916/com.example.finalyearprojectapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.finalyearprojectapp, PID: 31916
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp$IdTokenListenersCountChangedListener;
at com.google.firebase.auth.zzp.create(Unknown Source:3)
at com.google.firebase.components.ComponentRuntime.lambda$discoverComponents$0(ComponentRuntime.java:132)
at com.google.firebase.components.ComponentRuntime$$Lambda$1.get(Unknown Source:4)
at com.google.firebase.components.Lazy.get(Lazy.java:53)
at com.google.firebase.components.ComponentRuntime.doInitializeEagerComponents(ComponentRuntime.java:291)
at com.google.firebase.components.ComponentRuntime.initializeEagerComponents(ComponentRuntime.java:281)
at com.google.firebase.FirebaseApp.initializeAllApis(FirebaseApp.java:584)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:303)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:267)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:252)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2388)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2358)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)
at android.app.ActivityThread.installProvider(ActivityThread.java:7239)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6780)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6697)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.FirebaseApp$IdTokenListenersCountChangedListener" on path: DexPathList[[zip file "/data/app/~~yUZ3UTW9uE5Wv9gw7MBIVA==/com.example.finalyearprojectapp-ZqPMbXUiTbtxIQSglqq2dg==/base.apk"],nativeLibraryDirectories=[/data/app/~~yUZ3UTW9uE5Wv9gw7MBIVA==/com.example.finalyearprojectapp-ZqPMbXUiTbtxIQSglqq2dg==/lib/x86, /system/lib, /system_ext/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.google.firebase.auth.zzp.create(Unknown Source:3)
at com.google.firebase.components.ComponentRuntime.lambda$discoverComponents$0(ComponentRuntime.java:132)
at com.google.firebase.components.ComponentRuntime$$Lambda$1.get(Unknown Source:4)
at com.google.firebase.components.Lazy.get(Lazy.java:53)
at com.google.firebase.components.ComponentRuntime.doInitializeEagerComponents(ComponentRuntime.java:291)
at com.google.firebase.components.ComponentRuntime.initializeEagerComponents(ComponentRuntime.java:281)
at com.google.firebase.FirebaseApp.initializeAllApis(FirebaseApp.java:584)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:303)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:267)
at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:252)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2388)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2358)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)
at android.app.ActivityThread.installProvider(ActivityThread.java:7239)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6780)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6697)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2021-03-29 00:28:45.654 31916-31979/com.example.finalyearprojectapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
2021-03-29 00:28:45.667 31916-31979/com.example.finalyearprojectapp I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
2021-03-29 00:28:45.667 31916-31979/com.example.finalyearprojectapp I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
You want to create a Base class that extends the MultiDex if you don't have one.
public class BaseApp extends MultiDexApplication {
#Override
public void onCreate() {
super.onCreate();
}
}
Your Manifest can look like below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.finalyearprojectapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".BaseApp"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainScreen" />
<activity android:name=".RegisterActivity" />
<activity android:name=".LoginActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Edit:
You should upgrade your firebase to the latest, or at least version from 17.0.0 and above.
I was told that According to firebase release notes May 07, 2019, it says; "If you use Firebase Authentication, update to firebase-auth v17.0.0 or later to ensure functionality alignment with other updated Firebase libraries."
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.
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" />
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
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.