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

The following examples show how to use android.content.Intent#setFlags() . 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: CommonUtil.java    From QuickNote with Apache License 2.0 6 votes vote down vote up
public static void shareApp(Context context, boolean isShareAppIcon) {
    String shareAppTip = QuickNote.getString(R.string.share_app_content);
    if (isShareAppIcon) {
        new File(context.getFilesDir(), SHARE_APP_IMAGE).deleteOnExit();
        try {
            FileOutputStream fos = context.openFileOutput(SHARE_APP_IMAGE, Context.MODE_WORLD_READABLE);
            Bitmap pic = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_app);
            pic.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    Intent intent = new Intent("android.intent.action.SEND");
    intent.setType("image/*");
    intent.putExtra("sms_body", shareAppTip);
    intent.putExtra("android.intent.extra.TEXT", shareAppTip);
    if (isShareAppIcon) {
        File shareImage = new File(context.getFilesDir(), SHARE_APP_IMAGE);
        if (shareImage.exists()) {
            intent.putExtra("android.intent.extra.STREAM", Uri.fromFile(shareImage));
        }
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(Intent.createChooser(intent, QuickNote.getString(R.string.share_app_title)));
}
 
Example 2
Source File: DomainActivity.java    From BotLibre with Eclipse Public License 1.0 6 votes vote down vote up
public void browse(View view) {
	MainActivity.type = MainActivity.defaultType;
	
	MainActivity.connection.setDomain((DomainConfig)MainActivity.instance);
	MainActivity.domain = (DomainConfig)MainActivity.instance;
	MainActivity.tags = null;
	MainActivity.categories = null;
	MainActivity.forumTags = null;
	MainActivity.forumCategories = null;
	MainActivity.channelTags = null;
	MainActivity.channelCategories = null;
	MainActivity.avatarTags = null;
	MainActivity.avatarCategories = null;
	MainActivity.scriptTags = null;
	MainActivity.scriptCategories = null;
	
       Intent intent = new Intent(this, MainActivity.class);
	intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
       startActivity(intent);
}
 
Example 3
Source File: CheckUpdateTask.java    From fingerpoetry-android with Apache License 2.0 6 votes vote down vote up
/**
 * Show Notification
 */
private void showNotification(Context context, String content, String apkUrl) {
    Intent myIntent = new Intent(context, DownloadService.class);
    myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    myIntent.putExtra(Constants.APK_DOWNLOAD_URL, apkUrl);
    PendingIntent pendingIntent = PendingIntent.getService(context, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    int smallIcon = context.getApplicationInfo().icon;
    Notification notify = new NotificationCompat.Builder(context)
            .setTicker(context.getString(R.string.android_auto_update_notify_ticker))
            .setContentTitle(context.getString(R.string.android_auto_update_notify_content))
            .setContentText(content)
            .setSmallIcon(smallIcon)
            .setContentIntent(pendingIntent).build();

    notify.flags = Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notify);
}
 
Example 4
Source File: NotificationDisplay.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onClick(View v) {
    // The user has confirmed this notification, so remove it.
    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
            .cancel(R.layout.status_bar_notifications);
    
    // Pressing on the button brings the user back to our mood ring,
    // as part of the api demos app.  Note the use of NEW_TASK here,
    // since the notification display activity is run as a separate task.
    Intent intent = new Intent(this, StatusBarNotifications.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    
    // We're done.
    finish();
}
 
Example 5
Source File: MainActivity.java    From dex-hdog with MIT License 6 votes vote down vote up
private void openApp(String packageName) {
    PackageManager pm = this.getPackageManager();
    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
    resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resolveIntent.setPackage(packageName);

    List<ResolveInfo> apps = pm.queryIntentActivities(resolveIntent, 0);
    for (ResolveInfo app : apps) {
        if (packageName.equals(app.activityInfo.packageName)) {
            String className = app.activityInfo.name;
            ComponentName cn = new ComponentName(packageName, className);
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setComponent(cn);
            startActivity(intent);
        }
    }
}
 
Example 6
Source File: ShareUtil.java    From Gank.io with GNU General Public License v3.0 5 votes vote down vote up
public static void shareImage(Context context, Uri uri, String title) {
  Intent shareIntent = new Intent();
  shareIntent.setAction(Intent.ACTION_SEND);
  shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
  shareIntent.setType("image/jpeg");
  shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  context.startActivity(Intent.createChooser(shareIntent, title));
}
 
Example 7
Source File: TransferTicketDetailRouter.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
public void openTransfer(Context context, Token token, String ticketIDs, Wallet wallet, int state) {
    Intent intent = new Intent(context, TransferTicketDetailActivity.class);
    intent.putExtra(C.Key.WALLET, wallet);
    intent.putExtra(C.Key.TICKET, token);
    intent.putExtra(C.EXTRA_TOKENID_LIST, ticketIDs);
    intent.putExtra(C.EXTRA_STATE, state);
    intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    context.startActivity(intent);
}
 
Example 8
Source File: DemoActivity.java    From matomo-sdk-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 9
Source File: OnboardingActivity.java    From ResearchStack with Apache License 2.0 5 votes vote down vote up
private void startMainActivity() {
    // Onboarding completion is checked in splash activity. The check allows us to pass through
    // to MainActivity even if we haven't signed in. We want to set this true in every case so
    // the user is really only forced through Onboarding once. If they leave the study, they must
    // re-enroll in Settings, which starts OnboardingActivty.
    AppPrefs.getInstance(this).setOnboardingComplete(true);

    // Start MainActivity w/ clear_top and single_top flags. MainActivity may
    // already be on the activity-task. We want to re-use that activity instead
    // of creating a new instance and have two instance active.
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(intent);
    finish();
}
 
Example 10
Source File: SyncActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void startMain() {
    getSharedPreferences().edit().putBoolean(Preference.INITIAL_SYNC_DONE, true).apply();
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    finish();
}
 
Example 11
Source File: App.java    From alipay-master with GNU General Public License v3.0 5 votes vote down vote up
public static void dealAlipayCookieStr(Context context, Intent intent) {
    String cookieStr = intent.getStringExtra("cookieStr");
    String toastString = cookieStr;
    Log.i("liunianprint:", toastString);
    Toast.makeText(context, toastString, Toast.LENGTH_SHORT).show();
    Intent startIntent = new Intent(context, MainActivity.class);
    startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(startIntent);
}
 
Example 12
Source File: MediaNotificationManager.java    From LyricHere with Apache License 2.0 5 votes vote down vote up
private PendingIntent createContentIntent(MediaDescriptionCompat description) {
    Intent openUI = new Intent(mService, MusicPlayerActivity.class);
    openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    openUI.putExtra(MusicPlayerActivity.EXTRA_START_FULLSCREEN, true);
    if (description != null) {
        openUI.putExtra(MusicPlayerActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, description);
    }
    return PendingIntent.getActivity(mService, REQUEST_CODE, openUI,
            PendingIntent.FLAG_CANCEL_CURRENT);
}
 
Example 13
Source File: MainActivity.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onMediaClick(Album album, ArrayList<Media> media, int position) {

    if (!pickMode) {
        Intent intent = new Intent(getApplicationContext(), SingleMediaActivity.class);
        intent.putExtra(SingleMediaActivity.EXTRA_ARGS_ALBUM, album);
        try {
            intent.setAction(SingleMediaActivity.ACTION_OPEN_ALBUM);
            intent.putExtra(SingleMediaActivity.EXTRA_ARGS_MEDIA, media);
            intent.putExtra(SingleMediaActivity.EXTRA_ARGS_POSITION, position);
            startActivity(intent);
        } catch (Exception e) { // Putting too much data into the Bundle
            // TODO: Find a better way to pass data between the activities - possibly a key to
            // access a HashMap or a unique value of a singleton Data Repository of some sort.
            intent.setAction(SingleMediaActivity.ACTION_OPEN_ALBUM_LAZY);
            intent.putExtra(SingleMediaActivity.EXTRA_ARGS_MEDIA, media.get(position));
            startActivity(intent);
        }

    } else {

        Media m = media.get(position);
        Uri uri = LegacyCompatFileProvider.getUri(getApplicationContext(), m.getFile());
        Intent res = new Intent();
        res.setData(uri);
        res.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        setResult(RESULT_OK, res);
        finish();
    }
}
 
Example 14
Source File: AlarmReceiver.java    From Birdays with Apache License 2.0 5 votes vote down vote up
/**
 * Creates intent to open DetailActivity on notification click
 */
private Intent getResultIntent(Context context, long timeStamp, Intent intent) {
    Intent resultIntent = new Intent(context, DetailActivity.class);
    resultIntent.putExtra(Constants.TIME_STAMP, timeStamp);
    if (BirdaysApplication.isActivityVisible()) {
        resultIntent = intent;
    }
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return resultIntent;
}
 
Example 15
Source File: AlarmNotifications.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
public static Intent getAlarmListIntent(Context context, Long selectedAlarmId)
{
    Intent intent = new Intent(context, AlarmClockActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (selectedAlarmId != null) {
        intent.setData(ContentUris.withAppendedId(AlarmClockItem.CONTENT_URI, selectedAlarmId));
        intent.putExtra(AlarmClockActivity.EXTRA_SELECTED_ALARM, selectedAlarmId);
    }
    return intent;
}
 
Example 16
Source File: AlarmHelper.java    From MissZzzReader with Apache License 2.0 5 votes vote down vote up
public static void removeOneShotAlarm(Context context, int id){
    Intent intent = new Intent(alarmActicon);
    intent.setFlags(FLAG_INCLUDE_STOPPED_PACKAGES);
    PendingIntent pi = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarmManager = (AlarmManager)context.getSystemService(ALARM_SERVICE);
    alarmManager.cancel(pi);
}
 
Example 17
Source File: HomepageActivity.java    From chaoli-forum-for-android-2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    switch (item.getOrder()){
        case MENU_SETTING:
            //startActivity(new Intent(HomepageActivity.this, SettingsActivity.class));
            startActivityForResult(new Intent(HomepageActivity.this, SettingsActivity.class), SETTING_CODE);
            break;
        case MENU_LOGOUT:
            // showProcessDialog(getString(R.string.just_a_sec));
            Toast.makeText(getApplicationContext(), R.string.logout_success, Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(HomepageActivity.this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
            LoginUtils.logout(new LoginUtils.LogoutObserver() {
                @Override
                public void onLogoutSuccess() {
                    // dismissProcessDialog();
                }

                @Override
                public void onLogoutFailure(int statusCode) {
                    dismissProcessDialog();
                    showToast(R.string.network_err);
                }
            });

            break;
    }
    return true;
}
 
Example 18
Source File: NativeApi.java    From imsdk-android with MIT License 4 votes vote down vote up
public static void openPublicNumberVC() {
    Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(CommonConfig.schema + "://qunarchat/search?" +
            SEARCH_SCOPE + "=4"));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    CommonConfig.globalContext.startActivity(intent);
}
 
Example 19
Source File: AdamantFirebaseMessagingService.java    From adamant-android with GNU General Public License v3.0 4 votes vote down vote up
private void showNotification(String title, String message) {
    String channelId = buildChannel();

    Intent notificationIntent = new Intent(this.getApplicationContext(), SplashScreen.class);

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent intent = PendingIntent.getActivity(this.getApplicationContext(), 0,
            notificationIntent, 0);

    Notification notification = NotificationHelper.buildMessageNotification(channelId, this, title, message);
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    notification.contentIntent = intent;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(NOTIFICATION_ID, notification);
}
 
Example 20
Source File: ServicePlayer.java    From freemp with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    // initialize default output device
    if (!BASS.BASS_Init(-1, 44100, 0)) {
        return;
    }

    // look for plugins
    plugins = "";
    String path = getApplicationInfo().nativeLibraryDir;
    String[] list = new File(path).list();
    for (String s : list) {
        int plug = BASS.BASS_PluginLoad(path + "/" + s, 0);
        if (plug != 0) { // plugin loaded...
            plugins += s + "\n"; // add it to the list
        }
    }
    if (plugins.equals("")) plugins = "no plugins - visit the BASS webpage to get some\n";
    if (activity != null) {
        activity.onPluginsLoaded(plugins);
    }
    BASS.BASS_SetConfig(BASS.BASS_CONFIG_BUFFER, 1000);
    Log.w("BASS.BASS_CONFIG_BUFFER", "" + BASS.BASS_GetConfig(BASS.BASS_CONFIG_BUFFER));
    //screen
    screenHeight = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt("screenHeight", 1000);
    screenWidth = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt("screenWidth", 800);

    // Pending Intend
    Intent intent = new Intent(this, ActPlayer.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

    //tracklist
    updateTrackList();

    tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(telephone, PhoneStateListener.LISTEN_CALL_STATE);
    myBroadcastReceiver = new MyBroadcastReceiver();
    IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG);
    intentFilter.addAction("android.media.VOLUME_CHANGED_ACTION");
    intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    registerReceiver(myBroadcastReceiver, intentFilter);


    mAudioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
    mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC,
            AudioManager.AUDIOFOCUS_GAIN);
    ComponentName rcvMedia = new ComponentName(getPackageName(), RcvMediaControl.class.getName());
    mAudioManager.registerMediaButtonEventReceiver(rcvMedia);

    // Use the remote control APIs (if available) to set the playback state
    if (android.os.Build.VERSION.SDK_INT >= 14 && remoteControlClient == null) {
        registerRemoteControl(rcvMedia);
    }
}