Android权限不起作用

时间:2017-07-31 10:38:19

标签: android cordova ionic-native

我从此页https://ionicframework.com/docs/native/android-permissions/安装Android权限插件。但是,当我添加到构造函数constructor(private androidPermissions: AndroidPermissions) { }时,我的应用程序无法启动,并且在adv logcat中我出现错误Ionic Native: deviceready event fired after 826 ms当我删除private androidPermissions: AndroidPermissions应用程序工作时,我真的需要获得此权限!< / p>

应用程序启动后的完整logcat。 Iam newbee in ionic和js实际上/

07-31 13:55:06.825  6025  6025 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
07-31 13:55:06.827  6025  6025 D AndroidRuntime: CheckJNI is ON
07-31 13:55:06.840  6025  6025 D ICU     : No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
07-31 13:55:06.853  6025  6025 E memtrack: Couldn't load memtrack module (No such file or directory)

07-31 13:55:06.876  3935  3946 D DefContainer: Copying /data/local/tmp/android-debug.apk to base.apk
07-31 13:55:07.064  1961  2023 I PackageManager.DexOptimizer: Running dexopt (dex2oat) on: /data/app/vmdl487172328.tmp/base.apk pkg=io.ionic.starter isa=x86 vmSafeMode=false debuggable=true oatDir = /data/app/vmdl487172328.tmp/oat
07-31 13:55:07.072  6034  6034 W dex2oat : Unexpected CPU variant for X86 using defaults: x86
07-31 13:55:07.072  6034  6034 W dex2oat : Mismatch between dex2oat instruction set features (ISA: X86 Feature string: smp,-ssse3,-sse4.1,-sse4.2,-avx,-avx2) and those of dex2oat executable (ISA: X86 Feature string: smp,ssse3,-sse4.1,-sse4.2,-avx,-avx2) for the command line:
07-31 13:55:07.072  6034  6034 W dex2oat : /system/bin/dex2oat --zip-fd=6 --zip-location=base.apk --oat-fd=7 --oat-location=/data/app/vmdl487172328.tmp/oat/x86/base.odex --instruction-set=x86 --instruction-set-variant=x86 --instruction-set-features=default --runtime-arg -Xms64m --runtime-arg -Xmx512m --swap-fd=8 --debuggable
07-31 13:55:07.072  6034  6034 I dex2oat : /system/bin/dex2oat --debuggable
07-31 13:55:07.147  6034  6034 I dex2oat : dex2oat took 75.337ms (threads: 2) arena alloc=516KB java alloc=258KB native alloc=2MB free=1840KB
07-31 13:55:07.151  1961  1995 I ActivityManager: Force stopping io.ionic.starter appid=10053 user=-1: uninstall pkg
07-31 13:55:07.171  1961  2023 I PackageManager: Package io.ionic.starter codePath changed from /data/app/io.ionic.starter-2 to /data/app/io.ionic.starter-1; Retaining data and using new
07-31 13:55:07.171  1961  2023 W PackageManager: Code path for io.ionic.starter changing from /data/app/io.ionic.starter-2 to /data/app/io.ionic.starter-1
07-31 13:55:07.171  1961  2023 W PackageManager: Resource path for io.ionic.starter changing from /data/app/io.ionic.starter-2 to /data/app/io.ionic.starter-1
07-31 13:55:07.171  1961  1995 I ActivityManager: Force stopping io.ionic.starter appid=10053 user=-1: replace pkg
07-31 13:55:07.209  1961  2023 W Settings: Setting install_non_market_apps has moved from android.provider.Settings.Global to android.provider.Settings.Secure, returning read-only value.
07-31 13:55:07.209  1961  2023 I art     : Starting a blocking GC Explicit
07-31 13:55:07.229  1961  2023 I art     : Explicit concurrent mark sweep GC freed 12565(766KB) AllocSpace objects, 4(80KB) LOS objects, 33% free, 7MB/10MB, paused 941us total 20.001ms
07-31 13:55:07.234  1961  2023 W PackageManager: Couldn't remove dex file for package:  at location /data/app/io.ionic.starter-2/base.apk, retcode=-1
07-31 13:55:07.234  1961  2023 I ActivityManager: Force stopping io.ionic.starter appid=10053 user=0: pkg removed
07-31 13:55:07.235  6025  6025 I art     : System.exit called, status: 0
07-31 13:55:07.235  6025  6025 I AndroidRuntime: VM exiting with result code 0.
07-31 13:55:07.281  3306  3314 W SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/metrics.db.16' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
07-31 13:55:07.282  3306  3314 W SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/help_responses.db.18' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
07-31 13:55:07.283  3306  3314 W SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.google.android.gms/databases/auto_complete_suggestions.db' was leaked!  Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
07-31 13:55:07.296  1961  1961 D JobSchedulerService: Receieved: android.intent.action.PACKAGE_REMOVED
07-31 13:55:07.297  1961  2254 I InputReader: Reconfiguring input devices.  changes=0x00000010
07-31 13:55:07.302  2697  2697 D CarrierServiceBindHelper: Receive action: android.intent.action.PACKAGE_REMOVED
07-31 13:55:07.302  2697  2697 D CarrierServiceBindHelper: mHandler: 3
07-31 13:55:07.306  2677  3168 E NetworkScheduler.SR: Invalid parameter app
07-31 13:55:07.306  2677  3168 E NetworkScheduler.SR: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
07-31 13:55:07.321  3469  3469 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1221 android.content.ContextWrapper.startService:581 android.content.ContextWrapper.startService:581 com.android.keychain.KeyChainBroadcastReceiver.onReceive:12 android.app.ActivityThread.handleReceiver:2725 
07-31 13:55:07.356  1961  2254 I InputReader: Reconfiguring input devices.  changes=0x00000010
07-31 13:55:07.378  3306  6066 D Wear_Controller: Received broadcast action=android.intent.action.PACKAGE_REMOVED and uri=io.ionic.starter
07-31 13:55:07.414  2697  2697 D CarrierServiceBindHelper: Receive action: android.intent.action.PACKAGE_ADDED
07-31 13:55:07.414  2697  2697 D CarrierServiceBindHelper: mHandler: 3
07-31 13:55:07.419  3306  6062 D Wear_Controller: Received broadcast action=android.intent.action.PACKAGE_ADDED and uri=io.ionic.starter
07-31 13:55:07.474  1961  2254 I InputReader: Reconfiguring input devices.  changes=0x00000010
07-31 13:55:07.475  2697  2697 D CarrierServiceBindHelper: Receive action: android.intent.action.PACKAGE_REPLACED
07-31 13:55:07.475  2697  2697 D CarrierServiceBindHelper: mHandler: 3
07-31 13:55:07.475  2697  2697 D CarrierConfigLoader: mHandler: 9 phoneId: 0
07-31 13:55:07.476  2809  6069 I UpdateIcingCorporaServi: Updating corpora: APPS=io.ionic.starter, CONTACTS=MAYBE
07-31 13:55:07.477  6041  6041 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
07-31 13:55:07.478  6041  6041 D AndroidRuntime: CheckJNI is ON
07-31 13:55:07.491  6041  6041 D ICU     : No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
07-31 13:55:07.492  3306  6057 I FontsPackageChangeOp: Package io.ionic.starter has no metadata
07-31 13:55:07.513  6041  6041 E memtrack: Couldn't load memtrack module (No such file or directory)
07-31 13:55:07.513  6041  6041 E android.os.Debug: failed to load memtrack module: -2
07-31 13:55:07.518  6041  6041 I Radio-JNI: register_android_hardware_Radio DONE
07-31 13:55:07.527  6041  6041 D AndroidRuntime: Calling main entry com.android.commands.input.Input
07-31 13:55:07.527  6041  6041 I Input   : injectKeyEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_MENU, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=3105719, downTime=3105719, deviceId=-1, source=0x101 }
07-31 13:55:07.531  2677  3168 E NetworkScheduler.SR: Invalid parameter app
07-31 13:55:07.531  2677  3168 E NetworkScheduler.SR: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
07-31 13:55:07.532  6041  6041 I Input   : injectKeyEvent: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_MENU, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=3105719, downTime=3105719, deviceId=-1, source=0x101 }
07-31 13:55:07.533  6041  6041 D AndroidRuntime: Shutting down VM
07-31 13:55:07.540  1961  2407 I AccountManagerService: getTypesVisibleToCaller: isPermitted? true
07-31 13:55:08.047  3306  3848 W art     : Long monitor contention event with owner method=void suz.d(svc) from :com.google.android.gms:4 waiters=0 for 342ms
07-31 13:55:08.065  3306  5133 I Icing   : Usage reports 0 indexed 0 rejected 0 imm upload false
07-31 13:55:08.215  3306  5133 I Icing   : Usage reports 0 indexed 0 rejected 0 imm upload true
07-31 13:55:08.220  2809  6069 I UpdateIcingCorporaServi: UpdateCorporaTask done [took 744 ms] updated apps [took 744 ms] 
07-31 13:55:08.268  6080  6080 D AndroidRuntime: >>>>>> START com.android.internal.os.RuntimeInit uid 0 <<<<<<
07-31 13:55:08.271  6080  6080 D AndroidRuntime: CheckJNI is ON
07-31 13:55:08.281  3306  5133 I Icing   : Usage reports 0 indexed 0 rejected 0 imm upload false
07-31 13:55:08.285  3306  5133 I Icing   : Usage reports 0 indexed 0 rejected 0 imm upload false
07-31 13:55:08.288  3306  5133 I Icing   : Usage reports 0 indexed 0 rejected 0 imm upload false
07-31 13:55:08.293  6080  6080 D ICU     : No timezone override file found: /data/misc/zoneinfo/current/icu/icu_tzdata.dat
07-31 13:55:08.324  6080  6080 E memtrack: Couldn't load memtrack module (No such file or directory)
07-31 13:55:08.324  6080  6080 E android.os.Debug: failed to load memtrack module: -2
07-31 13:55:08.325  6080  6080 I Radio-JNI: register_android_hardware_Radio DONE
07-31 13:55:08.333  6080  6080 D AndroidRuntime: Calling main entry com.android.commands.am.Am
07-31 13:55:08.336  1961  2725 I ActivityManager: START u0 {act=android.intent.action.MAIN flg=0x10000000 cmp=io.ionic.starter/.MainActivity} from uid 0 on display 0
07-31 13:55:08.364  6090  6090 I art     : Not late-enabling -Xcheck:jni (already on)
07-31 13:55:08.367  1961  3766 I ActivityManager: Start proc 6090:io.ionic.starter/u0a53 for activity io.ionic.starter/.MainActivity
07-31 13:55:08.482  6090  6090 I CordovaLog: Changing log level to DEBUG(3)
07-31 13:55:08.482  6090  6090 I CordovaActivity: Apache Cordova native platform version 6.2.3 is starting
07-31 13:55:08.482  6090  6090 D CordovaActivity: CordovaActivity.onCreate()
07-31 13:55:08.484  6090  6090 I WebViewFactory: Loading com.android.webview version 44.0.2403.119 (code 246011910)
07-31 13:55:08.500  6090  6090 W System  : ClassLoader referenced unknown path: /system/app/webview/lib/x86
07-31 13:55:08.503  6090  6090 I LibraryLoader: Time to load native libraries: 0 ms (timestamps 6695-6695)
07-31 13:55:08.503  6090  6090 I LibraryLoader: Expected native library version number "",actual native library version number ""
07-31 13:55:08.535  2712  2901 E Surface : getSlotFromBufferLocked: unknown buffer: 0x9f5555e0
07-31 13:55:08.570  6090  6090 V WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper (main, tid 1) {3103e26}
07-31 13:55:08.571  6090  6090 I LibraryLoader: Expected native library version number "",actual native library version number ""
07-31 13:55:08.571  6090  6090 I chromium: [INFO:library_loader_hooks.cc(120)] Chromium logging enabled: level = 0, default verbosity = 0
07-31 13:55:08.573  6090  6090 I BrowserStartupController: Initializing chromium process, singleProcess=true
07-31 13:55:08.573  6090  6090 W art     : Attempt to remove non-JNI local reference, dumping thread
07-31 13:55:08.574  6090  6090 E SysUtils: ApplicationContext is null in ApplicationStatus
07-31 13:55:08.581  6090  6090 W chromium: [WARNING:resource_bundle.cc(285)] locale_file_path.empty()
07-31 13:55:08.583  6090  6090 E libEGL  : validate_display:255 error 3008 (EGL_BAD_DISPLAY)
07-31 13:55:08.583  6090  6090 E libEGL  : validate_display:255 error 3008 (EGL_BAD_DISPLAY)
07-31 13:55:08.569  6090  6090 W o.ionic.starter: type=1400 audit(0.0:48): avc: denied { search } for name="graphics" dev="tmpfs" ino=1274 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:graphics_device:s0 tclass=dir permissive=0
07-31 13:55:08.607  6090  6116 W AudioManagerAndroid: Requires BLUETOOTH permission
07-31 13:55:08.608  6090  6090 E DataReductionProxySettingListener: No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
07-31 13:55:08.617  6090  6090 W art     : Attempt to remove non-JNI local reference, dumping thread
07-31 13:55:08.619  6090  6090 W AwContents: onDetachedFromWindow called when already detached. Ignoring
07-31 13:55:08.631  6090  6090 D SystemWebViewEngine: CordovaWebView is running on device made by: unknown
07-31 13:55:08.638  6090  6090 W art     : Attempt to remove non-JNI local reference, dumping thread
07-31 13:55:08.638  6090  6090 W art     : Attempt to remove non-JNI local reference, dumping thread
07-31 13:55:08.638  6090  6090 D PluginManager: init()
07-31 13:55:08.643  1226  1285 E SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
07-31 13:55:08.643  6090  6123 D OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
07-31 13:55:08.647  6090  6090 D gralloc_ranchu: Emulator without host-side GPU emulation detected. Loading gralloc.default.so from /vendor/lib/hw/gralloc.default.so...
07-31 13:55:08.647  6090  6090 D gralloc_ranchu: gralloc.default.so not found in /vendor. Trying /system/lib/hw/gralloc.default.so...
07-31 13:55:08.710  6090  6090 D CordovaWebViewImpl: >>> loadUrl(file:///android_asset/www/index.html)
07-31 13:55:08.714  1225  1225 E SELinux : avc:  denied  { find } for service=batteryproperties scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:healthd_service:s0 tclass=service_manager
07-31 13:55:08.724  6090  6090 D CordovaActivity: Started the activity.
07-31 13:55:08.724  6090  6090 D CordovaActivity: Resumed the activity.
07-31 13:55:08.728  6090  6114 W chromium: [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup
07-31 13:55:08.764  6090  6123 I OpenGLRenderer: Initialized EGL, version 1.4
07-31 13:55:09.103  3306  3782 I Icing   : Indexing 01A01936D079744CE3B2C265076C88005C5472E3 from com.google.android.gms
07-31 13:55:09.127  1961  2796 I WindowManager: Switching to real app window: Window{483cb63 u0 io.ionic.starter/io.ionic.starter.MainActivity}
07-31 13:55:09.191  3306  3782 I Icing   : Indexing done 01A01936D079744CE3B2C265076C88005C5472E3
07-31 13:55:09.328  3306  3782 I Icing   : Indexing F301375E5CABF8A3BEBE3ECD1D9ECB5EAEE906C4 from com.google.android.googlequicksearchbox
07-31 13:55:09.346  3306  3782 I Icing   : Indexing 01A01936D079744CE3B2C265076C88005C5472E3 from com.google.android.gms
07-31 13:55:09.347  3306  3782 I Icing   : Indexing done 01A01936D079744CE3B2C265076C88005C5472E3
07-31 13:55:09.353  3306  3782 I Icing   : Indexing done F301375E5CABF8A3BEBE3ECD1D9ECB5EAEE906C4
07-31 13:55:09.597  1961  2010 I ActivityManager: Displayed io.ionic.starter/.MainActivity: +1s244ms
07-31 13:55:09.599  6080  6080 D AndroidRuntime: Shutting down VM
07-31 13:55:09.642  6090  6090 D CordovaWebViewImpl: onPageDidNavigate(file:///android_asset/www/index.html)
07-31 13:55:09.749  6090  6090 W BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 6090
07-31 13:55:10.020  6090  6090 D JsMessageQueue: Set native->JS mode to EvalBridgeMode
07-31 13:55:11.453  6090  6123 E Surface : getSlotFromBufferLocked: unknown buffer: 0x9eb7e200
07-31 13:55:11.490  1961  3689 W InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@9c242b7 attribute=null, token = android.os.BinderProxy@39cbf06
07-31 13:55:11.797  6090  6123 E Surface : getSlotFromBufferLocked: unknown buffer: 0x9b3fdd80
07-31 13:55:13.627  6090  6090 D SystemWebChromeClient: file:///android_asset/www/build/vendor.js: Line 3405 : Angular is running in the development mode. Call enableProdMode() to enable the production mode.
07-31 13:55:13.627  6090  6090 I chromium: [INFO:CONSOLE(3405)] "Angular is running in the development mode. Call enableProdMode() to enable the production mode.", source: file:///android_asset/www/build/vendor.js (3405)
07-31 13:55:13.635  6090  6090 D SystemWebChromeClient: file:///android_asset/www/build/vendor.js: Line 1443 : ERROR
07-31 13:55:13.635  6090  6090 I chromium: [INFO:CONSOLE(1443)] "ERROR", source: file:///android_asset/www/build/vendor.js (1443)
07-31 13:55:13.647  6090  6090 D SystemWebChromeClient: file:///android_asset/www/build/vendor.js: Line 112056 : Ionic Native: deviceready event fired after 1342 ms
07-31 13:55:13.647  6090  6090 I chromium: [INFO:CONSOLE(112056)] "Ionic Native: deviceready event fired after 1342 ms", source: file:///android_asset/www/build/vendor.js (112056)
07-31 13:55:13.650  6090  6134 I App     : WARNING: Back Button Default Behavior will be overridden.  The backbutton event will be fired!
07-31 13:55:13.681  6090  6090 D CordovaWebViewImpl: onPageFinished(file:///android_asset/www/index.html)

1 个答案:

答案 0 :(得分:0)

试试这个,希望它有效。

@Override
 public void onRequestPermissionsResult(int requestCode,
    String permissions[], int[] grantResults) {
switch (requestCode) {
    case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // permission was granted, yay! Do the
            // contacts-related task you need to do.

        } else {

            // permission denied, boo! Disable the
            // functionality that depends on this permission.
        }
        return;
    }

    // other 'case' lines to check for other
    // permissions this app might request
   }
 }

然后覆盖onRequestPermissionResult

{{1}}