android.content.Intent#addCategory ( )源码实例Demo

下面列出了android.content.Intent#addCategory ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BotLibre   文件: IntentIntegrator.java
/**
 * Shares the given text by encoding it as a barcode, such that another user can
 * scan the text off the screen of the device.
 *
 * @param text the text string to encode as a barcode
 * @param type type of data to encode. See {@code com.google.zxing.client.android.Contents.Type} constants.
 * @return the {@link AlertDialog} that was shown to the user prompting them to download the app
 *   if a prompt was needed, or null otherwise
 */
public final AlertDialog shareText(CharSequence text, CharSequence type) {
  Intent intent = new Intent();
  intent.addCategory(Intent.CATEGORY_DEFAULT);
  intent.setAction(BS_PACKAGE + ".ENCODE");
  intent.putExtra("ENCODE_TYPE", type);
  intent.putExtra("ENCODE_DATA", text);
  String targetAppPackage = findTargetAppPackage(intent);
  if (targetAppPackage == null) {
    return showDownloadDialog();
  }
  intent.setPackage(targetAppPackage);
  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
  attachMoreExtras(intent);
  if (fragment == null) {
    activity.startActivity(intent);
  } else {
    fragment.startActivity(intent);
  }
  return null;
}
 
源代码2 项目: MyHearts   文件: BitmapUtil.java
public static Intent buildImageGetIntent(Uri saveTo, int aspectX, int aspectY,
                                         int outputX, int outputY, boolean returnData) {
    Log.i(TAG, "Build.VERSION.SDK_INT : " + Build.VERSION.SDK_INT);
    Intent intent = new Intent();
    if (Build.VERSION.SDK_INT < 19) {
        intent.setAction(Intent.ACTION_GET_CONTENT);
    } else {
        intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
    }
    intent.setType("image/*");
    intent.putExtra("output", saveTo);
    intent.putExtra("aspectX", aspectX);
    intent.putExtra("aspectY", aspectY);
    intent.putExtra("outputX", outputX);
    intent.putExtra("outputY", outputY);
    intent.putExtra("scale", true);
    intent.putExtra("return-data", returnData);
    intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());
    return intent;
}
 
/**
 * Shares the given text by encoding it as a barcode, such that another user can
 * scan the text off the screen of the device.
 *
 * @param text the text string to encode as a barcode
 * @param type type of data to encode. See {@code com.google.zxing.client.android.Contents.Type} constants.
 * @return the {@link AlertDialog} that was shown to the user prompting them to download the app
 *   if a prompt was needed, or null otherwise
 */
public final AlertDialog shareText(CharSequence text, CharSequence type) {
  Intent intent = new Intent();
  intent.addCategory(Intent.CATEGORY_DEFAULT);
  intent.setAction(BS_PACKAGE + ".ENCODE");
  intent.putExtra("ENCODE_TYPE", type);
  intent.putExtra("ENCODE_DATA", text);
  String targetAppPackage = findTargetAppPackage(intent);
  if (targetAppPackage == null) {
    return showDownloadDialog();
  }
  intent.setPackage(targetAppPackage);
  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
  attachMoreExtras(intent);
  if (fragment == null) {
    activity.startActivity(intent);
  } else {
    fragment.startActivity(intent);
  }
  return null;
}
 
源代码4 项目: Wrox-ProfessionalAndroid-4E   文件: MyActivity.java
private void listing6_10() {
  // Listing 6-10: Generating a list of possible actions
  // to be performed on specific data
  PackageManager packageManager = getPackageManager();

  // Create the intent used to resolve which actions should appear in the menu.
  Intent intent = new Intent();
  intent.setType("vnd.android.cursor.item/vnd.com.professionalandroid.provider.moonbase");
  intent.addCategory(Intent.CATEGORY_SELECTED_ALTERNATIVE);

  // Specify flags. In this case, return all matches
  int flags = PackageManager.MATCH_ALL;

  // Generate the list
  List<ResolveInfo> actions;
  actions = packageManager.queryIntentActivities(intent, flags);

  // Extract the list of action names
  ArrayList<CharSequence> labels = new ArrayList<CharSequence>();
  Resources r = getResources();
  for (ResolveInfo action : actions)
    labels.add(action.nonLocalizedLabel);
}
 
源代码5 项目: Android-Application-ZJB   文件: ProgressWebView.java
private void openFileChooserImpl(ValueCallback<Uri> uploadMsg) {
    mUploadMessage = uploadMsg;
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("image/*");
    Activity activity = (Activity) getContext();
    activity.startActivityForResult(Intent.createChooser(i, "File Chooser"), BaseWebActivity.FILE_CHOOSER_RESULTCODE);
}
 
源代码6 项目: AssistantBySDK   文件: ActivityInvokeAPI.java
/**
 * 打开某条微博正文。
 * 
 * @param activity
 * @param blogId 某条微博id
 */
public static void openDetail(Activity activity,String blogId){
    if(activity==null){
        return;
    }
    Intent intent=new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setData(Uri.parse("sinaweibo://detail?mblogid="+blogId));
    activity.startActivity(intent);
}
 
源代码7 项目: InviZible   文件: UpdateService.java
private void updateNotification(int serviceStartId, int notificationId, long startTime, String Ticker, String Title, String Text, int percent) {

        //These three lines makes Notification to open main activity after clicking on it
        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(Intent.ACTION_MAIN);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Intent stopDownloadIntent = new Intent(this, UpdateService.class);
        stopDownloadIntent.setAction(STOP_DOWNLOAD_ACTION);
        stopDownloadIntent.putExtra("ServiceStartId", serviceStartId);
        PendingIntent stopDownloadPendingIntent = PendingIntent.getService(this, notificationId, stopDownloadIntent, PendingIntent.FLAG_UPDATE_CURRENT);


        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, UPDATE_CHANNEL_ID);
        builder.setContentIntent(contentIntent)
                .setOngoing(true)   //Can't be swiped out
                .setSmallIcon(R.drawable.ic_update)
                .setTicker(Ticker)
                .setContentTitle(Title) //Заголовок
                .setContentText(Text) // Текст уведомления
                .setOnlyAlertOnce(true)
                .setWhen(startTime - (System.currentTimeMillis() - startTime))
                .setUsesChronometer(true)
                .addAction(R.drawable.ic_stop, getText(R.string.cancel_download), stopDownloadPendingIntent);

        int PROGRESS_MAX = 100;
        builder.setProgress(PROGRESS_MAX, percent, false);

        Notification notification = builder.build();

        synchronized (notificationManager) {
            notificationManager.notify(notificationId, notification);
        }
    }
 
源代码8 项目: fontster   文件: SettingsFragment.java
private boolean viewSource() {
  final Intent intent = new Intent();
  intent.setAction(Intent.ACTION_VIEW);
  intent.addCategory(Intent.CATEGORY_BROWSABLE);
  intent.setData(Uri.parse(getString(R.string.settings_link_github)));
  startActivity(intent);
  return true;
}
 
源代码9 项目: ByWebView   文件: MyX5WebChromeClient.java
private void openFileChooserImplForAndroid5(ValueCallback<Uri[]> uploadMsg) {
    mUploadMessageForAndroid5 = uploadMsg;
    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    contentSelectionIntent.setType("image/*");

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    chooserIntent.putExtra(Intent.EXTRA_TITLE, "图片选择");

    mIWebPageView.startFileChooserForResult(chooserIntent, FILECHOOSER_RESULTCODE_FOR_ANDROID_5);
}
 
源代码10 项目: FastAccess   文件: FloatingVHPresenter.java
@Override public void onItemClick(int position, View v, AppsModel item) {
    try {
        Context context = v.getContext();
        PackageManager manager = context.getPackageManager();
        Intent intent = manager.getLaunchIntentForPackage(item.getPackageName());
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setComponent(new ComponentName(item.getPackageName(), item.getActivityInfoName()));
        context.startActivity(intent);
    } catch (Exception e) {// app uninstalled/not found
        e.printStackTrace();
        item.delete();
    }
    super.onItemClick(position, v, item);
}
 
源代码11 项目: focus-android   文件: HomeScreen.java
/**
 * Switch to the the default home screen activity (launcher).
 */
private static void goToHomeScreen(Context context) {
    Intent intent = new Intent(Intent.ACTION_MAIN);

    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
源代码12 项目: PowerFileExplorer   文件: Main.java
public void run() {

            if (mSettings.directintent2 == null) {
                Intent intent = new Intent("com.adamrocker.android.simeji.ACTION_INTERCEPT");
                intent.addCategory("com.adamrocker.android.simeji.REPLACE");

                int startsel = mEditor.getSelectionStart();
                int endsel = mEditor.getSelectionEnd();
                Editable text = mEditor.getText();

                String substr = "";
                if (startsel != endsel) {
                    if (endsel < startsel) {
                        int temp = startsel;
                        startsel = endsel;
                        endsel = temp;
                    }
                    if (endsel - startsel > jp.sblo.pandora.jota.text.TextView.MAX_PARCELABLE) {
                        Toast.makeText(Main.this, R.string.toast_overflow_of_limit,
                                Toast.LENGTH_LONG).show();
                        return;
                    }
                    substr = text.subSequence(startsel, endsel).toString();
                }
                intent.putExtra("replace_key", substr);

                try {
                    Intent pickIntent = new Intent(Main.this, ActivityPicker.class);
                    pickIntent.putExtra(Intent.EXTRA_INTENT, intent);
                    mReservedIntent = intent;
                    mReservedRequestCode = REQUESTCODE_MUSHROOM;
                    startActivityForResult(pickIntent, REQUESTCODE_APPCHOOSER);
                } catch (Exception e) {
                }
            } else {
                sendDirectIntent(mSettings.directintent2);
            }
        }
 
源代码13 项目: android   文件: LoginActivity.java
private void doSelectCACertificate() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    // we don't really care what kind of file it is as long as we can parse it
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {
        startActivityForResult(
                Intent.createChooser(intent, getString(R.string.select_ca_file)),
                FILE_SELECT_CODE);
    } catch (ActivityNotFoundException e) {
        // case for user not having a file browser installed
        Utils.showSnackBar(this, getString(R.string.please_install_file_browser));
    }
}
 
源代码14 项目: MyBookshelf   文件: QRCodeScanActivity.java
private void chooseFromGallery() {
    try {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("image/*");
        startActivityForResult(intent, REQUEST_QR_IMAGE);
    } catch (Exception ignored) {
        FilePicker picker = new FilePicker(this, FilePicker.FILE);
        picker.setBackgroundColor(getResources().getColor(R.color.background));
        picker.setTopBackgroundColor(getResources().getColor(R.color.background));
        picker.setItemHeight(30);
        picker.setOnFilePickListener(currentPath -> zxingview.decodeQRCode(currentPath));
        picker.show();
    }
}
 
源代码15 项目: openboard   文件: SetupWizardActivity.java
void invokeLanguageAndInputSettings() {
    final Intent intent = new Intent();
    intent.setAction(Settings.ACTION_INPUT_METHOD_SETTINGS);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    startActivity(intent);
    mNeedsToAdjustStepNumberToSystemState = true;
}
 
源代码16 项目: commcare-android   文件: CommCareSessionService.java
/**
 * Show a notification while this service is running.
 */
private void showLoggedInNotification(User user) {
    //We always want this click to simply bring the live stack back to the top
    Intent callable = new Intent(this, DispatchActivity.class);
    callable.setAction("android.intent.action.MAIN");
    callable.addCategory("android.intent.category.LAUNCHER");

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, callable, 0);

    String notificationText;
    if (AppUtils.getInstalledAppRecords().size() > 1) {
        try {
            notificationText = Localization.get("notification.logged.in",
                    new String[]{Localization.get("app.display.name")});
        } catch (NoLocalizedTextException e) {
            notificationText = getString(NOTIFICATION);
        }
    } else {
        notificationText = getString(NOTIFICATION);
    }

    // Set the icon, scrolling text and timestamp
    Notification notification = new NotificationCompat.Builder(this, CommCareNoficationManager.NOTIFICATION_CHANNEL_ERRORS_ID)
            .setContentTitle(notificationText)
            .setContentText("Session Expires: " + DateFormat.format("MMM dd h:mmaa", sessionExpireDate))
            .setSmallIcon(org.commcare.dalvik.R.drawable.notification)
            .setContentIntent(contentIntent)
            .build();

    if (user != null) {
        //Send the notification.
        this.startForeground(NOTIFICATION, notification);
    }
}
 
源代码17 项目: Aurora   文件: DeviceUtils.java
public static boolean isHaveMarket(Context context) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.APP_MARKET");
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
    return infos.size() > 0;
}
 
源代码18 项目: appcan-android   文件: CBrowserMainFrame.java
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
    ((EBrowserActivity) mContext).setmUploadMessage(getCompatCallback(uploadMsg));
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("*/*");
    ((EBrowserActivity) mContext).startActivityForResult(Intent.createChooser(i, "File Chooser"),
            EBrowserActivity.FILECHOOSER_RESULTCODE);
}
 
源代码19 项目: FileTransfer   文件: FileUtils.java
private static Intent getExcelFileIntent(Uri uri) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(uri, "application/vnd.ms-excel");
    return intent;
}
 
源代码20 项目: android-tv-launcher   文件: GetAppList.java
public ArrayList<AppBean> getLaunchAppList() {
    PackageManager localPackageManager = mContext.getPackageManager();
    Intent localIntent = new Intent("android.intent.action.MAIN");
    localIntent.addCategory("android.intent.category.LAUNCHER");
    List<ResolveInfo> localList = localPackageManager.queryIntentActivities(localIntent, 0);
    ArrayList<AppBean> localArrayList = null;
    Iterator<ResolveInfo> localIterator = null;
    if (localList != null) {
        localArrayList = new ArrayList<AppBean>();
        localIterator = localList.iterator();
    }
    while (true) {
        if (!localIterator.hasNext())
            break;
        ResolveInfo localResolveInfo = (ResolveInfo) localIterator.next();
        AppBean localAppBean = new AppBean();
        localAppBean.setIcon(localResolveInfo.activityInfo.loadIcon(localPackageManager));
        localAppBean.setName(localResolveInfo.activityInfo.loadLabel(localPackageManager).toString());
        localAppBean.setPackageName(localResolveInfo.activityInfo.packageName);
        localAppBean.setDataDir(localResolveInfo.activityInfo.applicationInfo.publicSourceDir);
        localAppBean.setLauncherName(localResolveInfo.activityInfo.name);
        String pkgName = localResolveInfo.activityInfo.packageName;
        PackageInfo mPackageInfo;
        try {
            mPackageInfo = mContext.getPackageManager().getPackageInfo(pkgName, 0);
            if ((mPackageInfo.applicationInfo.flags & mPackageInfo.applicationInfo.FLAG_SYSTEM) > 0) {//系统预装
                localAppBean.setSysApp(true);
            }
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }

        String noSeeApk = localAppBean.getPackageName();

        // 屏蔽自己 、芒果 、tcl新
        if (!noSeeApk.equals("com.cqsmiletv") && !noSeeApk.endsWith("com.starcor.hunan") && !noSeeApk.endsWith("com.tcl.matrix.tventrance")) {
            localArrayList.add(localAppBean);
        }
    }
    return localArrayList;
}
 
 方法所在类
 同类方法