2017-10-07 10 views
0

ImageView가있는 조각이 있습니다. 사용자가이 이미지를 클릭하면 현지화에 대한 권한을 요청하고 싶지만 "requestPermission()"이 실행 되더라도 요청 대화 상자가 표시되지 않습니다.Fragment not request 대화 상자의 requestPermission

내 조각 onCreateView 방법

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 

    View center = inflater.inflate(R.layout.board, container, false); 
    position = (ImageView) center.findViewById(R.id.position); 

    position.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 

       if (ContextCompat.checkSelfPermission(getActivity(), 
         Manifest.permission.ACCESS_FINE_LOCATION) 
         != PackageManager.PERMISSION_GRANTED) { 

        if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), 
          Manifest.permission.ACCESS_FINE_LOCATION)) { 

         Toast.makeText(getContext(), 
           "I need the permission pls", 
           Toast.LENGTH_LONG).show(); 
        } 

        requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION,}, LOCALIZATION_PERMISSION); 

       } 
      } 
     } 
    }); 
    return center; 
} 

참고 : shouldShowRequestPermissionRationale 사실이 결코 없다. 디버거로 확인합니다.

는 또한 매니페스트에

<?xml version="1.0" encoding="utf-8"?> 

    <manifest 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     package="it.peoople"> 

    <uses-permissions android:name="android.permissions.INTERNET" /> 
    <uses-permissions android:name="android.permissions.READ_EXTERNAL_STORAGE"/> 
    <uses-permissions android:name="android.permissions.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permissions android:name="android.permission.ACCESS_FINE_LOCATION"/> 
    <uses-permissions android:name="android.permission.ACCESS_COARSE_LOCATION"/> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:roundIcon="@mipmap/ic_launcher" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name="it.peoople.main.MainActivity" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" 
      android:windowSoftInputMode="stateHidden|adjustPan" > 

      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <activity android:name="it.peoople.floating.Messaging" 
      android:screenOrientation="portrait"> 
     </activity> 

     <activity android:name="it.peoople.floating.Registration" 
      android:screenOrientation="portrait"> 
     </activity> 
    </application> 

</manifest> 

참고 권한 관리 : 사용 권한 대화 상자가 나타 결코 그래서 "다시 표시하지 않음"확인하지 않습니다.

요청 권한이 자동으로 거부 실행하고 안드로이드

10-09 18:22:50.019 2223-2359/it.peoople D/AppTracker: App Event: stop 
10-09 18:22:50.020 2223-2254/it.peoople V/FA: Recording user engagement, ms: 5411 
10-09 18:22:50.020 2223-2254/it.peoople V/FA: Using measurement service 
10-09 18:22:50.020 2223-2254/it.peoople V/FA: Connecting to remote service 
10-09 18:22:50.025 2223-2254/it.peoople V/FA: Activity paused, time: 57774748 
10-09 18:22:50.030 2223-2254/it.peoople D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=5411, firebase_screen_class(_sc)=Registration, firebase_screen_id(_si)=-1569558894460098554}] 
10-09 18:22:50.043 2223-2254/it.peoople V/FA: Using measurement service 
10-09 18:22:50.043 2223-2254/it.peoople V/FA: Connection attempt already in progress 
10-09 18:22:50.050 2223-2254/it.peoople D/FA: Connected to remote service 
10-09 18:22:50.050 2223-2254/it.peoople V/FA: Processing queued up service tasks: 2 
10-09 18:22:50.082 2223-2254/it.peoople V/FA: Activity resumed, time: 57774811 
10-09 18:22:50.082 2223-2518/it.peoople D/AppTracker: App Event: start 

제발 도와주세요이 줄을 인쇄 로그 캣 때마다.

정말로 감사합니다.

+0

대상 SDK 버전은 무엇입니까? – nomag

+0

대상 SDK 25, minSDK 21 –

+0

및 테스트 장치의 빌드 버전? 그게 나를 위해 잘 작동 – nomag

답변

0

나는 이것을 액티비티로 옮기고 프래그먼트에서 그것과 상호 작용하는 새로운 리스너를 구현해야한다고 생각한다.

당신의 문제는 당신이 토스트를 실행하는 것이 아니라 당신이 빌드하는 것입니다. 그러나 그것에 nevet call .show()를 호출하십시오.

 AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setMessage(R.string.permission_prompt_location); 
     builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int which) { 
       ActivityCompat.requestPermissions(
         SwipeActivity.this, 
         new String[]{Manifest.permission.ACCESS_FINE_LOCATION, 
           Manifest.permission.ACCESS_COARSE_LOCATION}, 
         REQUEST_LOCATION); 
      } 
     }); 
     builder.create().show(); 
+0

토스트에 대해 .show를 잊어 버렸지 만 shouldShowRequestPermissionRationale가 디버거와 절대로 맞지 않는지 확인합니다. –

+0

이 장치는 실제 장치입니까, 아니면 에뮬레이션 된 장치입니까? –

+0

은 실제 기기입니다 –