Example usage for android.content ActivityNotFoundException printStackTrace

List of usage examples for android.content ActivityNotFoundException printStackTrace

Introduction

In this page you can find the example usage for android.content ActivityNotFoundException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.jungle.base.utils.MiscUtils.java

public static void rateAppInMarkets(Context context) {
    Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    try {//w  ww. ja  v  a2 s.  com
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.jungle.base.utils.MiscUtils.java

public static boolean callPhoneNumber(Context context, String phoneNumber) {
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {/*w w  w  .j  a v  a  2  s.  co  m*/
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:com.jungle.base.utils.MiscUtils.java

public static boolean dialPhoneNumber(Context context, String phoneNumber) {
    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {//ww  w. j a  v a2  s .  co  m
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:com.jungle.base.utils.MiscUtils.java

public static boolean installApk(Context context, String apkPath) {
    File apkFile = new File(apkPath);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");

    try {//from   w ww . jav  a2s .  c o m
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:com.jungle.base.utils.MiscUtils.java

public static boolean openUrlByBrowser(Context context, String url) {
    if (TextUtils.isEmpty(url)) {
        return false;
    }//from   ww  w  . j  a  v a  2s .c om

    final String HTTP_TAG = "http://";
    url = url.trim();
    if (!URLUtil.isNetworkUrl(url)) {
        url = HTTP_TAG + url;
    }

    try {
        Uri uri = Uri.parse(url);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(uri);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        return false;
    }

    return true;
}

From source file:com.amaze.carbonfilemanager.utils.files.Futils.java

public static void openunknown(File f, Context c, boolean forcechooser) {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);

    String type = MimeTypes.getMimeType(f);
    if (type != null && type.trim().length() != 0 && !type.equals("*/*")) {
        Uri uri = fileToContentUri(c, f);
        if (uri == null)
            uri = Uri.fromFile(f);//  w  w w. ja  v a 2  s  . co m
        intent.setDataAndType(uri, type);
        Intent startintent;
        if (forcechooser)
            startintent = Intent.createChooser(intent, c.getResources().getString(R.string.openwith));
        else
            startintent = intent;
        try {
            c.startActivity(startintent);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show();
            openWith(f, c);
        }
    } else {
        openWith(f, c);
    }

}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

/**
 * Install .apk file.//w w w  . j ava2 s.co  m
 * @param permissionsActivity needed to ask for {@link Manifest.permission#REQUEST_INSTALL_PACKAGES} permission
 */
public static void installApk(final @NonNull File f, final @NonNull PermissionsActivity permissionsActivity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
            && !permissionsActivity.getPackageManager().canRequestPackageInstalls()) {
        permissionsActivity.requestInstallApkPermission(() -> installApk(f, permissionsActivity));
    }

    Intent chooserIntent = new Intent();
    chooserIntent.setAction(Intent.ACTION_INSTALL_PACKAGE);
    chooserIntent.setData(Uri.fromFile(f));

    try {
        permissionsActivity.startActivity(chooserIntent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        Toast.makeText(permissionsActivity, R.string.error, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

/**
 * Open file from OTG/*ww w .  j  av a 2  s.  co  m*/
 */
public static void openunknown(DocumentFile f, Context c, boolean forcechooser, boolean useNewStack) {
    Intent chooserIntent = new Intent();
    chooserIntent.setAction(Intent.ACTION_VIEW);
    chooserIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    String type = f.getType();
    if (type != null && type.trim().length() != 0 && !type.equals("*/*")) {
        chooserIntent.setDataAndType(f.getUri(), type);
        Intent activityIntent;
        if (forcechooser) {
            if (useNewStack)
                applyNewDocFlag(chooserIntent);
            activityIntent = Intent.createChooser(chooserIntent, c.getString(R.string.openwith));
        } else {
            activityIntent = chooserIntent;
            if (useNewStack)
                applyNewDocFlag(chooserIntent);
        }

        try {
            c.startActivity(activityIntent);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show();
            openWith(f, c, useNewStack);
        }
    } else {
        openWith(f, c, useNewStack);
    }
}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

/**
 * Open a file not supported by Amaze/*from ww  w. j av  a  2  s. co m*/
 *
 * @param f the file
 * @param forcechooser force the chooser to show up even when set default by user
 */
public static void openunknown(File f, Context c, boolean forcechooser, boolean useNewStack) {
    Intent chooserIntent = new Intent();
    chooserIntent.setAction(Intent.ACTION_VIEW);

    String type = MimeTypes.getMimeType(f.getPath(), f.isDirectory());
    if (type != null && type.trim().length() != 0 && !type.equals("*/*")) {
        Uri uri = fileToContentUri(c, f);
        if (uri == null)
            uri = Uri.fromFile(f);
        chooserIntent.setDataAndType(uri, type);

        Intent activityIntent;
        if (forcechooser) {
            if (useNewStack)
                applyNewDocFlag(chooserIntent);
            activityIntent = Intent.createChooser(chooserIntent, c.getString(R.string.openwith));
        } else {
            activityIntent = chooserIntent;
            if (useNewStack)
                applyNewDocFlag(activityIntent);
        }

        try {
            c.startActivity(activityIntent);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show();
            openWith(f, c, useNewStack);
        }
    } else {
        // failed to load mime type
        openWith(f, c, useNewStack);
    }
}

From source file:com.tanlet.picture.PictureFragment.java

private void doTakePhotoAction() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
            "annotationDemo" + String.valueOf(System.currentTimeMillis()) + ".jpg"));

    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);

    try {/*  ww  w .j ava2 s  .  c om*/
        intent.putExtra("return-data", false);
        startActivityForResult(intent, 10086);

    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}