Search in sources :

Example 26 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project Fairphone by Kwamecorp.

the class LauncherTransitionable method onClickVoiceButton.

/**
	 * Event handler for the voice button
	 * 
	 * @param v
	 *            The view that was clicked.
	 */
public void onClickVoiceButton(View v) {
    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
    try {
        final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        ComponentName activityName = searchManager.getGlobalSearchActivity();
        Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (activityName != null) {
            intent.setPackage(activityName.getPackageName());
        }
        startActivity(null, intent, "onClickVoiceButton");
    } catch (ActivityNotFoundException e) {
        Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivitySafely(null, intent, "onClickVoiceButton");
    }
}
Also used : SearchManager(android.app.SearchManager) ActivityNotFoundException(android.content.ActivityNotFoundException) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent)

Example 27 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project Fairphone by Kwamecorp.

the class LauncherTransitionable method startActivityForResultSafely.

void startActivityForResultSafely(Intent intent, int requestCode) {
    ComponentName component = intent != null ? intent.getComponent() : null;
    String packageName = intent != null ? ItemInfo.getPackageName(intent) : "implicit Intent.";
    Log.d(TAG, "Start Activity for Result > " + (component != null ? component.toString() : packageName));
    try {
        startActivityForResult(intent, requestCode);
        if (component != null && (requestCode != REQUEST_CREATE_APPWIDGET && requestCode != REQUEST_BIND_APPWIDGET)) {
            updateActivityInfoViaExplicitIntent(component);
        }
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
    } catch (SecurityException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Launcher does not have the permission to launch " + intent + ". Make sure to create a MAIN intent-filter for the corresponding activity " + "or use the exported attribute for this activity.", e);
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) ComponentName(android.content.ComponentName)

Example 28 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project Fairphone by Kwamecorp.

the class LauncherTransitionable method startGlobalSearch.

/**
	 * Starts the global search activity. This code is a copied from
	 * SearchManager
	 */
public void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity();
    if (globalSearchActivity == null) {
        Log.w(TAG, "No global search activity found.");
        return;
    }
    Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setComponent(globalSearchActivity);
    // Make sure that we have a Bundle to put source in
    if (appSearchData == null) {
        appSearchData = new Bundle();
    } else {
        appSearchData = new Bundle(appSearchData);
    }
    // set already.
    if (!appSearchData.containsKey("source")) {
        appSearchData.putString("source", getPackageName());
    }
    intent.putExtra(SearchManager.APP_DATA, appSearchData);
    if (!TextUtils.isEmpty(initialQuery)) {
        intent.putExtra(SearchManager.QUERY, initialQuery);
    }
    if (selectInitialQuery) {
        intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery);
    }
    intent.setSourceBounds(sourceBounds);
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Global search activity not found: " + globalSearchActivity);
    }
}
Also used : SearchManager(android.app.SearchManager) ActivityNotFoundException(android.content.ActivityNotFoundException) Bundle(android.os.Bundle) ComponentName(android.content.ComponentName) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent)

Example 29 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project 9GAG by Mixiaoxiao.

the class IntentUtil method shareBitmap.

public static void shareBitmap(final Activity context, final Bitmap bitmap, final String chooserDialogTitleString) {
    //		chooserDialogTitleString = "share";
    final Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("image/png");
    //		ByteArrayOutputStream bos = new ByteArrayOutputStream();
    if (bitmap != null) {
        //			bitmap.compress(CompressFormat.PNG, 100, bos);
        //			intent.putExtra(Intent.EXTRA_STREAM, bos.toByteArray());
        //			final ProgressDialog dialog = ProgressDialog.show(context, null, MxxTextUtil.getTypefaceSpannableString(context, "Just wait a moment...",  MxxTextUtil.Roboto_Light, false));
        final Dialog dialog = MxxDialogUtil.creatPorgressDialog(context, null, MxxTextUtil.getTypefaceSpannableString(context, "Just wait a moment...", MxxTextUtil.Roboto_Light, false), false, true, null);
        dialog.show();
        new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                final String imagePath = MxxFileUtil.getCachePath(context) + "/9gag_image_share.png";
                final boolean saved = BitmapUtil.saveBitmapFile(bitmap, imagePath);
                context.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        dialog.dismiss();
                        if (saved) {
                            File f = new File(imagePath);
                            if (f != null && f.exists() && f.isFile()) {
                                Uri u = Uri.fromFile(f);
                                intent.putExtra(Intent.EXTRA_STREAM, u);
                            }
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            try {
                                context.startActivity(Intent.createChooser(intent, MxxTextUtil.getTypefaceSpannableString(context, chooserDialogTitleString, true)));
                            } catch (ActivityNotFoundException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
                });
            }
        }).start();
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) ProgressDialog(android.app.ProgressDialog) Dialog(android.app.Dialog) Intent(android.content.Intent) File(java.io.File) Uri(android.net.Uri)

Example 30 with ActivityNotFoundException

use of android.content.ActivityNotFoundException in project cornerstone by Onskreen.

the class PhoneWindowManager method launchAssistAction.

private void launchAssistAction() {
    sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
    Intent intent = SearchManager.getAssistIntent(mContext);
    if (intent != null) {
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        try {
            mContext.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Slog.w(TAG, "No activity to handle assist action.", e);
        }
    }
}
Also used : ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)384 Intent (android.content.Intent)343 Uri (android.net.Uri)45 View (android.view.View)38 PendingIntent (android.app.PendingIntent)37 RecognizerIntent (android.speech.RecognizerIntent)35 ResolveInfo (android.content.pm.ResolveInfo)33 UserHandle (android.os.UserHandle)28 ComponentName (android.content.ComponentName)24 PackageManager (android.content.pm.PackageManager)23 Bundle (android.os.Bundle)23 ImageView (android.widget.ImageView)23 RemoteException (android.os.RemoteException)22 TextView (android.widget.TextView)22 SearchManager (android.app.SearchManager)20 SearchableInfo (android.app.SearchableInfo)15 File (java.io.File)15 DialogInterface (android.content.DialogInterface)14 AlertDialog (android.app.AlertDialog)13 Context (android.content.Context)13