直接共享目标未在分享选择器中显示

时间:2015-12-10 19:34:54

标签: java android

我正在寻找创建一个tasker插件,允许用户在android 6.0上自定义他们的直接共享目标。我已按照文档说明完成所有操作,但它们没有显示出来。非常感谢所有帮助。

这是manifest.xml:

<activity android:name=".receiver.ShareReceiver"
        android:label="Test"
        android:icon="@drawable/ic_action_labels">

        <intent-filter android:label="Test" android:icon="@drawable/ic_action_labels">
            <action android:name="android.intent.action.SEND"/>
            <data android:mimeType="text/plain"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>

        <meta-data
            android:name="android.service.chooser.chooser_target_service"
            android:value=".ui.DirectShareService" />

    </activity>

    <activity android:name=".ui.ActivityIconSelector"
        android:label="Icon Selector">

    </activity>

这是DirectShareService:

public class DirectShareService extends ChooserTargetService {

    public SharedPreferences directShare;
    public List<ChooserTarget> items;
    public int numberOfItems;
    public String title;
    public String iconText;

    @Override
    public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
        Intent intent = new Intent(this, MainActivity.class);
        return getItems(targetActivityName, intent);
    }

    public List<ChooserTarget> getItems(ComponentName targetActivityName, Intent intent) {
        directShare = getSharedPreferences("Direct Share", 0);
        numberOfItems = getRightAmount(directShare.getInt("Items", 0));
        items = new ArrayList<>();
        for (int i = 1; i <= numberOfItems; i++) {
            switch (i) {
                case 1:
                    title = directShare.getString("OneTitle", "Not Set");
                    iconText = directShare.getString("OneIcon", "Not Set");
                    items.add(getTarget(title, iconText, "", i, targetActivityName, intent));
                    break;
                case 2:
                    title = directShare.getString("TwoTitle", "Not Set");
                    iconText = directShare.getString("TwoIcon", "Not Set");
                    items.add(getTarget(title, iconText, "", i, targetActivityName, intent));
                    break;
                case 3:
                    title = directShare.getString("ThreeTitle", "Not Set");
                    iconText = directShare.getString("ThreeIcon", "Not Set");
                    items.add(getTarget(title, iconText, "", i, targetActivityName, intent));
                    break;
                case 4:
                    title = directShare.getString("FourTitle", "Not Set");
                    iconText = directShare.getString("FourIcon", "Not Set");
                    items.add(getTarget(title, iconText, "", i, targetActivityName, intent));
                    break;
            }
        }
        return items;
    }

public ChooserTarget getTarget(String title, String icon, String command, int num, ComponentName targetActivityName, Intent intent) {
        if (icon.equals("Not Set")) {
            return new ChooserTarget(title, Icon.createWithResource(this, R.drawable.ic_action_labels), num, targetActivityName, intent.getExtras());
        } else
            return new ChooserTarget(title, Icon.createWithContentUri(icon), num, targetActivityName, intent.getExtras());
    }

1 个答案:

答案 0 :(得分:0)

你应该用这个构造函数提醒:

public ChooserTarget(CharSequence title, Icon icon, float score,
        ComponentName componentName, @Nullable Bundle intentExtras);

-score:此目标的排名得分在0.0f和1.0f之间,包括

在构造函数中,将检查分数:

if (score > 1.f || score < 0.f) {
        throw new IllegalArgumentException("Score " + score + " out of range; "
                + "must be between 0.0f and 1.0f");
    }

所以请不要填写“我&#39;代码中的值!