2017-08-31 68 views
0

我有我的應用程序Alarm兩項活動,在Genymotion 2.8Genymotion 2.9都工作正常。
我也有一個Media Player,它在2.8上正常工作,但當我按下MediaPlayer按鈕時在2.9上崩潰。
這是我報警活動的屏幕:
Alarm activity應用程序崩潰的按鈕按Genymotion 2.9版本,但在2.8的作品

這是屏幕,我拿到後我按2.9按鈕:
Error screen

這是logcat的後我按電話上的按鈕:

09-01 16:12:06.451 31541-31541/com.never.mediaalarmplayer E/AndroidRuntime:致命異常:主 過程:COM .never.mediaalarmplayer,PID:31541 java.lang.RuntimeException:無法啓動活動ComponentInfo {com.never.mediaalarmplayer/com.never.mediaalarmplayer.MediaPlayer}:java.lang.SecurityException:Permission Denial:reading com.android。 providers.media.MediaProvider uri content:// media/external/audio/media from pid = 31541,uid = 10174需要android.permission.READ_EXTERNAL_STORAGE或grantUriPermission() at android.app.ActivityThr ead.performLaunchActivity(ActivityThread.java:2724) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread $ H .handleMessage(ActivityThread.java:1527) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:203) at android.app.ActivityThread.main (ActivityThread.java:6251) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1063) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924) 由於:java.lang.SecurityException:Permission Denial:reading com.android.providers.media.MediaProvider uri content:// media/external/audio/media from pid = 31541,uid = 10174需要android.permission.READ_EXTERNAL_STORAGE或grantUriPermission() at android.os.Parcel.readException(Parcel.java:1683) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils的.java:188) 在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140) 在android.content.ContentProviderProxy.query(ContentProviderNative.java:421) 在android.content.ContentResolver.query(ContentResolver.java :537)(MediaPlayer.java:at android.content.ContentResolver.query(ContentResolver.java:479) at com.never.mediaalarmplayer.MediaPlayer.getSongList(MediaPlayer.java:138) at com.never.mediaalarmplayer.MediaPlayer.onCreate(MediaPlayer.java: 41) at android.app.Activity.performCreate(Activity.java:6666) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789) at android.app.ActivityThread.-wrap12(ActivityThread.java) 在android.app。在android.app.android.os.Looper.loop(Looper.java:203) 處的android.os.Handler.dispatchMessage(Handler.java:110) 處的ActivityThread $ H.handleMessage(ActivityThread.java:1527) 。 ActivityThread.main(ActivityThread.java:6251) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1063) at com .android.internal.os.ZygoteInit.main(ZygoteInit.java:924)

我有請求權限插入清單中的命令已經可能需要更多的東西:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.never.mediaalarmplayer"> 
android:versionCode = "1" 
    android:versionName="1.0"> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

    <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" 
     android:fullBackupContent="@xml/backup_descriptor"> 
     <activity android:name=".Alarm" 
      android:launchMode="singleTop" 
      android:screenOrientation="portrait" 
      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=".MediaPlayer" 
      android:launchMode="singleTop" 
      android:screenOrientation="portrait" 
      android:label="@string/app_name" 
      /> 

     <service android:name="com.never.mediaalarmplayer.MusicService" /> 
     <receiver android:name=".AlarmReceiver"/> 
    </application> 

</manifest> 

logcat的2.9:

09-02 06:34:47.269 666-677/system_process I/ActivityManager: START u0 {cmp=com.never.mediaalarmplayer/.MediaPlayer} from uid 10060 on display 0 
09-02 06:34:47.269 666-723/system_process W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 4, track 48000 Hz, output 44100 Hz 
09-02 06:34:47.313 1148-1167/android.process.media E/DatabaseUtils: Writing exception to parcel 
                    java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=2012, uid=10060 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission() 
                     at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:605) 
                     at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:480) 
                     at android.content.ContentProvider$Transport.query(ContentProvider.java:211) 
                     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112) 
                     at android.os.Binder.execTransact(Binder.java:507) 
09-02 06:34:47.313 2012-2012/com.never.mediaalarmplayer D/AndroidRuntime: Shutting down VM 
09-02 06:34:47.318 2012-2012/com.never.mediaalarmplayer E/AndroidRuntime: FATAL EXCEPTION: main 
                      Process: com.never.mediaalarmplayer, PID: 2012 
                      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.never.mediaalarmplayer/com.never.mediaalarmplayer.MediaPlayer}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=2012, uid=10060 requires android.permission.READ_EXTERNAL_STORAGE, 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.media.MediaProvider uri content://media/external/audio/media from pid=2012, uid=10060 requires android.permission.READ_EXTERNAL_STORAGE, 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 com.never.mediaalarmplayer.MediaPlayer.getSongList(MediaPlayer.java:138) 
                       at com.never.mediaalarmplayer.MediaPlayer.onCreate(MediaPlayer.java:41) 
                       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) 

它沒有我的手機上無論是 - 我有3諾基亞與Android 7.0。
謝謝你的答案!

+0

你可以添加'adb logcat'的輸出嗎? –

+0

我是新來的,所以我會問,我必須在調試模式下按Mediaplayer按鈕,然後得到adb logcat吧?如果沒有請解釋我是一個新手...非常感謝你! – Never

+0

是的,這樣做,但基於手機中的logcat,它看起來像是Android版本的問題。您是否在Genymotion 2.8和2.9上使用相同的Android版本? –

回答

0

READ_EXTERNAL_STORAGE是自Android 6.0以來的運行時權限。 在清單中添加權限請求是不夠的。應用程序應該在運行時請求權限。如果你不想這樣做,請改爲22或更少。

在Genymotion的實現中存在崩潰的原因。恕我直言(我的猜測),Genymotion 2.8中的MediaProvider無法訪問外部存儲,但2.9。

+0

謝謝你的幫助,併爲我延誤一段時間後的延誤感到抱歉。我非常感謝! – Never

0

按照logcat中的這一部分:

EXCEPTION: main Process: com.never.mediaalarmplayer, PID: 31541 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.never.mediaalarmplayer/com.never.mediaalarmplayer.MediaPlayer}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=31541, uid=10174 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

您的應用程序試圖訪問外部存儲,所以你必須在相應的權限添加到您的Android清單文件。請參閱https://developer.android.com/guide/topics/data/data-storage.html#filesExternal瞭解更多詳情。

+0

我已經有權限請求,我也在帖子中添加了我的清單,也許它需要更多的東西加入工作。謝謝你的回答:)。 – Never

+0

謝謝你,我知道你嘗試過,你真的幫我理解了一些事情。 – Never

相關問題