File indexing completed on 2024-12-22 04:41:41
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Albert Vaca Cintora <albertvaka@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 package org.kde.kdeconnect.Plugins.SharePlugin; 0008 0009 import android.app.Activity; 0010 import android.content.ClipData; 0011 import android.content.Intent; 0012 import android.net.Uri; 0013 import android.os.Bundle; 0014 import android.util.Log; 0015 import android.widget.Toast; 0016 0017 import androidx.appcompat.app.AppCompatActivity; 0018 0019 import org.kde.kdeconnect.KdeConnect; 0020 import org.kde.kdeconnect_tp.R; 0021 0022 import java.util.ArrayList; 0023 0024 0025 public class SendFileActivity extends AppCompatActivity { 0026 0027 private String mDeviceId; 0028 0029 @Override 0030 protected void onCreate(Bundle savedInstanceState) { 0031 super.onCreate(savedInstanceState); 0032 0033 mDeviceId = getIntent().getStringExtra("deviceId"); 0034 0035 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 0036 intent.setType("*/*"); 0037 intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); 0038 intent.addCategory(Intent.CATEGORY_OPENABLE); 0039 try { 0040 startActivityForResult( 0041 Intent.createChooser(intent, getString(R.string.send_files)), Activity.RESULT_FIRST_USER); 0042 } catch (android.content.ActivityNotFoundException ex) { 0043 Toast.makeText(this, R.string.no_file_browser, Toast.LENGTH_SHORT).show(); 0044 finish(); 0045 } 0046 } 0047 0048 @Override 0049 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 0050 switch (requestCode) { 0051 case Activity.RESULT_FIRST_USER: 0052 if (resultCode == RESULT_OK) { 0053 0054 final ArrayList<Uri> uris = new ArrayList<>(); 0055 0056 Uri uri = data.getData(); 0057 if (uri != null) { 0058 uris.add(uri); 0059 } 0060 0061 ClipData clipdata = data.getClipData(); 0062 if (clipdata != null) { 0063 for (int i = 0; i < clipdata.getItemCount(); i++) { 0064 uris.add(clipdata.getItemAt(i).getUri()); 0065 } 0066 } 0067 0068 if (uris.isEmpty()) { 0069 Log.w("SendFileActivity", "No files to send?"); 0070 } else { 0071 SharePlugin plugin = KdeConnect.getInstance().getDevicePlugin(mDeviceId, SharePlugin.class); 0072 if (plugin == null) { 0073 finish(); 0074 return; 0075 } 0076 plugin.sendUriList(uris); 0077 } 0078 } 0079 finish(); 0080 break; 0081 default: 0082 super.onActivityResult(requestCode, resultCode, data); 0083 } 0084 } 0085 0086 }