我想調用位於類的片段中的方法。現在我收到錯誤:非靜態方法checkWriteStoragePermission()不能從靜態內容中引用。我真的沒有想法。我現在用google搜索了大約2天,沒有任何結果。非靜態方法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();
}
}
我怎麼能輕易解決這個問題?因爲我無法將其轉換爲靜態方法。
親切的問候,
您寫這行「)RecordingMode.checkWriteStoragePermission(;」是RecordingMode類名或對象名稱? – Sakalya
RecordingMode.class是我的Fragment,而MyFiebaseMessagingService.class是我的外部類。 –