Java Code Examples for android.content.Intent#setAction()

The following examples show how to use android.content.Intent#setAction() . 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: AppInfoUtils.java    From Bailan with Apache License 2.0 6 votes vote down vote up
public static void showInstalledAppDetails(Context context, String packageName) {
    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;
    if (apiLevel >= 9) { // 2.3(ApiLevel 9)以上,使用SDK提供的接口
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
        intent.setData(uri);
    } else { // 2.3以下,使用非公开的接口(查看InstalledAppDetails源码)
        // 2.2和2.1中,InstalledAppDetails使用的APP_PKG_NAME不同。
        final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22
                : APP_PKG_NAME_21);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName(APP_DETAILS_PACKAGE_NAME,
                APP_DETAILS_CLASS_NAME);
        intent.putExtra(appPkgName, packageName);
    }
    context.startActivity(intent);
}
 
Example 2
Source File: MainActivity.java    From InviZible with GNU General Public License v3.0 6 votes vote down vote up
private void checkUpdates() {

        if (appVersion.equals("gp") || appVersion.equals("fd")) {
            return;
        }

        Intent intent = getIntent();
        if (Objects.equals(intent.getAction(), "check_update")) {
            if (topFragment != null) {
                topFragment.checkNewVer();
                modernDialog = modernProgressDialog();
            }

            intent.setAction(null);
            setIntent(intent);
        }
    }
 
Example 3
Source File: RhythmNotificationService.java    From Rhythm with Apache License 2.0 6 votes vote down vote up
private NotificationCompat.Builder makeCommonNotification(String text) {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.arl_rhythm)
            .setCategory(NotificationCompat.CATEGORY_SERVICE)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setAutoCancel(false)
            .setShowWhen(false)
            .setContentText(text)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(text));

    // Old androids throw an exception when the notification doesn't have content intent
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        Intent contentAction = new Intent(this, RhythmNotificationService.class);
        contentAction.setAction(ACTION_NEXT_OVERLAY);
        PendingIntent piContentAction = PendingIntent.getService(this, 0, contentAction, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(piContentAction);
    }

    return builder;
}
 
Example 4
Source File: ActivityInvokeAPI.java    From Simpler with Apache License 2.0 5 votes vote down vote up
/**
 * 打开某条微博正文。
 * 
 * @param activity
 * @param blogId 某条微博id
 */
public static void openDetail(Activity activity,String blogId){
    if(activity==null){
        return;
    }
    Intent intent=new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setData(Uri.parse("sinaweibo://detail?mblogid="+blogId));
    activity.startActivity(intent);
}
 
Example 5
Source File: FeedActivity.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
    Intent intent = new Intent(this, PostActivity.class);
    intent.setAction(PostActivity.ACTION_POST);
    intent.putExtra(PostActivity.KEY_POST, mFeedHelper.getDataAt(position));
    startActivity(intent);
    return true;
}
 
Example 6
Source File: HomeFragment.java    From ClassSchedule with Apache License 2.0 5 votes vote down vote up
/**
 * QQ反馈
 */
public void qqFeedback() {
    if (!QQIsAvailable()) {
        showMassage(getString(R.string.qq_not_installed));
        return;
    }
    String url1 = "mqqwpa://im/chat?chat_type=wpa&uin=" + getString(R.string.qq_number);
    Intent i1 = new Intent(Intent.ACTION_VIEW, Uri.parse(url1));
    i1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i1.setAction(Intent.ACTION_VIEW);
    if (getContext() != null && getContext().getApplicationContext() != null) {
        getContext().getApplicationContext().startActivity(i1);
    }
}
 
Example 7
Source File: AppListActivity.java    From product-emm with Apache License 2.0 5 votes vote down vote up
/**
 * Load device home screen.
 */
private void loadHomeScreen() {
    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    this.startActivity(i);
    super.onBackPressed();
}
 
Example 8
Source File: VAccountManagerService.java    From container with GNU General Public License v3.0 5 votes vote down vote up
void bind() {
	Log.v(TAG, "initiating bind to authenticator type " + mAuthenticatorInfo.desc.type);
	Intent intent = new Intent();
	intent.setAction(AccountManager.ACTION_AUTHENTICATOR_INTENT);
	intent.setClassName(mAuthenticatorInfo.serviceInfo.packageName, mAuthenticatorInfo.serviceInfo.name);
	intent.putExtra("_VA_|_user_id_", mUserId);

	if (!mContext.bindService(intent, this, Context.BIND_AUTO_CREATE)) {
		Log.d(TAG, "bind attempt failed for " + toDebugString());
		onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, "bind failure");
	}
}
 
Example 9
Source File: ModulesKiller.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private static void sendStopIntent(Context context, String action) {
    Intent intent = new Intent(context, ModulesService.class);
    intent.setAction(action);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        intent.putExtra("showNotification", true);
        context.startForegroundService(intent);
    } else {
        intent.putExtra("showNotification", isShowNotification(context));
        context.startService(intent);
    }
}
 
Example 10
Source File: MainActivity.java    From XposedWechatHelper with GNU General Public License v2.0 5 votes vote down vote up
private void sendURLIntent(String url) {
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    Uri contentUrl = Uri.parse(url);
    intent.setData(contentUrl);
    startActivity(intent);
}
 
Example 11
Source File: Utils.java    From android-utils with MIT License 5 votes vote down vote up
/**
 * @param ctx
 * @param savingUri
 * @param durationInSeconds
 * @return
 * @deprecated Use {@link MediaUtils#createTakeVideoIntent(Activity, Uri, int)}
 * Creates an intent to take a video from camera or gallery or any other application that can
 * handle the intent.
 */
public static Intent createTakeVideoIntent(Activity ctx, Uri savingUri, int durationInSeconds) {

    if (savingUri == null) {
        throw new NullPointerException("Uri cannot be null");
    }

    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    final PackageManager packageManager = ctx.getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, savingUri);
        intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationInSeconds);
        cameraIntents.add(intent);
    }

    // Filesystem.
    final Intent galleryIntent = new Intent();
    galleryIntent.setType("video/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    // Chooser of filesystem options.
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");

    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));

    return chooserIntent;
}
 
Example 12
Source File: UnknownErrorDialog.java    From PowerSwitch_Android with GNU General Public License v3.0 5 votes vote down vote up
private void reportExceptionViaMail() throws Exception {
    Intent emailIntent = new Intent();
    emailIntent.setAction(Intent.ACTION_SENDTO);
    emailIntent.setType("*/*");
    emailIntent.setData(Uri.parse("mailto:")); // only email apps should handle this
    emailIntent.putExtra(Intent.EXTRA_EMAIL, DEFAULT_EMAILS);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Unknown Error - " + throwable.getClass().getSimpleName() +
            ": " + throwable.getMessage());
    emailIntent.putExtra(Intent.EXTRA_TEXT, getEmailContentText());
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(LogHandler.getLogsAsZip(this)));

    startActivity(Intent.createChooser(emailIntent, getString(R.string.send_to)));
}
 
Example 13
Source File: MyWidgetProviderSimple.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
		int[] appWidgetIds) {
	// TODO 0 Make it possible to add the simple widget to the homescreen
	// via Android Manifest

	// TODO 1 Get the component name for MyWidgetProviderSimple.class
	// instead of Void.class
	ComponentName thisWidget = new ComponentName(context, Void.class);
	int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
	for (int widgetId : allWidgetIds) {
		// Create some random data
		int number = (new Random().nextInt(100));

		// TODO 2 Use widgetsimple_layout.xml as layout instead of -1
		RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
				-1);
		Log.w("WidgetExample", String.valueOf(number));
		// TODO 3 Set the text to the view with the id R.id.update
		// instead of -1
		remoteViews.setTextViewText(-1, String.valueOf(number));

		// Register an onClickListener
		Intent intent = new Intent(context, MyWidgetProviderSimple.class);

		intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
		intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

		PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
				0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
		// TODO 4 Add pending intent to the text view with the id
		// R.id.update
		// remoteViews.setOnClickPendingIntent();

		appWidgetManager.updateAppWidget(widgetId, remoteViews);
	}
}
 
Example 14
Source File: SampleDownloaderActivity.java    From play-apk-expansion with Apache License 2.0 5 votes vote down vote up
private void launchDownloader() {
    try {
        Intent launchIntent = SampleDownloaderActivity.this
                .getIntent();
        Intent intentToLaunchThisActivityFromNotification = new Intent(
                SampleDownloaderActivity
                        .this, SampleDownloaderActivity.this.getClass());
        intentToLaunchThisActivityFromNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                |
                Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intentToLaunchThisActivityFromNotification.setAction(launchIntent.getAction());

        if (launchIntent.getCategories() != null) {
            for (String category : launchIntent.getCategories()) {
                intentToLaunchThisActivityFromNotification.addCategory(category);
            }
        }

        if (DownloaderClientMarshaller.startDownloadServiceIfRequired(this,
                PendingIntent.getActivity(SampleDownloaderActivity
                                .this,
                        0, intentToLaunchThisActivityFromNotification,
                        PendingIntent.FLAG_UPDATE_CURRENT),
                SampleDownloaderService.class) != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
            initializeDownloadUI();
            return;
        } // otherwise we fall through to starting the movie
    } catch (NameNotFoundException e) {
        Log.e(LOG_TAG, "Cannot find own package! MAYDAY!");
        e.printStackTrace();
    }
}
 
Example 15
Source File: IRCService.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
public static void start(Context context) {
    Intent intent = new Intent(context, IRCService.class);
    intent.setAction(ACTION_START_FOREGROUND);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        context.startForegroundService(intent);
    else
        context.startService(intent);
}
 
Example 16
Source File: InstanceIDService.java    From gcm-android-client with Apache License 2.0 5 votes vote down vote up
/**
 * Called if InstanceID token is updated. This may occur if the security of
 * the previous token had been compromised. This call is initiated by the
 * InstanceID provider.
 */
@Override
public void onTokenRefresh() {
  // Fetch updated Instance ID token and notify our app's server of any changes (if applicable).
  Intent intent = new Intent(this, RegistrationIntentService.class);
  intent.setAction(RegistrationIntentService.ACTION_REGISTER);
  startService(intent);
}
 
Example 17
Source File: WidgetProvider.java    From OmniList with GNU Affero General Public License v3.0 4 votes vote down vote up
private PendingIntent pendingIntentLaunchApp(Context context, int widgetId) {
    Intent intentLaunchApp = new Intent(context, MainActivity.class);
    intentLaunchApp.setAction(Constants.ACTION_WIDGET_LAUNCH_APP);
    intentLaunchApp.putExtra(Constants.INTENT_WIDGET, widgetId);
    return PendingIntent.getActivity(context, widgetId, intentLaunchApp, PendingIntent.FLAG_CANCEL_CURRENT);
}
 
Example 18
Source File: MusicService.java    From Muzesto with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    if (D) Log.d(TAG, "Creating service");
    super.onCreate();

    mNotificationManager = NotificationManagerCompat.from(this);

    // gets a pointer to the playback state store
    mPlaybackStateStore = MusicPlaybackState.getInstance(this);
    mSongPlayCount = SongPlayCount.getInstance(this);
    mRecentStore = RecentStore.getInstance(this);


    mHandlerThread = new HandlerThread("MusicPlayerHandler",
            android.os.Process.THREAD_PRIORITY_BACKGROUND);
    mHandlerThread.start();


    mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper());


    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mMediaButtonReceiverComponent = new ComponentName(getPackageName(),
            MediaButtonIntentReceiver.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        setUpMediaSession();

    mPreferences = getSharedPreferences("Service", 0);
    mCardId = getCardId();

    registerExternalStorageListener();

    mPlayer = new MultiPlayer(this);
    mPlayer.setHandler(mPlayerHandler);

    // Initialize the intent filter and each action
    final IntentFilter filter = new IntentFilter();
    filter.addAction(SERVICECMD);
    filter.addAction(TOGGLEPAUSE_ACTION);
    filter.addAction(PAUSE_ACTION);
    filter.addAction(STOP_ACTION);
    filter.addAction(NEXT_ACTION);
    filter.addAction(PREVIOUS_ACTION);
    filter.addAction(PREVIOUS_FORCE_ACTION);
    filter.addAction(REPEAT_ACTION);
    filter.addAction(SHUFFLE_ACTION);
    // Attach the broadcast listener
    registerReceiver(mIntentReceiver, filter);

    mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler);
    getContentResolver().registerContentObserver(
            MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver);
    getContentResolver().registerContentObserver(
            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver);

    // Initialize the wake lock
    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
    mWakeLock.setReferenceCounted(false);


    final Intent shutdownIntent = new Intent(this, MusicService.class);
    shutdownIntent.setAction(SHUTDOWN);

    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0);

    scheduleDelayedShutdown();

    reloadQueueAfterPermissionCheck();
    notifyChange(QUEUE_CHANGED);
    notifyChange(META_CHANGED);
}
 
Example 19
Source File: UnlockActivity.java    From Hentoid with Apache License 2.0 3 votes vote down vote up
/**
 * Creates an intent that launches this activity before launching the given wrapped intent
 *
 * @param context           used for creating the return intent
 * @param destinationIntent intent that refers to the next activity
 * @return intent that launches this activity which leads to another activity referred to by
 * {@code destinationIntent}
 */
public static Intent wrapIntent(Context context, Intent destinationIntent) {
    Intent intent = new Intent(context, UnlockActivity.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.putExtra(EXTRA_INTENT, destinationIntent);
    return intent;
}
 
Example 20
Source File: ArticleContentActivity.java    From CrimeTalk-Reader with Apache License 2.0 2 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    final ArticleListItem articleListItem = getIntent().getExtras().getParcelable(ArticleContentActivity.ARG_LIST_ITEM);

    switch (item.getItemId()) {

        case android.R.id.home:

            this.finish();

            return true;

        case R.id.action_share:

            final Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.check_out_article));
            shareIntent.putExtra(Intent.EXTRA_TEXT, articleListItem.getLink());
            shareIntent.setType("text/plain");
            startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_via)));

            return true;

        case R.id.action_browser:

            final Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(articleListItem.getLink()));
            startActivity(intent);

            return true;

        case R.id.action_clipboard:

            final ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            final ClipData clipData = ClipData.newPlainText("article", String.format(getResources()
                    .getString(R.string.clipboard_article), articleListItem.getTitle(), articleListItem.getAuthor(), articleListItem.getLink()));
            clipboard.setPrimaryClip(clipData);

            SuperActivityToast.create(this, getResources().getString(R.string.clipboard_toast),
                    SuperToast.Duration.SHORT, Style.getStyle(Style.RED)).show();

            return true;

    }

    return false;

}