클래스의 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();
}
}
이 어떻게 쉽게이 문제를 해결할 수 있습니까? 나는 이것을 정적 방법으로 변환 할 수 없기 때문에.
종류와 관련,
당신이 줄을 작성했습니다 : 같은 방법을 편집하십시오.? – Sakalya
RecordingMode.class가 내 Fragment이고 MyFiebaseMessagingService.class가 내 외부 클래스입니다. –