Java 类android.content.ActivityNotFoundException 实例源码

项目:Camera-Roll-Android-App    文件:ItemActivity.java   
public void setPhotoAs() {
    if (!(albumItem instanceof Photo)) {
        return;
    }

    Uri uri = albumItem.getUri(this);

    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.setDataAndType(uri, MediaType.getMimeType(this, uri));
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    try {
        startActivityForResult(Intent.createChooser(intent,
                getString(R.string.set_as)), 13);
    } catch (SecurityException se) {
        Toast.makeText(this, "Error (SecurityException)", Toast.LENGTH_SHORT).show();
        se.printStackTrace();
    } catch (ActivityNotFoundException anfe) {
        Toast.makeText(this, "No App found", Toast.LENGTH_SHORT).show();
        anfe.printStackTrace();
    }
}
项目:PicShow-zhaipin    文件:DeviceUtils.java   
/**
 * 发送邮件
 *
 * @param context
 * @param subject 主题
 * @param content 内容
 * @param emails  邮件地址
 */
public static void sendEmail(Context context, String subject,
                             String content, String... emails) {
    try {
        Intent intent = new Intent(Intent.ACTION_SEND);
        // 模拟器
        // intent.setType("text/plain");
        intent.setType("message/rfc822"); // 真机
        intent.putExtra(Intent.EXTRA_EMAIL, emails);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, content);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
项目:MVPArms_Fragment-fragment    文件:DeviceUtils.java   
/**
 * 发送邮件
 *
 * @param context
 * @param subject 主题
 * @param content 内容
 * @param emails  邮件地址
 */
public static void sendEmail(Context context, String subject,
                             String content, String... emails) {
    try {
        Intent intent = new Intent(Intent.ACTION_SEND);
        // 模拟器
        // intent.setType("text/plain");
        intent.setType("message/rfc822"); // 真机
        intent.putExtra(Intent.EXTRA_EMAIL, emails);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, content);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
项目:GitHub    文件:DeviceUtils.java   
/**
 * 发送邮件
 *
 * @param context
 * @param subject 主题
 * @param content 内容
 * @param emails  邮件地址
 */
public static void sendEmail(Context context, String subject,
                             String content, String... emails) {
    try {
        Intent intent = new Intent(Intent.ACTION_SEND);
        // 模拟器
        // intent.setType("text/plain");
        intent.setType("message/rfc822"); // 真机
        intent.putExtra(Intent.EXTRA_EMAIL, emails);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, content);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
项目:VirtualAPK    文件:VAInstrumentation.java   
private ActivityResult realExecStartActivity(
        Context who, IBinder contextThread, IBinder token, Activity target,
        Intent intent, int requestCode, Bundle options) {
    ActivityResult result = null;
    try {
        Class[] parameterTypes = {Context.class, IBinder.class, IBinder.class, Activity.class, Intent.class,
        int.class, Bundle.class};
        result = (ActivityResult)ReflectUtil.invoke(Instrumentation.class, mBase,
                "execStartActivity", parameterTypes,
                who, contextThread, token, target, intent, requestCode, options);
    } catch (Exception e) {
        if (e.getCause() instanceof ActivityNotFoundException) {
            throw (ActivityNotFoundException) e.getCause();
        }
        e.printStackTrace();
    }

    return result;
}
项目:GitHub    文件:CameraPickerHelper.java   
private void startCameraIntent(final Activity activity, final Fragment fragment, String subFolder,
                               final String action, final int requestCode) {
    final String cameraOutDir = BoxingFileHelper.getExternalDCIM(subFolder);
    try {
        if (BoxingFileHelper.createFile(cameraOutDir)) {
            mOutputFile = new File(cameraOutDir, String.valueOf(System.currentTimeMillis()) + ".jpg");
            mSourceFilePath = mOutputFile.getPath();
            Intent intent = new Intent(action);
            Uri uri = getFileUri(activity.getApplicationContext(), mOutputFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            try {
                startActivityForResult(activity, fragment, intent, requestCode);
            } catch (ActivityNotFoundException ignore) {
                callbackError();
            }

        }
    } catch (ExecutionException | InterruptedException e) {
        BoxingLog.d("create file" + cameraOutDir + " error.");
    }

}
项目:kognitivo    文件:LoginManager.java   
private boolean tryFacebookActivity(
        StartActivityDelegate startActivityDelegate,
        LoginClient.Request request) {

    Intent intent = getFacebookActivityIntent(request);

    if (!resolveIntent(intent)) {
        return false;
    }

    try {
        startActivityDelegate.startActivityForResult(
                intent,
                LoginClient.getLoginRequestCode());
    } catch (ActivityNotFoundException e) {
        return false;
    }

    return true;
}
项目:Aurora    文件:DeviceUtils.java   
/**
 * 发送邮件
 *
 * @param context
 * @param subject 主题
 * @param content 内容
 * @param emails  邮件地址
 */
public static void sendEmail(Context context, String subject,
                             String content, String... emails) {
    try {
        Intent intent = new Intent(Intent.ACTION_SEND);
        // 模拟器
        // intent.setType("text/plain");
        intent.setType("message/rfc822"); // 真机
        intent.putExtra(Intent.EXTRA_EMAIL, emails);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, content);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
项目:LaunchEnr    文件:Launcher.java   
public boolean startActivitySafely(View v, Intent intent, ItemInfo item) {
    if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
        Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
        return false;
    }
    // Only launch using the new animation if the shortcut has not opted out (this is a
    // private contract between launcher and may be ignored in the future).
    boolean useLaunchAnimation = (v != null) &&
            !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION);
    Bundle optsBundle = useLaunchAnimation ? getActivityLaunchOptions(v) : null;

    UserHandle user = item == null ? null : item.user;

    // Prepare intent
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (v != null) {
        intent.setSourceBounds(getViewBounds(v));
    }
    try {
        if (AndroidVersion.isAtLeastMarshmallow
                && (item instanceof ShortcutInfo)
                && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT
                 || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT)
                && !((ShortcutInfo) item).isPromise()) {
            // Shortcuts need some special checks due to legacy reasons.
            startShortcutIntentSafely(intent, optsBundle, item);
        } else if (user == null || user.equals(Process.myUserHandle())) {
            // Could be launching some bookkeeping activity
            startActivity(intent, optsBundle);
        } else {
            LauncherAppsCompat.getInstance(this).startActivityForProfile(
                    intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
        }
        return true;
    } catch (ActivityNotFoundException|SecurityException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
    return false;
}
项目:Kids-Portal-Android    文件:helper_main.java   
private static void openFile(Activity activity, File file, String string, View view) {

        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Uri contentUri = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", file);
            intent.setDataAndType(contentUri,string);

        } else {
            intent.setDataAndType(Uri.fromFile(file),string);
        }

        try {
            activity.startActivity (intent);
        } catch (ActivityNotFoundException e) {
            Snackbar.make(view, R.string.toast_install_app, Snackbar.LENGTH_LONG).show();
        }
    }
项目:simple-share-android    文件:StandaloneActivity.java   
@Override
public void onDocumentPicked(DocumentInfo doc) {
    final FragmentManager fm = getFragmentManager();
    if (doc.isDirectory()) {
        mState.stack.push(doc);
        mState.stackTouched = true;
        onCurrentDirectoryChanged(ANIM_DOWN);
    } else {
        // Fall back to viewing
        final Intent view = new Intent(Intent.ACTION_VIEW);
        view.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        view.setData(doc.derivedUri);
        try {
            startActivity(view);
        } catch (ActivityNotFoundException ex2) {
            Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show();
        }
    }
}
项目:Paper-Launcher    文件:IntentUtil.java   
public static void startGoogleSearchActivity(View view) {
    final Context context = view.getContext();

    final SearchManager searchManager =
            (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    if (searchManager == null) {
        return;
    }

    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        return;
    }

    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);

    Bundle appSearchData = new Bundle();
    appSearchData.putString("source", context.getPackageName());

    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    intent.setSourceBounds(getViewBounds(view));
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        ex.printStackTrace();
    }
}
项目:okwallet    文件:RequestCoinsFragment.java   
private void handleLocalApp() {
    final ComponentName component = new ComponentName(activity, SendCoinsActivity.class);
    final PackageManager pm = activity.getPackageManager();
    final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(determineBitcoinRequestStr(false)));

    try {
        // launch intent chooser with ourselves excluded
        pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
        startActivity(intent);
    } catch (final ActivityNotFoundException x) {
        new Toast(activity).longToast(R.string.request_coins_no_local_app_msg);
    } finally {
        pm.setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    }

    activity.finish();
}
项目:amap    文件:OsUtils.java   
public static void gotoWchat(Activity activity)
{
    try
    {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI");

        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setComponent(cmp);
        activity.startActivity(intent);
    }
    catch (ActivityNotFoundException e)
    {
        Toast.makeText(activity, "检查到您手机没有安装微信,请安装后使用该功能", Toast.LENGTH_LONG).show();
    }
}
项目:GxIconAndroid    文件:ExtraUtil.java   
public static void shareText(Context context, String content, String hint) {
    if (context == null || TextUtils.isEmpty(content)) {
        return;
    }

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, content);
    try {
        if (TextUtils.isEmpty(hint)) {
            context.startActivity(intent);
        } else {
            context.startActivity(Intent.createChooser(intent, hint));
        }
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
项目:chromium-for-android-56-debug-video    文件:UpdateMenuItemHelper.java   
/**
 * Handles a click on the update menu item.
 * @param activity The current {@link ChromeActivity}.
 */
public void onMenuItemClicked(ChromeActivity activity) {
    if (mUpdateUrl == null) return;

    // If the update menu item is showing because it was forced on through about://flags
    // then mLatestVersion may be null.
    if (mLatestVersion != null) {
        PrefServiceBridge.getInstance().setLatestVersionWhenClickedUpdateMenuItem(
                mLatestVersion);
    }

    // Fire an intent to open the URL.
    try {
        Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mUpdateUrl));
        activity.startActivity(launchIntent);
        recordItemClickedHistogram(ITEM_CLICKED_INTENT_LAUNCHED);
        PrefServiceBridge.getInstance().setClickedUpdateMenuItem(true);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "Failed to launch Activity for: %s", mUpdateUrl);
        recordItemClickedHistogram(ITEM_CLICKED_INTENT_FAILED);
    }
}
项目:Floo    文件:OpenDirectlyHandler.java   
@Override
public boolean onTargetNotFound(
    @NonNull Context context,
    @NonNull Uri uri,
    @NonNull Bundle bundle,
    @Nullable Integer intentFlags) {

    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.putExtras(bundle);
    if (intentFlags != null) {
        intent.setFlags(intentFlags);
    }
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException exception) {
        exception.printStackTrace();
        return false;
    }
    return true;
}
项目:RLibrary    文件:RUtils.java   
/**
 * qq咨询
 */
public static boolean chatQQ(Context context, String qq) {
    try {
        if (CmdUtil.checkApkExist(context, "com.tencent.mobileqq")) {
            String url = "mqqwpa://im/chat?chat_type=wpa&uin=" + qq;
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            return true;
        } else {
            T_.error("您没有安装腾讯QQ");
        }
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        T_.error("您没有安装腾讯QQ");
    }
    return false;
}
项目:LoggingInterceptor    文件:MainActivity.java   
private void downloadFile(ResponseBody body) throws IOException {
    int count;
    byte data[] = new byte[1024 * 4];
    InputStream bis = new BufferedInputStream(body.byteStream(), 1024 * 8);
    outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "file.zip");
    OutputStream output = new FileOutputStream(outputFile);
    while ((count = bis.read(data)) != -1) {
        output.write(data, 0, count);
    }

    output.flush();
    output.close();
    bis.close();

    Intent target = new Intent(Intent.ACTION_VIEW);
    target.setDataAndType(Uri.fromFile(outputFile), "application/pdf");
    target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

    Intent intent = Intent.createChooser(target, "Open File");
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
项目:CSI-KJSCEOfficial    文件:Utils.java   
public static void onShareClick(Context context, String message, String appName) {

        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");

        // message might be in html form, so convert back to plain text
        message = Html.fromHtml(message).toString();
        sendIntent.putExtra(Intent.EXTRA_TEXT, message);
        if(!appName.isEmpty())
            sendIntent.setPackage(appName);
       try {
           context.startActivity(sendIntent);
       } catch(ActivityNotFoundException e){
           Log.e("Social Share", "package does not exist");
           Toast.makeText(context, "Action not supported",Toast.LENGTH_SHORT).show();
       }

    }
项目:appinventor-extensions    文件:BarcodeScanner.java   
/**
 * Begins a barcode scan, using the camera. When the scan is complete, the
 * AfterScan event will be raised.
 */
@SimpleFunction(description = "Begins a barcode scan, using the camera. When the scan " +
    "is complete, the AfterScan event will be raised.")
public void DoScan() {
  Intent intent = new Intent(SCAN_INTENT);
  if (!useExternalScanner && (SdkLevel.getLevel() >= SdkLevel.LEVEL_ECLAIR)) {  // Should we attempt to use an internal scanner?
    String packageName = container.$form().getPackageName();
    intent.setComponent(new ComponentName(packageName, "com.google.zxing.client.android.AppInvCaptureActivity"));
  }
  if (requestCode == 0) {
    requestCode = form.registerForActivityResult(this);
  }
  try {
    container.$context().startActivityForResult(intent, requestCode);
  } catch (ActivityNotFoundException e) {
    e.printStackTrace();
    container.$form().dispatchErrorOccurredEvent(this, "BarcodeScanner",
      ErrorMessages.ERROR_NO_SCANNER_FOUND, "");
  }
}
项目:Perfect-Day    文件:CreateTaskBySpeech.java   
@OnClick(R.id.btnSpeak)
public void onSpeakButtonClick() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}
项目:MVPArmsTest1    文件:DeviceUtils.java   
/**
 * 发送邮件
 *
 * @param context
 * @param subject 主题
 * @param content 内容
 * @param emails  邮件地址
 */
public static void sendEmail(Context context, String subject,
                             String content, String... emails) {
    try {
        Intent intent = new Intent(Intent.ACTION_SEND);
        // 模拟器
        // intent.setType("text/plain");
        intent.setType("message/rfc822"); // 真机
        intent.putExtra(Intent.EXTRA_EMAIL, emails);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, content);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
项目:FicsaveMiddleware    文件:FicsaveDownloadListener.java   
private void openFileOnDevice(Uri mostRecentDownload) {
    Intent fileIntent = new Intent(Intent.ACTION_VIEW);
    // DownloadManager stores the Mime Type. Makes it really easy for us.
    String mimeType =
            mDownloadManager.getMimeTypeForDownloadedFile(fileDownloadId);
    fileIntent.setDataAndType(mostRecentDownload, mimeType);
    fileIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {
        mContext.startActivity(fileIntent);
    } catch (ActivityNotFoundException e) {
        Log.d("ficsaveM/cantOpenFile", fileName);
        trackFileCannotOpen();
        Toast.makeText(mContext, "You don't have a supported ebook reader",
                Toast.LENGTH_LONG).show();
    }
}
项目:Say_it    文件:SearchActivity.java   
/**
 * Showing google speech input dialog
 */
private void promptSpeechInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}
项目:android-about-box    文件:AboutBoxUtils.java   
public static void openApplication(Activity context, String appURI, String webURI) {
    try {
        context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(appURI)));
    } catch (ActivityNotFoundException e1) {
        try {
            openHTMLPage(context, webURI);
        } catch (ActivityNotFoundException e2) {
            Toast.makeText(context, R.string.egab_can_not_open, Toast.LENGTH_SHORT).show();
        }
    }
}
项目:https-github.com-hyb1996-NoRootScriptDroid    文件:IntentUtil.java   
public static boolean browse(Context context, String link) {
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException ignored) {
        return false;
    }

}
项目:decoy    文件:VideoMessageHelper.java   
/**
 * API19 之前选择视频
 */
protected void chooseVideoFromLocalBeforeKitKat() {
    Intent mIntent = new Intent(Intent.ACTION_GET_CONTENT);
    mIntent.setType(C.MimeType.MIME_VIDEO_ALL);
    mIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
    try {
        activity.startActivityForResult(mIntent, localRequestCode);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(activity, R.string.gallery_invalid, Toast.LENGTH_SHORT).show();
    }
}
项目:SimpleAvatarPicker    文件:AbstractAvatarPicker.java   
private void startActivityToCropImage() {
    mIntentBuilder.outputUri(mUri);
    Intent intent = mIntentBuilder.buildCropApp();
    try {
        startActivityForResult(intent, REQ_CODE_CROP_AVATAR);
    } catch (ActivityNotFoundException e) {
        showToastMsg("Your device is not support to crop image.");
    }
}
项目:tvConnect_android    文件:ResultHandler.java   
final void openURL(String url) {
  // Strangely, some Android browsers don't seem to register to handle HTTP:// or HTTPS://.
  // Lower-case these as it should always be OK to lower-case these schemes.
  if (url.startsWith("HTTP://")) {
    url = "http" + url.substring(4);
  } else if (url.startsWith("HTTPS://")) {
    url = "https" + url.substring(5);
  }
  Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
  try {
    launchIntent(intent);
  } catch (ActivityNotFoundException ignored) {
    Log.w(TAG, "Nothing available to handle " + intent);
  }
}
项目:OpenHub    文件:AppOpener.java   
public static void launchEmail(@NonNull Context context, @NonNull String email){
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("message/rfc822");
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try{
        context.startActivity(Intent.createChooser(intent, context.getString(R.string.send_email)));
    }catch (ActivityNotFoundException e){
        Toasty.warning(context, context.getString(R.string.no_email_clients)).show();
    }
}
项目:decoy    文件:PreviewImageFromCameraActivity.java   
/**
 * 获取本地图片
 */
protected void choosePictureFromLocal() {
    if (!StorageUtil.hasEnoughSpaceForWrite(PreviewImageFromCameraActivity.this, StorageType.TYPE_IMAGE, true)) {
        return;
    }

    new AsyncTask<String, Integer, Boolean>() {

        @Override
        protected void onPreExecute() {
            Toast.makeText(PreviewImageFromCameraActivity.this, R.string.waitfor_image_local, Toast.LENGTH_LONG).show();
        }

        @Override
        protected Boolean doInBackground(String... params) {
            return true;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            if (Build.VERSION.SDK_INT >= 11) {
                intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
            }
            try {
                PreviewImageFromCameraActivity.this.startActivityForResult(intent, RequestCode.GET_LOCAL_IMAGE);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(PreviewImageFromCameraActivity.this, R.string.gallery_invalid, Toast.LENGTH_LONG).show();
            }
        }
    }.execute();
}
项目:Bigbang    文件:AppItem.java   
@Override
public boolean openUI(Context context) {
    try {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        intent.setComponent(mName);
        mContext.startActivity(intent);
    } catch (ActivityNotFoundException e) {
    }
    return true;
}
项目:chilly    文件:SearchFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSpinnerFragment = new SpinnerFragment();
    mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
    mVideoCursorAdapter.setMapper(new VideoCursorMapper());
    setSearchResultProvider(this);
    setOnItemViewClickedListener(new ItemViewClickedListener());
    if (DEBUG) {
        Log.d(TAG, "User is initiating a search. Do we have RECORD_AUDIO permission? " +
            hasPermission(Manifest.permission.RECORD_AUDIO));
    }
    if (!hasPermission(Manifest.permission.RECORD_AUDIO)) {
        if (DEBUG) {
            Log.d(TAG, "Does not have RECORD_AUDIO, using SpeechRecognitionCallback");
        }
        // SpeechRecognitionCallback is not required and if not provided recognition will be
        // handled using internal speech recognizer, in which case you must have RECORD_AUDIO
        // permission
        setSpeechRecognitionCallback(new SpeechRecognitionCallback() {
            @Override
            public void recognizeSpeech() {
                try {
                    startActivityForResult(getRecognizerIntent(), REQUEST_SPEECH);
                } catch (ActivityNotFoundException e) {
                    Log.e(TAG, "Cannot find activity for speech recognizer", e);
                }
            }
        });
    } else if (DEBUG) {
        Log.d(TAG, "We DO have RECORD_AUDIO");
    }
}
项目:AndiCar    文件:StatisticsActivity.java   
private void share() {
    try {
        Intent shareIntent = new Intent(Intent.ACTION_SENDTO);
        shareIntent.setData(Uri.parse("mailto:"));
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, " AndiCar - " + getTitle());
        shareIntent.putExtra(Intent.EXTRA_TEXT,
                mEmailText_Filters.toString().replace("\t", "    ") + "\n\n" +
                        "Data:\n" +
                        mEmailText_Values.toString().replace("\t", "    ") + "\n\nSent by AndiCar (http://www.andicar.org)");
        startActivity(shareIntent);
    }
    catch (ActivityNotFoundException e) {
        Utils.showNotReportableErrorDialog(this, e.getMessage(), null);
    }
}
项目:three-things-today    文件:MainActivity.java   
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.mi_export_database:
            new DatabaseExportTask(this, mThreeThingsDatabase).execute();
            return true;
        case R.id.mi_import_database:
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("*/*");
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            try {
                startActivityForResult(Intent.createChooser(intent, "Select a file to open"),
                        DATABASE_IMPORT_CODE);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getApplicationContext(), "Please install a File Manager",
                        Toast.LENGTH_LONG).show();
            }
            return true;
        case R.id.mi_sign_in_sign_out:
            if (FirebaseAuth.getInstance().getCurrentUser() == null) {
                Intent signInIntent = AuthUI.getInstance().createSignInIntentBuilder()
                        .setProviders(Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()))
                        .build();
                startActivityForResult(signInIntent, FIREBASE_SIGN_IN_CODE);
            } else {
                FirebaseAuth.getInstance().signOut();
                Toast.makeText(this, "Signed out", Toast.LENGTH_SHORT).show();
            }
            return true;
        case R.id.mi_test_notification:
            Intent notificationIntent = new Intent(this, NotificationIntentService.class);
            startService(notificationIntent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
项目:NoticeDog    文件:AppManager.java   
void safeStartActivity(Intent intent) {
    try {
        this.context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.d(TAG, "Failed to start activity");
    }
}
项目:MBEStyle    文件:AboutFragment.java   
private void openUrl(String url) {
    try {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
项目:android-banklink    文件:RequestTest.java   
@Test
public void createIntentWithOldSwedbankAppThrows() {
  try {
    installApp("com.swedbank", 1, SWEDBANK_SIGNATURE);
    final Intent banklinkIntent = eeClient.createBanklinkIntent(SIGNED_PACKET_MAP);
    fail();
  } catch (ActivityNotFoundException e) {
    assertThat(e.getMessage()).isEqualTo("Swedbank app is not installed on this device.");
  }
}
项目:Cable-Android    文件:ConversationActivity.java   
private void handleAddToContacts() {
  try {
    final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
    intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipients.getPrimaryRecipient().getNumber());
    intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
    startActivityForResult(intent, ADD_CONTACT);
  } catch (ActivityNotFoundException e) {
    Log.w(TAG, e);
  }
}