android.content.ActivityNotFoundException Java Examples

The following examples show how to use android.content.ActivityNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FragmentBuildUriRequest.java    From WMRouter with Apache License 2.0 6 votes vote down vote up
@Override
protected StartFragmentAction getStartFragmentAction() {
    return new StartFragmentAction() {
        @Override
        public boolean startFragment(@NonNull UriRequest request, @NonNull Bundle bundle) throws ActivityNotFoundException, SecurityException {
            String fragmentClassName = request.getStringField(FragmentTransactionHandler.FRAGMENT_CLASS_NAME);
            if (TextUtils.isEmpty(fragmentClassName)) {
                Debugger.fatal("FragmentBuildUriRequest.handleInternal()应返回的带有ClassName");
                return false;
            }
            try {
                Fragment fragment = Fragment.instantiate(request.getContext(), fragmentClassName, bundle);
                if (fragment == null) {
                    return false;
                }
                //自定义处理不做transaction,直接放在request里面回调
                request.putField(FRAGMENT,fragment);
                return true;
            } catch (Exception e) {
                Debugger.e(e);
                return false;
            }
        }
    };
}
 
Example #2
Source File: LauncherHelper.java    From candybar with Apache License 2.0 6 votes vote down vote up
private static void applyEvie(Context context, String launcherPackage, String launcherName) {
    new MaterialDialog.Builder(context)
            .typeface(
                    TypefaceHelper.getMedium(context),
                    TypefaceHelper.getRegular(context))
            .title(launcherName)
            .content(context.getResources().getString(R.string.apply_manual,
                    launcherName,
                    context.getResources().getString(R.string.app_name)) + "\n\n" +
                    context.getResources().getString(R.string.apply_manual_evie,
                            context.getResources().getString(R.string.app_name)))
            .positiveText(android.R.string.ok)
            .onPositive((dialog, which) -> {
                try {
                    final Intent intent = context.getPackageManager().getLaunchIntentForPackage(launcherPackage);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                    context.startActivity(intent);
                    ((AppCompatActivity) context).finish();
                } catch (ActivityNotFoundException | NullPointerException e) {
                    openGooglePlay(context, launcherPackage, launcherName);
                }
            })
            .negativeText(android.R.string.cancel)
            .show();
}
 
Example #3
Source File: VerifyIdentityActivity.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void handleShare(@NonNull Fingerprint fingerprint, int segmentCount) {
  String shareString =
      getString(R.string.VerifyIdentityActivity_our_signal_safety_number) + "\n" +
          getFormattedSafetyNumbers(fingerprint, segmentCount) + "\n";

  Intent intent = new Intent();
  intent.setAction(Intent.ACTION_SEND);
  intent.putExtra(Intent.EXTRA_TEXT, shareString);
  intent.setType("text/plain");

  try {
    startActivity(Intent.createChooser(intent, getString(R.string.VerifyIdentityActivity_share_safety_number_via)));
  } catch (ActivityNotFoundException e) {
    Toast.makeText(getActivity(), R.string.VerifyIdentityActivity_no_app_to_share_to, Toast.LENGTH_LONG).show();
  }
}
 
Example #4
Source File: PageJumpOut.java    From Tok-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * open system file manager
 *
 * @param activity activity
 * @param type file type
 * @param requestCode code
 * @param extraMimeType mimiType must be arrays
 */
private static void select(Activity activity, String type, int requestCode,
    String... extraMimeType) {
    Intent intent = new Intent();
    intent.setType(type);
    intent.putExtra(Intent.EXTRA_MIME_TYPES, extraMimeType);
    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
    try {
        activity.startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException e) {
        intent.setAction(Intent.ACTION_GET_CONTENT);
        try {
            activity.startActivityForResult(intent, requestCode);
        } catch (ActivityNotFoundException e2) {
            e2.printStackTrace();
        }
    }
}
 
Example #5
Source File: PreferenceActivity.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void buildPreferences(@NonNull Context context) {
    MaterialStandardPreference importProfiles = new MaterialStandardPreference(context);
    importProfiles.setTitle(R.string.importProfiles);
    importProfiles.setSummary(R.string.importProfiles_summary);
    addPreference(importProfiles);

    importProfiles.setOnClickListener(v -> {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");

        try {
            startActivityForResult(Intent.createChooser(intent, "Select a file"), IMPORT_PROFILES_CODE);
        } catch (ActivityNotFoundException ex) {
            showToast(Toaster.build().message(R.string.noFilemanager));
        }
    });

    MaterialStandardPreference exportProfiles = new MaterialStandardPreference(context);
    exportProfiles.setTitle(R.string.exportProfiles);
    exportProfiles.setSummary(R.string.exportProfiles_summary);
    addPreference(exportProfiles);

    exportProfiles.setOnClickListener(v -> doExport());
}
 
Example #6
Source File: MainActivity.java    From homeassist with Apache License 2.0 6 votes vote down vote up
private void showWebUI() {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        //builder.setStartAnimations(mActivity, R.anim.right_in, R.anim.left_out);

        builder.setStartAnimations(this, R.anim.activity_open_translate, R.anim.activity_close_scale);
        builder.setExitAnimations(this, R.anim.activity_open_scale, R.anim.activity_close_translate);
        builder.setToolbarColor(ResourcesCompat.getColor(getResources(), R.color.md_blue_500, null));
//        builder.setSecondaryToolbarColor(ResourcesCompat.getColor(getResources(), R.color.md_white_1000, null));
        CustomTabsIntent customTabsIntent = builder.build();

        try {
            customTabsIntent.launchUrl(this, mCurrentServer.getBaseUri());
        } catch (ActivityNotFoundException e) {
            showToast(getString(R.string.exception_no_chrome));
        }
    }
 
Example #7
Source File: LogEntryAdapter.java    From emerald-dialer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(View view) {
	if (view.getId() == R.id.contact_image) {
		String number = (String)view.getTag();
		if (null == number) {
			return;
		}
		Uri contactIdUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
		Cursor cursor = activityRef.get().getContentResolver().query(contactIdUri, new String[] {PhoneLookup.CONTACT_ID}, null, null, null);
		if (cursor == null || !cursor.moveToFirst()) {
			unknownNumberDialog(number);
			return;
		}
		String contactId = cursor.getString(0);
		cursor.close();
		Intent intent = new Intent(Intent.ACTION_VIEW);
		Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, contactId);
		intent.setDataAndType(uri, "vnd.android.cursor.dir/contact");
		try {
			activityRef.get().startActivity(intent);
		} catch (ActivityNotFoundException e) {
			activityRef.get().showMissingContactsAppDialog();
		}
	}
}
 
Example #8
Source File: HashCalculatorFragment.java    From hash-checker with Apache License 2.0 6 votes vote down vote up
private void saveTextFile(@NonNull String filename) {
    try {
        Intent saveTextFileIntent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
        saveTextFileIntent.addCategory(Intent.CATEGORY_OPENABLE);
        saveTextFileIntent.setType("text/plain");
        saveTextFileIntent.putExtra(
                Intent.EXTRA_TITLE,
                filename + ".txt"
        );
        startActivityForResult(
                saveTextFileIntent,
                SettingsHelper.FILE_CREATE
        );
    } catch (ActivityNotFoundException e) {
        L.e(e);
        showSnackbarWithoutAction(
                getString(R.string.message_error_start_file_selector)
        );
    }
}
 
Example #9
Source File: ProxyCameraActivity.java    From DocUIProxy-Android with GNU General Public License v3.0 6 votes vote down vote up
private void processIntentForOthers(@NonNull Intent intent) {
    final ComponentName preferredCamera = Settings.getInstance().getPreferredCamera();
    boolean launched = false;
    if (preferredCamera != null) {
        Log.d(TAG, "Launch preferred camera: " + preferredCamera.toString());
        try {
            onStartCameraApp(preferredCamera);
            launched = true;
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            Settings.getInstance().setPreferredCamera(null);
        }
    }
    if (!launched) {
        CameraChooserDialogFragment
                .newInstance()
                .show(getFragmentManager(), "CameraChooser");
    }
}
 
Example #10
Source File: SpotifyNativeAuthUtil.java    From blade-player with GNU General Public License v3.0 6 votes vote down vote up
public boolean startAuthActivity() {
    Intent intent = createAuthActivityIntent();
    if (intent == null) {
        return false;
    }
    intent.putExtra(EXTRA_VERSION, PROTOCOL_VERSION);

    intent.putExtra(KEY_CLIENT_ID, mRequest.getClientId());
    intent.putExtra(KEY_REDIRECT_URI, mRequest.getRedirectUri());
    intent.putExtra(KEY_RESPONSE_TYPE, mRequest.getResponseType());
    intent.putExtra(KEY_REQUESTED_SCOPES, mRequest.getScopes());

    try {
        mContextActivity.startActivityForResult(intent, LoginActivity.REQUEST_CODE);
    } catch (ActivityNotFoundException e) {
        return false;
    }
    return true;
}
 
Example #11
Source File: SearchView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void onVoiceClicked() {
    // guard against possible race conditions
    if (mSearchable == null) {
        return;
    }
    SearchableInfo searchable = mSearchable;
    try {
        if (searchable.getVoiceSearchLaunchWebSearch()) {
            Intent webSearchIntent = createVoiceWebSearchIntent(mVoiceWebSearchIntent,
                    searchable);
            getContext().startActivity(webSearchIntent);
        } else if (searchable.getVoiceSearchLaunchRecognizer()) {
            Intent appSearchIntent = createVoiceAppSearchIntent(mVoiceAppSearchIntent,
                    searchable);
            getContext().startActivity(appSearchIntent);
        }
    } catch (ActivityNotFoundException e) {
        // Should not happen, since we check the availability of
        // voice search before showing the button. But just in case...
        Log.w(LOG_TAG, "Could not find voice search activity");
    }
}
 
Example #12
Source File: AboutActivity.java    From leafpicrevived with GNU General Public License v3.0 6 votes vote down vote up
@OnClick(R.id.about_link_rate)
public void onRate() {
    Uri uri = Uri.parse(String.format("market://details?id=%s", BuildConfig.APPLICATION_ID));
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    /* To count with Play market backstack, After pressing back button,
     * to taken back to our application, we need to add following flags to intent. */

    int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;

    goToMarket.addFlags(flags);

    try {
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse(String.format("http://play.google.com/store/apps/details?id=%s", BuildConfig.APPLICATION_ID))));
    }
}
 
Example #13
Source File: MainActivity.java    From Intra with Apache License 2.0 6 votes vote down vote up
private boolean prepareVpnService() throws ActivityNotFoundException {
  Intent prepareVpnIntent = null;
  try {
     prepareVpnIntent = VpnService.prepare(this);
  } catch (NullPointerException e) {
    // This exception is not mentioned in the documentation, but it has been encountered by Intra
    // users and also by other developers, e.g. https://stackoverflow.com/questions/45470113.
    LogWrapper.logException(e);
    return false;
  }
  if (prepareVpnIntent != null) {
    Log.i(LOG_TAG, "Prepare VPN with activity");
    startActivityForResult(prepareVpnIntent, REQUEST_CODE_PREPARE_VPN);
    syncDnsStatus();  // Set DNS status to off in case the user does not grant VPN permissions
    return false;
  }
  return true;
}
 
Example #14
Source File: IntentUtils.java    From AcgClub with MIT License 5 votes vote down vote up
/**
 * 跳转到应用市场
 *
 * @param context 上下文
 * @param packageName 应用包名
 * @return 跳转是否成功
 */
public static boolean go2Market(Context context, String packageName) {
  Uri uri = Uri.parse("market://details?id=" + packageName);
  Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
  goToMarket.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  try {
    context.startActivity(goToMarket);
    return true;
  } catch (ActivityNotFoundException e) {
    e.printStackTrace();
    return false;
  }
}
 
Example #15
Source File: GankIoActivity.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * 启动微信二维码扫描页
 * ps: 需要你引导用户从文件中扫描二维码
 *
 * @param activity activity
 */
private static void gotoWeChatQrScan(@NonNull Activity activity) {
    Intent intent = new Intent(TENCENT_ACTIVITY_BIZSHORTCUT);
    intent.setPackage(TENCENT_PACKAGE_NAME);
    intent.putExtra(TENCENT_EXTRA_ACTIVITY_BIZSHORTCUT, true);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
            Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    try {
        activity.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(activity, "安装微信", Toast.LENGTH_SHORT).show();
    }
}
 
Example #16
Source File: ActivityBase.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void startActivity(Intent intent) {
    try {
        super.startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.w(ex);
        ToastEx.makeText(this, getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show();
    }
}
 
Example #17
Source File: Crop.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * Pick image from a support library Fragment with a custom request code
 *
 * @param context     Context
 * @param fragment    Fragment to receive result
 * @param requestCode requestCode for result
 */
public static void pickImage(Context context, android.support.v4.app.Fragment fragment, int requestCode) {
    try {
        fragment.startActivityForResult(getImagePicker(), requestCode);
    } catch (ActivityNotFoundException e) {
        showImagePickerError(context);
    }
}
 
Example #18
Source File: Crop.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * Pick image from an Activity with a custom request code
 *
 * @param activity    Activity to receive result
 * @param requestCode requestCode for result
 */
public static void pickImage(Activity activity, int requestCode) {
    try {
        activity.startActivityForResult(getImagePicker(), requestCode);
    } catch (ActivityNotFoundException e) {
        showImagePickerError(activity);
    }
}
 
Example #19
Source File: Crop.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * Pick image from a Fragment with a custom request code
 *
 * @param context     Context
 * @param fragment    Fragment to receive result
 * @param requestCode requestCode for result
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void pickImage(Context context, Fragment fragment, int requestCode) {
    try {
        fragment.startActivityForResult(getImagePicker(), requestCode);
    } catch (ActivityNotFoundException e) {
        showImagePickerError(context);
    }
}
 
Example #20
Source File: BasePreferenceActivity.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
private static void openLink(@NonNull Context context, @NonNull String uri) {
    try {
        context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uri)));
    } catch (ActivityNotFoundException ex) {
        Toaster.with(context).message(R.string.missingWebBrowser).show();
    }
}
 
Example #21
Source File: FragmentDialogBase.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void startActivity(Intent intent) {
    try {
        super.startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.w(ex);
        ToastEx.makeText(getContext(), getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show();
    }
}
 
Example #22
Source File: CameraActivity.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * Launches an ACTION_EDIT intent for the given local data item. If
 * 'withTinyPlanet' is set, this will show a disambig dialog first to let
 * the user start either the tiny planet editor or another photo editor.
 *
 * @param data The data item to edit.
 */
public void launchEditor(FilmstripItem data)
{
    Intent intent = new Intent(Intent.ACTION_EDIT).setDataAndType(data.getData().getUri(), data.getData()
            .getMimeType()).setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    try
    {
        launchActivityByIntent(intent);
    } catch (ActivityNotFoundException e)
    {
        final String msgEditWith = getResources().getString(R.string.edit_with);
        launchActivityByIntent(Intent.createChooser(intent, msgEditWith));
    }
}
 
Example #23
Source File: HomeScreenActivity.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
public void displaySpeechRecognizer() {
    try {
        startActivityForResult(
                new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
                        .putExtra(
                                RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
                        ),
                SPEECH_REQUEST_CODE);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, S.str(e.getMessage()));
        e.printStackTrace();
        BaldToast.error(this);
    }
}
 
Example #24
Source File: BaseContactsActivity.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
private void displaySpeechRecognizer() {
    try {
        startActivityForResult(
                new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
                        .putExtra(
                                RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
                        ),
                SPEECH_REQUEST_CODE);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, S.str(e.getMessage()));
        e.printStackTrace();
        BaldToast.error(this);
    }
}
 
Example #25
Source File: SingleContactActivity.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
@Override
public void startActivity(Intent intent) {
    try {
        super.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        BaldToast.error(this);
    }
}
 
Example #26
Source File: ScreenRecordActivity.java    From ScreenCapture with MIT License 5 votes vote down vote up
private void viewResult(File file) {
    Intent view = new Intent(Intent.ACTION_VIEW);
    view.addCategory(Intent.CATEGORY_DEFAULT);
    view.setDataAndType(Uri.fromFile(file), "video/*");
    view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {
        startActivity(view);
    } catch (ActivityNotFoundException e) {
        // no activity can open this video
    }
}
 
Example #27
Source File: PageJumpOut.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
private static void create(Activity activity, String type, int requestCode,
    String... extraMimeType) {
    Intent intent = new Intent();
    // intent.setType(type);
    //intent.putExtra(Intent.EXTRA_MIME_TYPES, extraMimeType);
    intent.setAction(Intent.ACTION_OPEN_DOCUMENT_TREE);
    try {
        activity.startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
 
Example #28
Source File: DetailFragment.java    From WanAndroid with Apache License 2.0 5 votes vote down vote up
private void share() {
    try {
        Intent shareIntent = new Intent(Intent.ACTION_SEND).setType("text/plain");
        String shareText = title + " " + url;
        shareIntent.putExtra(Intent.EXTRA_TEXT, shareText);
        startActivity(Intent.createChooser(shareIntent, getString(R.string.detail_share_to)));
    }catch (ActivityNotFoundException e){
        showMessage(R.string.detail_no_activity_found);
    }
}
 
Example #29
Source File: Utils.java    From SmartFlasher with GNU General Public License v3.0 5 votes vote down vote up
public static void launchUrl(String url, Context context) {
    if (Utils.networkUnavailable(context)) {
        Utils.toast(R.string.no_internet, context);
        return;
    }
    try {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        context.startActivity(i);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}
 
Example #30
Source File: FragmentBase.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void startActivityForResult(Intent intent, int requestCode) {
    try {
        super.startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException ex) {
        Log.w(ex);
        ToastEx.makeText(getContext(), getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show();
    }
}