File indexing completed on 2024-12-22 04:41:41
0001 /* 0002 * SPDX-FileCopyrightText: 2017 Nicolas Fella <nicolas.fella@gmx.de> 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.content.ComponentName; 0010 import android.content.IntentFilter; 0011 import android.graphics.drawable.Icon; 0012 import android.os.Bundle; 0013 import android.service.chooser.ChooserTarget; 0014 import android.service.chooser.ChooserTargetService; 0015 import android.util.Log; 0016 0017 import org.kde.kdeconnect.Device; 0018 import org.kde.kdeconnect.KdeConnect; 0019 import org.kde.kdeconnect_tp.R; 0020 0021 import java.util.ArrayList; 0022 import java.util.List; 0023 0024 public class ShareChooserTargetService extends ChooserTargetService { 0025 @Override 0026 public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) { 0027 Log.d("DirectShare", "invoked"); 0028 final List<ChooserTarget> targets = new ArrayList<>(); 0029 for (Device d : KdeConnect.getInstance().getDevices().values()) { 0030 if (d.isReachable() && d.isPaired()) { 0031 Log.d("DirectShare", d.getName()); 0032 final String targetName = d.getName(); 0033 final Icon targetIcon = Icon.createWithResource(this, R.drawable.icon); 0034 final float targetRanking = 1; 0035 final ComponentName targetComponentName = new ComponentName(getPackageName(), 0036 ShareActivity.class.getCanonicalName()); 0037 final Bundle targetExtras = new Bundle(); 0038 targetExtras.putString("deviceId", d.getDeviceId()); 0039 targets.add(new ChooserTarget( 0040 targetName, targetIcon, targetRanking, targetComponentName, targetExtras 0041 )); 0042 } 0043 } 0044 0045 return targets; 0046 } 0047 }