2016-09-28 2 views
0

클래스의 Fragment에있는 메서드를 호출하려고합니다. 이제 오류가 나타납니다 : 비 정적 메서드 checkWriteStoragePermission() 정적 콘텐츠에서 참조 할 수 없습니다. 나는 아이디어가 정말 없어. 나는 아무 결과없이 대략 2 일 동안 지금 googling이다.정적 콘텐츠에서 정적이 아닌 메서드 checkWriteStoragePermission()을 참조 할 수 없습니다.

나는 메서드를 호출하려고 클래스 다음 조각 클래스의

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

public static String sRecordDate; 

public void onMessageReceived(RemoteMessage remoteMessage) { 

    Intent intent = new Intent(this,MainActivity.class); 
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT); 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); 
    notificationBuilder.setContentTitle("FCM NOTIFICATION"); 
    notificationBuilder.setContentText(remoteMessage.getNotification().getBody()); 
    notificationBuilder.setAutoCancel(true); 
    notificationBuilder.setSmallIcon(R.mipmap.ic_launcher); 
    notificationBuilder.setContentIntent(pendingIntent); 
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(0,notificationBuilder.build()); 

    for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) { 
     String key = entry.getKey(); 
     String value = entry.getValue(); 

     Log.d(":", "key, " + key + " value " + value); 

     sRecordDate = value; 

     RecordingMode.checkWriteStoragePermission(); //HERE I AM GETIING THE ERROR 
    } 
} 

방법 :

public void checkWriteStoragePermission() { 
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 
     if(ContextCompat.checkSelfPermission(getActivity(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE) 
       == PackageManager.PERMISSION_GRANTED) { 
      mIsRecording = true; 
      try { 
       createVideoFileName(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      startRecord(); 
      mMediaRecorder.start(); 
      mChronometer.setBase(SystemClock.elapsedRealtime()); 
      mChronometer.setVisibility(View.VISIBLE); 
      mChronometer.start(); 
     } else { 
      if(shouldShowRequestPermissionRationale(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) { 
       Toast.makeText(getActivity(), "app needs to be able to save videos", Toast.LENGTH_SHORT).show(); 
      } 
      requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION_RESULT); 
     } 
    } else { 
     mIsRecording = true; 
     try { 
      createVideoFileName(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
     startRecord(); 
     mMediaRecorder.start(); 
     mChronometer.setBase(SystemClock.elapsedRealtime()); 
     mChronometer.setVisibility(View.VISIBLE); 
     mChronometer.start(); 
    } 
} 

이 어떻게 쉽게이 문제를 해결할 수 있습니까? 나는 이것을 정적 방법으로 변환 할 수 없기 때문에.

종류와 관련,

+0

당신이 줄을 작성했습니다 : 같은 방법을 편집하십시오.? – Sakalya

+0

RecordingMode.class가 내 Fragment이고 MyFiebaseMessagingService.class가 내 외부 클래스입니다. –

답변

3

하지만 (클래스의 이름을 호출) 정적 메서드 인 것처럼 당신이이 방법을 가지고 해당 인스턴스에 호출 클래스의 인스턴스를 생성이 방법을 사용하고 있습니다.

Fragment fragment = new Fragment(); 
fragment.checkWriteStoragePermission(); 
+0

고마워요! 그건 내가 생각했던 것보다 쉬웠다. –

0

귀하의 방법 checkWriteStoragePermissionstatic 아니라 당신이 당신의 서비스에서 직접 호출하려고 : 당신은 다음 조각 '클래스는,`말했습니다. RecordingMode 클래스 이름 또는 개체 이름인가; "RecordingMode.checkWriteStoragePermission()"

public static void checkWriteStoragePermission() { 
.... 
} 
+0

나는 이것을 할 수 없다. 메서드는 정적이 아니어야합니다. –

+0

해결 방법보다 @Whatzs 게시 방법입니다. – Lennart

관련 문제