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

The following examples show how to use android.content.Intent#addFlags() . 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: GcmListenerSvc.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void sendNotification(String body, String title) {
    Intent intent = new Intent(this, Home.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Notification.Builder notificationBuilder = (Notification.Builder) new Notification.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(title)
            .setContentText(body)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
 
Example 2
Source File: RomEntity.java    From XKnife-Android with Apache License 2.0 6 votes vote down vote up
private void showMiuiInstalledAppDetails(Context context) {
            String rom = super.getPropertyValue();
            String pkg = context.getPackageName();
            if ("V6".equals(rom)) {
                Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR");
                intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
                intent.putExtra("extra_pkgname", pkg);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                    context.startActivity(intent);
                } catch (Exception e) {
                }

//            Activity activity = PageSwitcher.peekActivityStack();
//            if (Util.isIntentAvailable(activity, intent)) {
//                activity.startActivityForResult(intent, 2);
//            } else {
//                L.e("Intent is not available!");
//            }
            } else {
                NotProguardUtils.showInstalledAppDetails(context, pkg);
            }
        }
 
Example 3
Source File: ExternalOpenVPNService.java    From android with GNU General Public License v3.0 6 votes vote down vote up
private void startProfile(VpnProfile vp) {
    Intent vpnPermissionIntent = VpnService.prepare(ExternalOpenVPNService.this);
    /* Check if we need to show the confirmation dialog,
     * Check if we need to ask for username/password */

    int needpw = vp.needUserPWInput(false);

    if (vpnPermissionIntent != null || needpw != 0) {
        Intent shortVPNIntent = new Intent(Intent.ACTION_MAIN);
        shortVPNIntent.setClass(getBaseContext(), ht.vpn.android.LaunchVPN.class);
        shortVPNIntent.putExtra(ht.vpn.android.LaunchVPN.EXTRA_KEY, vp.getUUIDString());
        shortVPNIntent.putExtra(ht.vpn.android.LaunchVPN.EXTRA_HIDELOG, true);
        shortVPNIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(shortVPNIntent);
    } else {
        VPNLaunchHelper.startOpenVpn(vp, getBaseContext());
    }

}
 
Example 4
Source File: PermissionRequestActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
public static void requestPermissions(@NonNull Context context, @NonNull String[] permissions,
        @NonNull ResultReceiver resultReceiver) {
    Intent callIntent = new Intent(context, PermissionRequestActivity.class);
    callIntent.putExtra(EXTRA_PERMISSIONS, permissions);
    callIntent.putExtra(EXTRA_CALLBACK, resultReceiver);
    // NOTE: FLAG_ACTIVITY_SINGLE_TASK causes Activity#onActivityResult()
    // being called prematurely. FLAG_ACTIVITY_SINGLE_TOP, on the other
    // hand, does not cause that.
    callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
        context.startActivity(callIntent);
    } else {
        NotificationUtils.createNotificationChannel(context);
        NotificationUtils.notify(context, NOTIFICATION_ID, REQUEST_CODE, callIntent, NOTIFICATION_CONTENT);
    }
}
 
Example 5
Source File: ConfirmationIntentWrapperActivity.java    From SAI with GNU General Public License v3.0 5 votes vote down vote up
public static void start(Context c, int sessionId, Intent confirmationIntent) {
    Intent intent = new Intent(c, ConfirmationIntentWrapperActivity.class);
    intent.putExtra(EXTRA_CONFIRMATION_INTENT, confirmationIntent);
    intent.putExtra(RootlessSAIPIService.EXTRA_SESSION_ID, sessionId);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    c.startActivity(intent);
}
 
Example 6
Source File: SetupActivity.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Intent intent = new Intent();
    intent.setClass(this, SetupWizardActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    if (!isFinishing()) {
        finish();
    }
}
 
Example 7
Source File: LoginFragment.java    From incubator-taverna-mobile with Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.bRegister)
public void register(View v) {
    if (Build.VERSION.SDK_INT < 15) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse(myExperimentURL));
        startActivity(intent);
    } else {
        CustomTabsIntent.Builder customTabsIntentBuilder = new CustomTabsIntent.Builder();
        CustomTabsIntent customTabsIntent = customTabsIntentBuilder.build();
        customTabsIntent.launchUrl(getActivity(), Uri.parse(myExperimentURL));
    }
}
 
Example 8
Source File: ClickPendingIntentActivity.java    From ZadakNotification with MIT License 5 votes vote down vote up
@Override
public PendingIntent onSettingPendingIntent() {
    Intent clickIntentActivity = new Intent(ZadakNotification.mSingleton.mContext, mActivity);
    clickIntentActivity.setAction(BroadcastActions.ACTION_CLICK_INTENT);
    clickIntentActivity.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    clickIntentActivity.setPackage(ZadakNotification.mSingleton.mContext.getPackageName());

    if (mBundle != null) {
        clickIntentActivity.putExtras(mBundle);
    }
    return PendingIntent.getActivity(ZadakNotification.mSingleton.mContext, mIdentifier, clickIntentActivity,
            PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 9
Source File: ReadArticleActivity.java    From android-app with GNU General Public License v3.0 5 votes vote down vote up
private boolean handleTagClicked(String url) {
    final String tagUrlPrefix = "tag://";

    if (!url.startsWith(tagUrlPrefix)) return false;

    long tagId;
    try {
        tagId = Long.parseLong(url.substring(tagUrlPrefix.length()));
    } catch (NumberFormatException nfe) {
        Log.w(TAG, "handleTagClicked() couldn't handle tag URL: " + url);
        return true;
    }

    Tag tag = null;
    for (Tag t : article.getTags()) {
        if (t.getId() == tagId) {
            tag = t;
            break;
        }
    }

    if (tag == null) {
        Log.w(TAG, "handleTagClicked() couldn't find tag by ID: " + tagId);
        return true;
    }

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra(MainActivity.PARAM_TAG_LABEL, tag.getLabel());

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    startActivity(intent);

    return true;
}
 
Example 10
Source File: GilgaService.java    From gilgamesh with GNU General Public License v3.0 5 votes vote down vote up
private void startBroadcasting() {
  //  if(D) Log.d(TAG, "ensure discoverable");
   if (mBluetoothAdapter.getScanMode() !=
      BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
    	
        Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 3600);
        discoverableIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(discoverableIntent);
        
    }
   
   if (!mBluetoothAdapter.isDiscovering())
	   mBluetoothAdapter.startDiscovery();

   if (mDirectChatSession == null)
   {
	   mDirectChatSession = new DirectMessageSession(this, mHandler);
	   mDirectChatSession.start();
   }
   else {
       // Only if the state is STATE_NONE, do we know that we haven't started already
       if (mDirectChatSession.getState() == DirectMessageSession.STATE_NONE) {
         // Start the Bluetooth chat services
    	   mDirectChatSession.start();
       }
       
   }
    
}
 
Example 11
Source File: DetailActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
/**
 * Uses the ShareCompat Intent builder to create our Forecast intent for sharing.  All we need
 * to do is set the type, text and the NEW_DOCUMENT flag so it treats our share as a new task.
 * See: http://developer.android.com/guide/components/tasks-and-back-stack.html for more info.
 *
 * @return the Intent to use to share our weather forecast
 */
private Intent createShareForecastIntent() {
    Intent shareIntent = ShareCompat.IntentBuilder.from(this)
            .setType("text/plain")
            .setText(mForecastSummary + FORECAST_SHARE_HASHTAG)
            .getIntent();
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    return shareIntent;
}
 
Example 12
Source File: IntentUtils.java    From AndroidDocumentViewer with MIT License 5 votes vote down vote up
static Intent getTextFileIntent(String paramString, boolean paramBoolean) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.addCategory("android.intent.category.DEFAULT");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (paramBoolean) {
        Uri uri1 = Uri.parse(paramString);
        intent.setDataAndType(uri1, "text/plain");
    }
    return intent;
}
 
Example 13
Source File: DownloadImage.java    From Android with MIT License 5 votes vote down vote up
public void prepareShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_TEXT, "Just for test my app ");
    shareIntent.putExtra(Intent.EXTRA_STREAM, image_path);
    shareIntent.setType("image/*");
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    mContext.startActivity(Intent.createChooser(shareIntent, "Share Opportunity"));
}
 
Example 14
Source File: SettingsActivity.java    From AppOpsX with MIT License 5 votes vote down vote up
private void switchLanguage() {
  LangHelper.updateLanguage(getContext());
  LangHelper.updateLanguage(getContext().getApplicationContext());

  Intent it = new Intent(getActivity(), MainActivity.class);
  it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
  it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  getActivity().startActivity(it);
  getActivity().finish();
}
 
Example 15
Source File: FileUtil.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
public static Intent getImageFileIntent( String param ) {

        Intent intent = new Intent("android.intent.action.VIEW");
        intent.addCategory("android.intent.category.DEFAULT");
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Uri uri = Uri.fromFile(new File(param ));
        intent.setDataAndType(uri, "image/*");
        return intent;
    }
 
Example 16
Source File: Router.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
public void showCourseDiscussionPostsForDiscussionTopic(Activity activity, DiscussionTopic topic,
                                                        String topicId, String threadId,
                                                        EnrolledCoursesResponse courseData) {
    Intent showDiscussionPostsIntent = new Intent(activity, CourseDiscussionPostsActivity.class);
    showDiscussionPostsIntent.putExtra(EXTRA_COURSE_DATA, courseData);
    if (topic != null) {
        showDiscussionPostsIntent.putExtra(EXTRA_DISCUSSION_TOPIC, topic);
    }
    showDiscussionPostsIntent.putExtra(Router.EXTRA_DISCUSSION_TOPIC_ID, topicId);
    showDiscussionPostsIntent.putExtra(Router.EXTRA_DISCUSSION_THREAD_ID, threadId);
    showDiscussionPostsIntent.putExtra(CourseDiscussionPostsThreadFragment.ARG_DISCUSSION_HAS_TOPIC_NAME, topic != null);
    showDiscussionPostsIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    activity.startActivity(showDiscussionPostsIntent);
}
 
Example 17
Source File: OpenFileUtil.java    From GreenDamFileExploere with Apache License 2.0 5 votes vote down vote up
public static Intent getAllIntent(String param) {

        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(android.content.Intent.ACTION_VIEW);
        Uri uri = Uri.fromFile(new File(param));
        intent.setDataAndType(uri, "*/*");
        return intent;
    }
 
Example 18
Source File: IntentUtils.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
private static Intent getIntent(final Intent intent, final boolean isNewTask) {
    return isNewTask ? intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) : intent;
}
 
Example 19
Source File: AbstractWidgetProvider.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
private void performActionOnReceiveForWidget(Context context, Intent intent, int widgetId) {
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
    LocationsDbHelper locationsDbHelper = LocationsDbHelper.getInstance(context);
    WidgetSettingsDbHelper widgetSettingsDbHelper = WidgetSettingsDbHelper.getInstance(context);
    Long locationId = widgetSettingsDbHelper.getParamLong(widgetId, "locationId");
    if (locationId == null) {
        currentLocation = locationsDbHelper.getLocationByOrderId(0);
        if (!currentLocation.isEnabled()) {
            currentLocation = locationsDbHelper.getLocationByOrderId(1);
        }
    } else {
        currentLocation = locationsDbHelper.getLocationById(locationId);
    }
    switch (intent.getAction()) {
        case "org.thosp.yourlocalweather.action.WEATHER_UPDATE_RESULT":
        case "android.appwidget.action.APPWIDGET_UPDATE":
            if (!servicesStarted) {
                onEnabled(context);
                servicesStarted = true;
            }
            onUpdate(context, widgetManager, new int[] {widgetId});
            break;
        case Intent.ACTION_LOCALE_CHANGED:
        case Constants.ACTION_APPWIDGET_THEME_CHANGED:
        case Constants.ACTION_APPWIDGET_SETTINGS_SHOW_CONTROLS:
            refreshWidgetValues(context);
            break;
        case Constants.ACTION_APPWIDGET_UPDATE_PERIOD_CHANGED:
            onEnabled(context);
            break;
        case Constants.ACTION_APPWIDGET_CHANGE_SETTINGS:
            onUpdate(context, widgetManager, new int[]{ widgetId});
            break;
    }

    if (intent.getAction().startsWith(Constants.ACTION_APPWIDGET_SETTINGS_OPENED)) {
        String[] params = intent.getAction().split("__");
        String widgetIdTxt = params[1];
        widgetId = Integer.parseInt(widgetIdTxt);
        openWidgetSettings(context, widgetId, params[2]);
    } else if (intent.getAction().startsWith(Constants.ACTION_APPWIDGET_START_ACTIVITY)) {
        AppPreference.setCurrentLocationId(context, currentLocation);
        Long widgetActionId = intent.getLongExtra("widgetAction", 1);
        Class activityClass = WidgetActions.getById(widgetActionId, "action_current_weather_icon").getActivityClass();
        Intent activityIntent = new Intent(context, activityClass);
        activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(activityIntent);
    } else if (intent.getAction().startsWith(Constants.ACTION_APPWIDGET_CHANGE_LOCATION)) {
        changeLocation(widgetId, locationsDbHelper, widgetSettingsDbHelper);
        GraphUtils.invalidateGraph();
        onUpdate(context, widgetManager, new int[]{widgetId});
    } else if (intent.getAction().startsWith(Constants.ACTION_FORCED_APPWIDGET_UPDATE)) {
        if (!WidgetRefreshIconService.isRotationActive) {
            sendWeatherUpdate(context, widgetId);
        }
        onUpdate(context, widgetManager, new int[]{ widgetId});

    }
}
 
Example 20
Source File: BookInfoEditActivity.java    From MyBookshelf with GNU General Public License v3.0 4 votes vote down vote up
public static void startThis(Context context, String noteUrl) {
    Intent intent = new Intent(context, BookInfoEditActivity.class);
    intent.putExtra("noteUrl", noteUrl);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}