mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-20 21:18:07 +00:00
Force file scanning
This commit is contained in:
parent
ad30045834
commit
f7f6789816
5 changed files with 84 additions and 1 deletions
|
|
@ -113,6 +113,7 @@ import org.linphone.receivers.HookReceiver;
|
|||
import org.linphone.receivers.KeepAliveReceiver;
|
||||
import org.linphone.receivers.NetworkManager;
|
||||
import org.linphone.receivers.OutgoingCallReceiver;
|
||||
import org.linphone.ui.LinphoneMediaScanner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
|
@ -183,6 +184,7 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
private Address mCurrentChatRoomAddress;
|
||||
|
||||
public String wizardLoginViewDomain = null;
|
||||
private LinphoneMediaScanner mMediaScanner;
|
||||
|
||||
protected LinphoneManager(final Context c) {
|
||||
mUnreadChatsPerRoom = new HashMap();
|
||||
|
|
@ -207,6 +209,8 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
mSensorManager = (SensorManager) c.getSystemService(Context.SENSOR_SERVICE);
|
||||
mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
|
||||
mR = c.getResources();
|
||||
|
||||
mMediaScanner = new LinphoneMediaScanner(c);
|
||||
}
|
||||
|
||||
private static final int LINPHONE_VOLUME_STREAM = STREAM_VOICE_CALL;
|
||||
|
|
@ -991,11 +995,16 @@ public class LinphoneManager implements CoreListener, SensorEventListener, Accou
|
|||
public static synchronized void destroy() {
|
||||
if (instance == null) return;
|
||||
instance.changeStatusToOffline();
|
||||
instance.mMediaScanner.destroy();
|
||||
sExited = true;
|
||||
instance.destroyCore();
|
||||
instance = null;
|
||||
}
|
||||
|
||||
public LinphoneMediaScanner getMediaScanner() {
|
||||
return mMediaScanner;
|
||||
}
|
||||
|
||||
private String getString(int key) {
|
||||
return mR.getString(key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ import org.linphone.core.AccountCreator;
|
|||
import org.linphone.core.Address;
|
||||
import org.linphone.core.Call;
|
||||
import org.linphone.core.Call.State;
|
||||
import org.linphone.core.ChatMessage;
|
||||
import org.linphone.core.ChatRoom;
|
||||
import org.linphone.core.ChatRoomSecurityLevel;
|
||||
import org.linphone.core.Content;
|
||||
|
|
@ -71,6 +72,7 @@ import org.linphone.core.RegistrationState;
|
|||
import org.linphone.core.ZrtpPeerStatus;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.mediastream.video.capture.hwconf.Hacks;
|
||||
import org.linphone.ui.LinphoneMediaScanner;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
|
|
@ -735,6 +737,7 @@ public final class LinphoneUtils {
|
|||
public static Uri createCvsFromString(String vcardString){
|
||||
String contactName = getContactNameFromVcard(vcardString);
|
||||
File vcfFile = new File(Environment.getExternalStorageDirectory(), contactName+".cvs");
|
||||
LinphoneManager.getInstance().getMediaScanner().scanFile(vcfFile);
|
||||
try {
|
||||
FileWriter fw = new FileWriter(vcfFile);
|
||||
fw.write(vcardString);
|
||||
|
|
@ -852,5 +855,17 @@ public final class LinphoneUtils {
|
|||
public static ZrtpPeerStatus getZrtpStatus(Core lc, String uri) {
|
||||
return (uri != null) ? lc.getZrtpStatus(uri) : ZrtpPeerStatus.Unknown;
|
||||
}
|
||||
|
||||
public static void scanFile(ChatMessage message) {
|
||||
String appData = message.getAppdata();
|
||||
if (appData == null) {
|
||||
for (Content c : message.getContents()) {
|
||||
if (c.isFile()) {
|
||||
appData = c.getFilePath();
|
||||
}
|
||||
}
|
||||
}
|
||||
LinphoneManager.getInstance().getMediaScanner().scanFile(new File(appData));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ public class ChatEventsAdapter extends ListSelectionAdapter {
|
|||
message.setListener(mListener);
|
||||
message.setFileTransferFilepath(file.getPath());
|
||||
message.downloadFile();
|
||||
|
||||
LinphoneManager.getInstance().getMediaScanner().scanFile(file);
|
||||
} else {
|
||||
Log.w("WRITE_EXTERNAL_STORAGE permission not granted, won't be able to store the downloaded file");
|
||||
LinphoneActivity.instance().checkAndRequestExternalStoragePermission();
|
||||
|
|
@ -570,6 +570,7 @@ public class ChatEventsAdapter extends ListSelectionAdapter {
|
|||
Content fileContent = message.getFileTransferInformation();
|
||||
String appData = fileContent.getFilePath();
|
||||
if (fileContent != null && fileContent.isFile() && appData != null) {
|
||||
LinphoneUtils.scanFile(message);
|
||||
holder.fileName.setText(fileContent.getName());
|
||||
if (LinphoneUtils.isExtensionImage(appData)) {
|
||||
holder.messageImage.setVisibility(View.VISIBLE);
|
||||
|
|
|
|||
|
|
@ -672,6 +672,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
|||
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.app_name));
|
||||
file.mkdirs();
|
||||
file = new File(Environment.getExternalStorageDirectory() + "/" + getString(R.string.app_name), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())+".jpeg"));
|
||||
LinphoneManager.getInstance().getMediaScanner().scanFile(file);
|
||||
mImageToUploadUri = Uri.fromFile(file);
|
||||
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageToUploadUri);
|
||||
cameraIntents.add(captureIntent);
|
||||
|
|
|
|||
57
src/android/org/linphone/ui/LinphoneMediaScanner.java
Normal file
57
src/android/org/linphone/ui/LinphoneMediaScanner.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package org.linphone.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.net.Uri;
|
||||
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class LinphoneMediaScanner implements MediaScannerConnection.MediaScannerConnectionClient {
|
||||
private MediaScannerConnection mMediaConnection;
|
||||
private boolean mIsConnected;
|
||||
private File mFileWaitingForScan;
|
||||
|
||||
public LinphoneMediaScanner(Context context) {
|
||||
mIsConnected = false;
|
||||
mMediaConnection = new MediaScannerConnection(context, this);
|
||||
mMediaConnection.connect();
|
||||
mFileWaitingForScan = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaScannerConnected() {
|
||||
mIsConnected = true;
|
||||
Log.i("[MediaScanner] Connected");
|
||||
if (mFileWaitingForScan != null) {
|
||||
scanFile(mFileWaitingForScan);
|
||||
mFileWaitingForScan = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void scanFile(File file) {
|
||||
scanFile(file, null);
|
||||
}
|
||||
|
||||
public void scanFile(File file, String mime) {
|
||||
if (!mIsConnected) {
|
||||
Log.w("[MediaScanner] Not connected yet...");
|
||||
mFileWaitingForScan = file;
|
||||
return;
|
||||
}
|
||||
Log.i("[MediaScanner] Scanning file " + file.getAbsolutePath() + " with MIME " + mime);
|
||||
mMediaConnection.scanFile(file.getAbsolutePath(), mime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanCompleted(String path, Uri uri) {
|
||||
Log.i("[MediaScanner] Scan completed : " + path + " => " + uri);
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
Log.i("[MediaScanner] Disconnecting");
|
||||
mMediaConnection.disconnect();
|
||||
mIsConnected = false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue