2017-08-08 14 views
1

cn1にネイティブアンドロイドコードを書き込む際に許可が必要です。しかし、次のコードは許可を求めるのではなく、空白の画面を表示します。デバッグ中、以下に述べるデバッグの第2部分は無限に繰り返されます。ネイティブインタフェース(アンドロイド)でのアクセス許可

import android.Manifest; 
import android.support.v4.app.ActivityCompat; 
import android.util.Log; 
import com.codename1.impl.android.AndroidNativeUtil; 

public class FusedLocationImpl implements ConnectionCallbacks, 
     OnConnectionFailedListener{ 

    public boolean isSupported() { 
     return true; 
    } 

    public void getFusedLocationPermission() { 
     if (!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.CAMERA, "Please allow camera permission")) { 
      ActivityCompat.requestPermissions((android.app.Activity) MyApplication.getContext(), new String[]{Manifest.permission.CAMERA}, 0); 
      //commenting this line does nothing 
     } 
    } 
} 

FusedLocation.java

public interface FusedLocation extends NativeInterface{ 
    public void getFusedLocationPermission(); 
} 

MyApplication.java

public void start() { 
    if (current != null) { 
     current.show(); 
     return; 
    } 
    FusedLocation my = (FusedLocation) NativeLookup.create(FusedLocation.class); 
    if(my != null && my.isSupported()){ 
     my.getFusedLocationPermission(); 
     System.out.println("bbeck"); 
    } 
    Form hi = new Form("Hi World", BoxLayout.y()); 
    hi.add(new Label("Hi World")); 
    hi.show(); 
} 

public static Object getContext() { 
    return context; 
} 

デバッグ中

08-08 14:56:49.161: W/ResourcesManager(4437): Resource getTopLevelResources for package com.fusedLocation.myappoverlayDirs =Null 
08-08 14:56:49.171: W/System(4437): ClassLoader referenced unknown path: /data/app/com.fusedLocation.myapp-1/lib/arm 
08-08 14:56:49.181: D/ContextRelationManager(4437): ContextRelationManager() : FEATURE_ENABLED=true 
08-08 14:56:49.231: I/GMPM(4437): App measurement is starting up 
08-08 14:56:49.241: E/GMPM(4437): getGoogleAppId failed with status: 10 
08-08 14:56:49.241: E/GMPM(4437): Uploading is not possible. App measurement disabled 
08-08 14:56:49.261: E/Qmage(4437): isQIO : stream is not a QIO file 
08-08 14:56:49.261: E/Qmage(4437): isQIO : stream is not a QIO file 
08-08 14:56:49.261: E/Qmage(4437): isQIO : stream is not a QIO file 
08-08 14:56:49.311: D/SecWifiDisplayUtil(4437): Metadata value : SecSettings2 
08-08 14:56:49.311: D/ViewRootImpl(4437): #1 mView = com.android.internal.policy.PhoneWindow$DecorView{a207dc I.ED..... R.....ID 0,0-0,0} 
08-08 14:56:49.311: D/OpenGLRenderer(4437): Use EGL_SWAP_BEHAVIOR_PRESERVED: true 
08-08 14:56:49.331: W/ActivityThread(4437): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:56:49.361: I/Codename One(4437): Resource not found: theme_phone.ovr 
08-08 14:56:49.361: I/Codename One(4437): Resource not found: theme_android.ovr 
08-08 14:56:49.361: I/Codename One(4437): Resource not found: theme_android-phone.ovr 
08-08 14:56:49.361: D/libEGL(4437): eglInitialize EGLDisplay = 0xddf077c4 

デバッグ、次の行が

01無限に繰り返します
08-08 14:17:26.871: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:26.871: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41788755 
08-08 14:17:26.991: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:26.991: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41788872 
08-08 14:17:27.071: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:27.071: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41788957 
08-08 14:17:27.171: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41789058 
08-08 14:17:27.171: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:27.371: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:27.371: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41789256 
08-08 14:17:27.491: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:27.491: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41789373 
08-08 14:17:27.591: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:27.591: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41789475 
08-08 14:17:27.761: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:27.761: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41789640 
08-08 14:17:27.871: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:27.871: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41789757 
08-08 14:17:27.971: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:27.971: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41789857 
08-08 14:17:28.071: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:28.071: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41789958 
08-08 14:17:28.141: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:28.141: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41790025 
08-08 14:17:28.241: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:28.241: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41790125 
08-08 14:17:28.341: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:28.341: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41790227 
08-08 14:17:28.441: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:28.441: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41790325 
08-08 14:17:28.541: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:28.541: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41790426 
08-08 14:17:28.641: W/ActivityThread(29413): AppLock checkAppLockState isAppLocked = false pkgName = com.fusedLocation.myapp showWhenLocked = false 
08-08 14:17:28.641: I/Timeline(29413): Timeline: Activity_idle id: [email protected] time:41790526 

Updated1

FusedLocationImplはConnectionCallbacks、 OnConnectionFailedListener {

public boolean isSupported() { 
    return true; 
} 

public void getFusedLocationPermission() { 
    if (!com.codename1.impl.android.AndroidNativeUtil.checkForPermission(Manifest.permission.ACCESS_FINE_LOCATION, "Please allow location permission")) { 
     // you didn't get the permission, you might want to return here 
     ActivityCompat.requestPermissions((android.app.Activity) MyApplication.getContext(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0); 
    } 
} 

}

FusedLocation.java

public interface FusedLocation extends NativeInterface{ 
     public void getFusedLocationPermission(); 
     public void fusedLocation(); 
} 
を実装するパブリッククラス

MyApplication.java

public void start() { 
    if (current != null) { 
     current.show(); 
     return; 
    } 
    Form hi = new Form("Hi World", BoxLayout.y()); 
    hi.show(); 

    Button btn = new Button("ask for permission"); 
    btn.addActionListener(e -> { 
     FusedLocation my = (FusedLocation) NativeLookup.create(FusedLocation.class); 
     if (my != null && my.isSupported()) { 
      my.getFusedLocationPermission(); 
      my.fusedLocation(); 
     } 
    }); 
    hi.add(btn); 
} 

public static Object getContext() { 
    return context; 
} 

答えて

0

スタートは、アプリが起動されるたびに発生します。許可を求めるネイティブダイアログを開く許可を求めています。アプリが停止されます。アプリケーションが復元され、再度許可を求める...

通常、サスペンド時に現在のフォームを使用していても、このようなコードは発生しないため、このコードには到達できません。

この段階で権限を要求するのは、ネイティブのCodename OneアプリではBADです。

UIが表示されておらず、ユーザーがあなたが居なくなったと表示されていない場合。あなたは、表示するためのコンテキストが必要です。そして、ユーザに許可を求める。

+0

実際には、権限はbtnアクションリスナー内にあります。私はACCESS_FINE_LOCATIONに融合した場所を使用するよう求めています。上記は単なる例でした。上記のupdate1をご覧ください。ありがとう – beck

+1

android.xpermissionsビルドヒントにも権限を追加しましたか?ユーザーが拒否した場合、再び許可を求めるプロンプトはなぜ表示されますか?私たちはすでにそれをしていますし、あなたがそれをしてもそれは良く見えません。 –

+0

ohhh thankyou ... android.xpermissionsヒントを追加するのを忘れてしまった。許可がユーザーによって拒否された場合、返される内容はわからないので、再度尋ねられます。 – beck

関連する問題