Example usage for android.app Activity startActivity

List of usage examples for android.app Activity startActivity

Introduction

In this page you can find the example usage for android.app Activity startActivity.

Prototype

@Override
public void startActivity(Intent intent) 

Source Link

Document

Same as #startActivity(Intent,Bundle) with no options specified.

Usage

From source file:com.android.launcher3.Utilities.java

private static void checkPermissionForRingtone(Activity activity) {
    NotificationManager notificationManager = (NotificationManager) activity.getApplicationContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
            && !notificationManager.isNotificationPolicyAccessGranted()) {

        Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);

        activity.startActivity(intent);
    }// w  w  w . j a v  a  2s.c o m
}

From source file:org.witness.ssc.xfer.utils.PublishingUtils.java

public void launchVideoPlayer(final Activity activity, final String movieurl) {

    try {/* ww  w  .  j ava  2 s  .  c  om*/
        Intent tostart = new Intent(Intent.ACTION_VIEW);
        tostart.setDataAndType(Uri.parse(movieurl), "video/*");
        activity.startActivity(tostart);
    } catch (android.content.ActivityNotFoundException e) {
        Log.e(TAG, " Cant start activity to show video!");

        new AlertDialog.Builder(activity).setMessage(R.string.cant_show_video)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                    }
                })

                .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                    }
                }).show();

        return;
    }

}

From source file:com.vuze.android.remote.SessionInfo.java

public static void showUrlFailedDialog(final Activity activity, final String errMsg, final String url,
        final String sample) {
    if (activity == null) {
        Log.e(null, "No activity for error message " + errMsg);
        return;/*from w w w .j a  v a 2  s . c  om*/
    }
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (activity.isFinishing()) {
                return;
            }
            String s = activity.getResources().getString(R.string.torrent_url_add_failed, url, sample);

            Spanned msg = Html.fromHtml(s);
            Builder builder = new AlertDialog.Builder(activity).setMessage(msg).setCancelable(true)
                    .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    }).setNeutralButton(R.string.torrent_url_add_failed_openurl, new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                            activity.startActivity(intent);
                        }
                    });
            builder.show();
        }
    });

}

From source file:com.scoreflex.Scoreflex.java

protected static void showView(Activity activity, String resource, Scoreflex.RequestParams params,
        boolean useActivityForViews) {
    if (useActivityForViews) {
        Intent intent = new Intent(activity, ScoreflexActivity.class);
        intent.putExtra(ScoreflexActivity.INTENT_SHOW_EXTRA_KEY,
                ScoreflexActivity.INTENT_EXTRA_SHOW_FULLSCREEN_VIEW);
        intent.putExtra(ScoreflexActivity.INTENT_EXTRA_FULLSCREEN_RESOURCE, resource);
        intent.putExtra(ScoreflexActivity.INTENT_EXTRA_REQUEST_PARAMS_KEY, params);
        activity.startActivity(intent);
    } else {//w  w w .  java 2  s.  c  o  m
        showFullScreenView(activity, resource, params);
    }
}

From source file:au.com.infiniterecursion.vidiom.utils.PublishingUtils.java

public void launchVideoPlayer(final Activity activity, final String moviePath) {

    try {//from  w  w w . j av  a  2 s.  com
        Intent tostart = new Intent(Intent.ACTION_VIEW);
        tostart.setDataAndType(Uri.parse("file://" + moviePath), "video/*");
        activity.startActivity(tostart);
    } catch (android.content.ActivityNotFoundException e) {
        Log.e(TAG, " Cant start activity to show video!");

        e.printStackTrace();

        new AlertDialog.Builder(activity).setMessage(R.string.cant_show_video)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                    }
                }).show();

        return;
    }

}

From source file:com.jtechme.apphub.FDroidApp.java

public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
    if (resultCode == Activity.RESULT_CANCELED)
        return;/*from   w  w  w .j  av a  2  s  .c  om*/
    String bluetoothPackageName = null;
    String className = null;
    boolean found = false;
    Intent sendBt = null;
    try {
        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        sendBt = new Intent(Intent.ACTION_SEND);
        // The APK type is blocked by stock Android, so use zip
        // sendBt.setType("application/vnd.android.package-archive");
        sendBt.setType("application/zip");
        sendBt.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + appInfo.publicSourceDir));
        // not all devices have the same Bluetooth Activities, so
        // let's find it
        for (ResolveInfo info : pm.queryIntentActivities(sendBt, 0)) {
            bluetoothPackageName = info.activityInfo.packageName;
            if ("com.android.bluetooth".equals(bluetoothPackageName)
                    || "com.mediatek.bluetooth".equals(bluetoothPackageName)) {
                className = info.activityInfo.name;
                found = true;
                break;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Could not get application info to send via bluetooth", e);
        found = false;
    }
    if (sendBt != null) {
        if (found) {
            sendBt.setClassName(bluetoothPackageName, className);
            activity.startActivity(sendBt);
        } else {
            Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show();
            activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send)));
        }
    }
}

From source file:com.mobicage.rogerthat.plugins.history.HistoryListAdapter.java

void startItemDetailActivity(Activity activity, HistoryItem item) {
    T.UI();//from w w  w.  j  av a 2 s. c  o  m
    switch (item.type) {

    case HistoryItem.MESSAGE_SENT:
    case HistoryItem.MESSAGE_RECEIVED:
    case HistoryItem.QUICK_REPLY_RECEIVED_FOR_ME:
    case HistoryItem.QUICK_REPLY_RECEIVED_FOR_OTHER:
    case HistoryItem.QUICK_REPLY_SENT_FOR_ME:
    case HistoryItem.QUICK_REPLY_SENT_FOR_OTHER:
    case HistoryItem.QUICK_REPLY_UNDONE:
    case HistoryItem.MESSAGE_LOCKED_BY_ME:
    case HistoryItem.MESSAGE_LOCKED_BY_OTHER:
    case HistoryItem.MESSAGE_DISMISSED_BY_ME:
    case HistoryItem.MESSAGE_DISMISSED_BY_OTHER: {
        Message message = getMessage(item.reference);
        mMessagingPlugin.showMessage(activity, message, message.sender);
        break;
    }

    case HistoryItem.REPLY_SENT:
    case HistoryItem.REPLY_RECEIVED: {
        // Show message thread scrolled to this offset
        Message message = getMessage(item.reference);
        mMessagingPlugin.showMessage(activity, message, message.sender);
        break;
    }

    case HistoryItem.SERVICE_POKED:
    case HistoryItem.FRIEND_ADDED:
    case HistoryItem.FRIEND_UPDATED:
    case HistoryItem.LOCATION_SHARING_MY_LOCATION_SENT: {
        mFriendsPlugin.launchDetailActivity(activity, item.reference);
        break;
    }

    case HistoryItem.FRIEND_BECAME_FRIEND: {
        final Intent intent = new Intent(activity, ProcessScanActivity.class);
        intent.putExtra(ProcessScanActivity.EMAILHASH, item.reference);
        activity.startActivity(intent);
        break;
    }

    case HistoryItem.FRIEND_REMOVED:
    case HistoryItem.DEBUG:
    case HistoryItem.INFO:
    case HistoryItem.WARNING:
    case HistoryItem.ERROR:
    case HistoryItem.FATAL: {
        // do nothing
        break;
    }

    default: {
        L.bug("History item detail requested for unknown item type " + item.type);
    }

    }
}

From source file:au.com.infiniterecursion.vidiom.utils.PublishingUtils.java

public void launchEmailIntentWithCurrentVideo(final Activity activity,
        final String latestVideoFile_absolutepath) {
    Log.d(TAG, "launchEmailIntentWithCurrentVideo starting");

    Intent i = new Intent(Intent.ACTION_SEND);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // XXX hardcoded video mimetype
    i.setType("video/mp4");
    i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + latestVideoFile_absolutepath));
    activity.startActivity(i);
}

From source file:com.amaze.filemanager.fragments.MainFragment.java

public static void launchSMB(final HybridFileParcelable baseFile, final Activity activity) {
    final Streamer s = Streamer.getInstance();
    new Thread() {
        public void run() {
            try {
                /*//from   www  .ja v a 2s. c  o  m
                List<SmbFile> subtitleFiles = new ArrayList<SmbFile>();
                        
                // finding subtitles
                for (Layoutelements layoutelement : LIST_ELEMENTS) {
                SmbFile smbFile = new SmbFile(layoutelement.getDesc());
                if (smbFile.getName().contains(smbFile.getName())) subtitleFiles.add(smbFile);
                }
                */

                s.setStreamSrc(new SmbFile(baseFile.getPath()), baseFile.getSize());
                activity.runOnUiThread(() -> {
                    try {
                        Uri uri = Uri.parse(Streamer.URL + Uri
                                .fromFile(new File(Uri.parse(baseFile.getPath()).getPath())).getEncodedPath());
                        Intent i = new Intent(Intent.ACTION_VIEW);
                        i.setDataAndType(uri,
                                MimeTypes.getMimeType(baseFile.getPath(), baseFile.isDirectory()));
                        PackageManager packageManager = activity.getPackageManager();
                        List<ResolveInfo> resInfos = packageManager.queryIntentActivities(i, 0);
                        if (resInfos != null && resInfos.size() > 0)
                            activity.startActivity(i);
                        else
                            Toast.makeText(activity,
                                    activity.getResources().getString(R.string.smb_launch_error),
                                    Toast.LENGTH_SHORT).show();
                    } catch (ActivityNotFoundException e) {
                        e.printStackTrace();
                    }
                });

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
}

From source file:com.smartnsoft.droid4me.app.ActivityController.java

/**
 * Indicates whether a redirection is required before letting the activity continue its life cycle. It launches the redirected {@link Activity} if a
 * redirection is need, and provide to its {@link Intent} the initial activity {@link Intent} trough the extra {@link Parcelable}
 * {@link ActivityController#CALLING_INTENT} key.
 * //from   w w  w.j  a  va 2 s.c  o m
 * <p>
 * If the provided {@code activity} implements the {@link ActivityController.EscapeToRedirector} interface or exposes the
 * {@link ActivityController.EscapeToRedirectorAnnotation} annotation, the method returns {@code false}.
 * </p>
 * 
 * <p>
 * Note that this method does not need to be marked as {@code synchronized}, because it is supposed to be invoked systematically from the UI thread.
 * </p>
 * 
 * @param activity
 *          the activity which is being proved against the {@link ActivityController.Redirector}
 * @return {@code true} if and only if the given activity should be paused (or ended) and if another activity should be launched instead through the
 *         {@link Activity#startActivity(Intent)} method
 * @see ActivityController#extractCallingIntent(Activity)
 * @see ActivityController.Redirector#getRedirection(Activity)
 * @see ActivityController.EscapeToRedirector
 * @see ActivityController.EscapeToRedirectorAnnotation
 */
public boolean needsRedirection(Activity activity) {
    if (redirector == null) {
        return false;
    }
    if (activity instanceof ActivityController.EscapeToRedirector || activity.getClass()
            .getAnnotation(ActivityController.EscapeToRedirectorAnnotation.class) != null) {
        if (log.isDebugEnabled()) {
            log.debug("The Activity with class '" + activity.getClass().getName()
                    + "' is escaped regarding the Redirector");
        }
        return false;
    }
    final Intent intent = redirector.getRedirection(activity);
    if (intent == null) {
        return false;
    }
    if (log.isDebugEnabled()) {
        log.debug("A redirection is needed");
    }

    // We redirect to the right Activity
    {
        // We consider the parent activity in case it is embedded (like in an ActivityGroup)
        final Intent formerIntent = activity.getParent() != null ? activity.getParent().getIntent()
                : activity.getIntent();
        intent.putExtra(ActivityController.CALLING_INTENT, formerIntent);
        // Disables the fact that the new started activity should belong to the tasks history and from the recent tasks
        // intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        // intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        activity.startActivity(intent);
    }

    // We now finish the redirected Activity
    activity.finish();

    return true;
}