当前位置: 首页>>代码示例>>Java>>正文


Java LabeledIntent类代码示例

本文整理汇总了Java中android.content.pm.LabeledIntent的典型用法代码示例。如果您正苦于以下问题:Java LabeledIntent类的具体用法?Java LabeledIntent怎么用?Java LabeledIntent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LabeledIntent类属于android.content.pm包,在下文中一共展示了LabeledIntent类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shareWithTranslate

import android.content.pm.LabeledIntent; //导入依赖的package包/类
/**
 * Share with other applications (but tries to put applications with "Translate" in the package
 * name in the first place(s).
 */
public static void shareWithTranslate(Activity activity, String text) {
    Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
    sendIntent.setType("text/plain");
    sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);

    PackageManager pm = activity.getPackageManager();
    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<>();
    for (ResolveInfo ri : resInfo) {
        if(ri.activityInfo.packageName.contains("translate")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(ri.activityInfo.packageName, ri.activityInfo.name));
            intent.putExtra(android.content.Intent.EXTRA_TEXT, text);
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intentList.add(new LabeledIntent(intent, ri.activityInfo.packageName, ri.loadLabel(pm), ri.icon));
        }
    }
    LabeledIntent[] extraIntents = intentList.toArray( new LabeledIntent[ intentList.size() ]);

    Intent openInChooser = Intent.createChooser(sendIntent, "Translate");

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    activity.startActivity(openInChooser);
}
 
开发者ID:tkrajina,项目名称:10000sentences,代码行数:30,代码来源:ShareUtils.java

示例2: getLabeledIntents

import android.content.pm.LabeledIntent; //导入依赖的package包/类
private static LabeledIntent[] getLabeledIntents(Context context) {
    Intent sendIntent = getShareIntent(context);
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intents = new ArrayList<>();
    for (ResolveInfo ri : resInfo) {
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains("twitter")
                || packageName.contains("facebook")
                || packageName.contains("whatsapp")
                || packageName.contains("plus")
                || packageName.contains("talk")
                || packageName.contains("viber")) {
            Intent intent = getShareIntent(context);
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intents.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }
    return intents.toArray(new LabeledIntent[intents.size()]);
}
 
开发者ID:rubenlop88,项目名称:autotracks-android,代码行数:21,代码来源:ShareIntentBuilder.java

示例3: buildLabeledIntent

import android.content.pm.LabeledIntent; //导入依赖的package包/类
private static LabeledIntent buildLabeledIntent(Intent intent, ResolveInfo intentActivity) {

        LabeledIntent labeledIntent = new LabeledIntent(intent, intentActivity.resolvePackageName,
                intentActivity.labelRes, intentActivity.getIconResource());
        labeledIntent.setPackage(getPackageName(intentActivity));
        labeledIntent.setClassName(getPackageName(intentActivity), intentActivity.activityInfo.name);
        return labeledIntent;
    }
 
开发者ID:gnosygnu,项目名称:xowa_android,代码行数:9,代码来源:ShareUtil.java

示例4: showFileAttach

import android.content.pm.LabeledIntent; //导入依赖的package包/类
private void showFileAttach() {
    final List<Intent> allIntents = new ArrayList<Intent>();

    // all openable...
    Intent contentIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentIntent.setType(SafeSlingerConfig.MIMETYPE_ADD_ATTACH);
    contentIntent.addCategory(Intent.CATEGORY_OPENABLE);

    // camera
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    SafeSlinger.setTempCameraFileUri(SSUtil.makeCameraOutputUri());
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, SafeSlinger.getTempCameraFileUri());
    allIntents.add(cameraIntent);

    // audio recorder
    Intent recorderIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
    recorderIntent.putExtra(MediaStore.EXTRA_OUTPUT, SSUtil.makeRecorderOutputUri());
    allIntents.add(recorderIntent);

    // our custom browser
    if (SSUtil.isExternalStorageReadable()) {
        Intent filePickIntent = new Intent(HomeActivity.this, FilePickerActivity.class);
        LabeledIntent fileIntent = new LabeledIntent(filePickIntent,
                filePickIntent.getPackage(), R.string.menu_FileManager,
                R.drawable.ic_menu_directory);
        allIntents.add(fileIntent);
    }

    // Chooser of file system options.
    Intent chooserIntent = Intent.createChooser(contentIntent,
            getString(R.string.title_ChooseFileLoad));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            allIntents.toArray(new Parcelable[] {}));
    startActivityForResult(chooserIntent, VIEW_FILEATTACH_ID);
}
 
开发者ID:SafeSlingerProject,项目名称:SafeSlinger-Android,代码行数:36,代码来源:HomeActivity.java

示例5: openMailChooser

import android.content.pm.LabeledIntent; //导入依赖的package包/类
public void openMailChooser() {
    String[] mails = new String[]{"[email protected]"};
    String PACKAGE_GMAIL = "android.gm";
    String PACKAGE_EMAIL = "android.email";
    String INTENT_TYPE_MSG = "message/rfc822";
    String INTENT_TYPE_TEXT = "text/plain";

    Intent mailIntent = new Intent();
    mailIntent.setAction(Intent.ACTION_SEND);
    mailIntent.putExtra(Intent.EXTRA_EMAIL, mails);
    mailIntent.setType(INTENT_TYPE_MSG);

    PackageManager pm = mContext.getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType(INTENT_TYPE_TEXT);

    Intent openInChooser = Intent.createChooser(mailIntent, mContext.getString(R.string.email_chooser));

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<>();
    for (ResolveInfo ri : resInfo) {
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains(PACKAGE_EMAIL)) {
            mailIntent.setPackage(packageName);
        } else if (packageName.contains(PACKAGE_GMAIL)) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType(INTENT_TYPE_TEXT);

            intent.putExtra(Intent.EXTRA_EMAIL, mails);
            intent.setType(INTENT_TYPE_MSG);

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    mContext.startActivity(openInChooser);
}
 
开发者ID:jinxul,项目名称:Baboon,代码行数:43,代码来源:Utils.java

示例6: getShareIntent

import android.content.pm.LabeledIntent; //导入依赖的package包/类
@Override
public Intent getShareIntent(Context context) {
    StorageManager storage = StorageManager.getInstance(context);

    File pdfFile = new File(storage.getPaperDirectory(getPaper()), getKey());
    File papersDir = storage.get(StorageManager.PAPER);

    try {
        String pagePath = pdfFile.getCanonicalPath()
                                 .replace(papersDir.getCanonicalPath(), "papers");

        Uri contentUri = Uri.parse("content://" + BuildConfig.APPLICATION_ID + ".streamprovider")
                            .buildUpon()
                            .appendEncodedPath(pagePath)
                            .build();

        //share Intent
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("application/pdf");
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra(Intent.EXTRA_STREAM, contentUri);
        intent.putExtra(Intent.EXTRA_SUBJECT, getPaper().getTitelWithDate(context) + ": " + getTitle());
        intent.putExtra(Intent.EXTRA_TEXT, getPaper().getTitelWithDate(context) + "\n" + getTitle());

        //get extra intents to view pdf
        Intent viewIntent = new Intent(Intent.ACTION_VIEW);
        viewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        viewIntent.setData(contentUri);
        PackageManager packageManager = context.getPackageManager();
        List<ResolveInfo> resInfo = packageManager.queryIntentActivities(viewIntent, 0);
        Intent[] extraIntents = new Intent[resInfo.size()];
        for (int i = 0; i < resInfo.size(); i++) {
            // Extract the label, append it, and repackage it in a LabeledIntent
            ResolveInfo ri = resInfo.get(i);
            String packageName = ri.activityInfo.packageName;
            Intent extraViewIntent = new Intent();
            extraViewIntent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            extraViewIntent.setAction(Intent.ACTION_VIEW);
            extraViewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            extraViewIntent.setData(contentUri);
            CharSequence label = ri.loadLabel(packageManager);
            extraIntents[i] = new LabeledIntent(extraViewIntent, packageName, label, ri.icon);
        }
        Intent chooserIntent = Intent.createChooser(intent, context.getString(R.string.reader_action_share_open));
        if (extraIntents.length > 0) chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
        return chooserIntent;

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:die-tageszeitung,项目名称:tazapp-android,代码行数:53,代码来源:Paper.java

示例7: build

import android.content.pm.LabeledIntent; //导入依赖的package包/类
public Intent build(String chooserTitle, final Context context) throws NoShareIntentsException {
	if (_intents.isEmpty()) {
		throw new IllegalStateException("Please add shares!");
	}

	final PackageManager packageManager = context.getPackageManager();

	ArrayList<LabeledIntent> extraIntents = new ArrayList<>(_intents.size() * 2);
	Intent mainIntent = null;

	for (int i = 0; i < _intents.size(); ++i) {
		Intent intent = _intents.get(i);

		List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0);
		if (resolveInfoList == null) {//Some devices return null...
			continue;
		}
		if (mainIntent == null && resolveInfoList.isEmpty() == false) {
			mainIntent = intent;
			//This will be main chooser so we don't want duplicates
			continue;
		}
		for (ResolveInfo info : resolveInfoList) {
			// Extract the label, append it, and repackage it in a LabeledIntent
			String packageName = info.activityInfo.packageName;

			intent.setComponent(new ComponentName(packageName, info.activityInfo.name));
			final LabeledIntent labeledIntent =
					new LabeledIntent(intent, packageName, info.loadLabel(packageManager), info.icon);
			extraIntents.add(labeledIntent);
		}
	}

	if (mainIntent == null) {
		Logger.e("No app can't handle such share request");
		throw new NoShareIntentsException("No app can't handle such share request");
	}

	final Intent chooser = Intent.createChooser(mainIntent, chooserTitle);
	chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents.toArray(new LabeledIntent[extraIntents.size()]));
	return chooser;
}
 
开发者ID:gelldur,项目名称:Common-Android,代码行数:43,代码来源:ShareIntentBuilder.java

示例8: itemViewOnShare

import android.content.pm.LabeledIntent; //导入依赖的package包/类
@Override
public void itemViewOnShare(MobiStegoItem mobiStegoItem) {
    PackageManager pm = getPackageManager();
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    //emailIntent.setType("vnd.android.cursor.item/*");
    emailIntent.setType("vnd.android.cursor.item/*");
    Intent openInChooser = Intent.createChooser(new Intent(), getResources().getString(R.string.send));

    File f = mobiStegoItem.getBitmap();
    if (f != null) {


        List<ResolveInfo> resInfo = pm.queryIntentActivities(emailIntent, 0);
        List<LabeledIntent> intentList = new ArrayList<>();
        for (int i = 0; i < resInfo.size(); i++) {
            // Extract the label, append it, and repackage it in a LabeledIntent
            ResolveInfo ri = resInfo.get(i);
            String packageName = ri.activityInfo.packageName;
            if(packageName.contains("whatsapp")||packageName.contains("telegram"))
                continue;

            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("vnd.android.cursor.item/*");
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));

        }

        // convert intentList to array
        LabeledIntent[] extraIntents = intentList.toArray( new LabeledIntent[ intentList.size() ]);

        openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
        startActivity(openInChooser);



        //startActivity(Intent.createChooser(emailIntent, getResources().getString(R.string.send)));
    }
}
 
开发者ID:paspao,项目名称:MobiStego,代码行数:43,代码来源:MainActivity.java

示例9: openMailChooser

import android.content.pm.LabeledIntent; //导入依赖的package包/类
public static void openMailChooser(Context context, String text, String[] mails, String subject) {
    Intent mailIntent = new Intent();
    mailIntent.setAction(Intent.ACTION_SEND);
    mailIntent.putExtra(Intent.EXTRA_TEXT, text);
    mailIntent.putExtra(Intent.EXTRA_EMAIL, mails);
    mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    mailIntent.setType(INTENT_TYPE_MSG);

    PackageManager pm = context.getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType(INTENT_TYPE_TEXT);

    Intent openInChooser = Intent.createChooser(mailIntent, "");

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (ResolveInfo ri : resInfo) {
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains(PACKAGE_EMAIL)) {
            mailIntent.setPackage(packageName);
        } else if (packageName.contains(PACKAGE_MMS) || packageName.contains(PACKAGE_GMAIL)) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType(INTENT_TYPE_TEXT);
            if (packageName.contains(PACKAGE_MMS)) {
                intent.putExtra("subject", subject);
                intent.putExtra("sms_body", text);
                intent.putExtra("address", mails[0]);
                intent.setType(INTENT_TYPE_MSG);
            } else if (packageName.contains(PACKAGE_GMAIL)) {
                intent.putExtra(Intent.EXTRA_TEXT, text);
                intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                intent.putExtra(Intent.EXTRA_EMAIL, mails);
                intent.setType(INTENT_TYPE_MSG);
            }

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    context.startActivity(openInChooser);
}
 
开发者ID:konifar,项目名称:kotoha-android,代码行数:47,代码来源:AppUtils.java


注:本文中的android.content.pm.LabeledIntent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。