Example usage for android.content Intent getFlags

List of usage examples for android.content Intent getFlags

Introduction

In this page you can find the example usage for android.content Intent getFlags.

Prototype

public @Flags int getFlags() 

Source Link

Document

Retrieve any special flags associated with this intent.

Usage

From source file:cl.chileagil.agileday2012.fragment.MainFragment.java

void gotAccount() {
    Account account = accountManager.getAccountByName(accountName);
    if (account == null) {
        chooseAccount();/*from   w w w  .jav a 2 s  .  co  m*/
        return;
    }
    if (authToken != null) {
        //Ya tengo elegido mi cuenta.
        //Solo si no tengo datos en la DB, lo pido, sino cargo lo que hay
        //y actualizo solo a peticion del usuario
        DatabaseAdapter dbAdapter = null;
        try {
            dbAdapter = new DatabaseAdapter(this);
            dbAdapter.open();
            if (dbAdapter.fetchCountEvents() <= 0) {
                onAuthToken();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                dbAdapter.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return;
    }
    accountManager.getAccountManager().getAuthToken(account, AUTH_TOKEN_TYPE, true,
            new AccountManagerCallback<Bundle>() {

                public void run(AccountManagerFuture<Bundle> future) {
                    try {
                        Bundle bundle = future.getResult();
                        if (bundle.containsKey(AccountManager.KEY_INTENT)) {
                            Intent intent = bundle.getParcelable(AccountManager.KEY_INTENT);
                            intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivityForResult(intent, REQUEST_AUTHENTICATE);
                        } else if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
                            setAuthToken(bundle.getString(AccountManager.KEY_AUTHTOKEN));
                            onAuthToken();
                        }
                    } catch (Exception e) {
                        Log.e(TAG, e.getMessage(), e);
                    }
                }
            }, null);
}

From source file:com.cyanogenmod.account.ui.SetupWizardActivity.java

private void finishSetup() {
    Settings.Global.putInt(getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
    Settings.Secure.putInt(getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
    ((CMAccount) AppGlobals.getInitialApplication()).enableStatusBar();
    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.HOME");
    disableSetupWizards(intent);/*from w w w  .  j a v a  2  s. c  o m*/
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | intent.getFlags());
    startActivity(intent);
    finish();
}

From source file:ch.bfh.instacircle.service.NetworkService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    // Initializing the dbHelper in order to get access to the database
    dbHelper = NetworkDbHelper.getInstance(this);

    // Create a pending intent which will be invoked after tapping on the
    // Android notification
    Intent notificationIntent = new Intent(this, NetworkActiveActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            notificationIntent.getFlags());

    // Setting up the notification which is being displayed
    Notification.Builder notificationBuilder = new Notification.Builder(this);
    notificationBuilder.setContentTitle(getResources().getString(R.string.app_name));
    notificationBuilder.setContentText("An InstaCircle Chat session is running. Tap to bring in front.");
    notificationBuilder.setSmallIcon(R.drawable.glyphicons_244_conversation);
    notificationBuilder.setContentIntent(pendingNotificationIntent);
    notificationBuilder.setOngoing(true);
    Notification notification = notificationBuilder.getNotification();

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

    notificationManager.notify(TAG, 1, notification);

    udpBroadcastReceiverThreads = new UDPBroadcastReceiverThread[100];
    tcpUnicastReceiverThreads = new TCPUnicastReceiverThread[100];

    // starting 100 threads allocating 100 Ports
    for (int i = 0; i < 50; i++) {
        udpBroadcastReceiverThreads[i] = new UDPBroadcastReceiverThread(this, i + 12300);
        tcpUnicastReceiverThreads[i] = new TCPUnicastReceiverThread(this, i + 12300);

        udpBroadcastReceiverThreads[i].start();
        tcpUnicastReceiverThreads[i].start();
    }/*w ww.j a v  a2s  . com*/

    // Register a broadcastreceiver in order to get notification from the UI
    // when a message should be sent
    LocalBroadcastManager.getInstance(this).registerReceiver(messageSendReceiver,
            new IntentFilter("messageSend"));

    // Opening a conversation
    dbHelper.openConversation(getSharedPreferences(PREFS_NAME, 0).getString("password", "N/A"));

    // joining the conversation using the identification in the preferences
    // file
    joinNetwork(getSharedPreferences(PREFS_NAME, 0).getString("identification", "N/A"));

    // start the NetworkActiveActivity
    intent = new Intent(this, NetworkActiveActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    startActivity(intent);
    return super.onStartCommand(intent, flags, startId);
}

From source file:de.lespace.apprtc.activity.ConnectActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_connect);

    // Get setting keys.
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    keyprefFrom = getString(R.string.pref_from_key);
    keyprefVideoCallEnabled = getString(R.string.pref_videocall_key);
    keyprefResolution = getString(R.string.pref_resolution_key);
    keyprefFps = getString(R.string.pref_fps_key);
    keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key);
    keyprefVideoBitrateType = getString(R.string.pref_startvideobitrate_key);
    keyprefVideoBitrateValue = getString(R.string.pref_startvideobitratevalue_key);
    keyprefVideoCodec = getString(R.string.pref_videocodec_key);
    keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key);
    keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key);
    keyprefAudioBitrateType = getString(R.string.pref_startaudiobitrate_key);
    keyprefAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key);
    keyprefAudioCodec = getString(R.string.pref_audiocodec_key);
    keyprefNoAudioProcessingPipeline = getString(R.string.pref_noaudioprocessing_key);
    keyprefAecDump = getString(R.string.pref_aecdump_key);
    keyprefOpenSLES = getString(R.string.pref_opensles_key);
    keyprefDisplayHud = getString(R.string.pref_displayhud_key);
    keyprefTracing = getString(R.string.pref_tracing_key);
    keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key);
    keyprefRoomList = getString(R.string.pref_room_list_key);

    // Video call enabled flag.
    boolean videoCallEnabled = sharedPref.getBoolean(keyprefVideoCallEnabled,
            Boolean.valueOf(getString(R.string.pref_videocall_default)));

    String wssUrl = sharedPref.getString(keyprefRoomServerUrl,
            getString(R.string.pref_room_server_url_default));
    from = sharedPref.getString(keyprefFrom, getString(R.string.pref_from_default));
    // Get default codecs.
    String videoCodec = sharedPref.getString(keyprefVideoCodec, getString(R.string.pref_videocodec_default));
    String audioCodec = sharedPref.getString(keyprefAudioCodec, getString(R.string.pref_audiocodec_default));

    // Check HW codec flag.
    boolean hwCodec = sharedPref.getBoolean(keyprefHwCodecAcceleration,
            Boolean.valueOf(getString(R.string.pref_hwcodec_default)));

    // Check Capture to texture.
    boolean captureToTexture = sharedPref.getBoolean(keyprefCaptureToTexture,
            Boolean.valueOf(getString(R.string.pref_capturetotexture_default)));

    // Check Disable Audio Processing flag.
    boolean noAudioProcessing = sharedPref.getBoolean(keyprefNoAudioProcessingPipeline,
            Boolean.valueOf(getString(R.string.pref_noaudioprocessing_default)));

    // Check Disable Audio Processing flag.
    boolean aecDump = sharedPref.getBoolean(keyprefAecDump,
            Boolean.valueOf(getString(R.string.pref_aecdump_default)));

    // Check OpenSL ES enabled flag.
    boolean useOpenSLES = sharedPref.getBoolean(keyprefOpenSLES,
            Boolean.valueOf(getString(R.string.pref_opensles_default)));

    // Check for mandatory permissions.
    missingPermissions = new ArrayList();

    for (String permission : MANDATORY_PERMISSIONS) {
        if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
            missingPermissions.add(permission);
        }//from  w w  w.  j a  v  a2s  .co  m
    }
    requestPermission();

    networkchangeBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            if (intent.getFlags() == 0) {
                SignalingService.appRTCClient.resetWebsocket();
            }
            if (intent.getFlags() == 1) {
                SignalingService.appRTCClient.reconnect();
                Toast.makeText(context, "network is online:" + intent.getFlags(), Toast.LENGTH_LONG).show();
            }
        }
    };

    // Registering BroadcastReceiver
    registerNetworkChangeReceiver();

    // Get video resolution from settings.
    int videoWidth = 0;
    int videoHeight = 0;
    String resolution = sharedPref.getString(keyprefResolution, getString(R.string.pref_resolution_default));
    String[] dimensions = resolution.split("[ x]+");
    if (dimensions.length == 2) {
        try {
            videoWidth = Integer.parseInt(dimensions[0]);
            videoHeight = Integer.parseInt(dimensions[1]);
        } catch (NumberFormatException e) {
            videoWidth = 0;
            videoHeight = 0;
            Log.e(TAG, "Wrong video resolution setting: " + resolution);
        }
    }

    // Get camera fps from settings.
    int cameraFps = 0;
    String fps = sharedPref.getString(keyprefFps, getString(R.string.pref_fps_default));
    String[] fpsValues = fps.split("[ x]+");
    if (fpsValues.length == 2) {
        try {
            cameraFps = Integer.parseInt(fpsValues[0]);
        } catch (NumberFormatException e) {
            Log.e(TAG, "Wrong camera fps setting: " + fps);
        }
    }

    // Check capture quality slider flag.
    boolean captureQualitySlider = sharedPref.getBoolean(keyprefCaptureQualitySlider,
            Boolean.valueOf(getString(R.string.pref_capturequalityslider_default)));

    // Get video and audio start bitrate.
    int videoStartBitrate = 0;
    String bitrateTypeDefault = getString(R.string.pref_startvideobitrate_default);
    String bitrateType = sharedPref.getString(keyprefVideoBitrateType, bitrateTypeDefault);
    if (!bitrateType.equals(bitrateTypeDefault)) {
        String bitrateValue = sharedPref.getString(keyprefVideoBitrateValue,
                getString(R.string.pref_startvideobitratevalue_default));
        videoStartBitrate = Integer.parseInt(bitrateValue);
    }
    int audioStartBitrate = 0;
    bitrateTypeDefault = getString(R.string.pref_startaudiobitrate_default);
    bitrateType = sharedPref.getString(keyprefAudioBitrateType, bitrateTypeDefault);
    if (!bitrateType.equals(bitrateTypeDefault)) {
        String bitrateValue = sharedPref.getString(keyprefAudioBitrateValue,
                getString(R.string.pref_startaudiobitratevalue_default));
        audioStartBitrate = Integer.parseInt(bitrateValue);
    }

    // Check statistics display option.
    boolean displayHud = sharedPref.getBoolean(keyprefDisplayHud,
            Boolean.valueOf(getString(R.string.pref_displayhud_default)));

    boolean tracing = sharedPref.getBoolean(keyprefTracing,
            Boolean.valueOf(getString(R.string.pref_tracing_default)));

    // Log.d(TAG, "Connecting from " + from + " at URL " + wssUrl);

    if (validateUrl(wssUrl)) {
        Uri uri = Uri.parse(wssUrl);
        intent = new Intent(this, ConnectActivity.class);
        intent.setData(uri);
        intent.putExtra(CallActivity.EXTRA_VIDEO_CALL, videoCallEnabled);
        intent.putExtra(CallActivity.EXTRA_VIDEO_WIDTH, videoWidth);
        intent.putExtra(CallActivity.EXTRA_VIDEO_HEIGHT, videoHeight);
        intent.putExtra(CallActivity.EXTRA_VIDEO_FPS, cameraFps);
        intent.putExtra(CallActivity.EXTRA_VIDEO_CAPTUREQUALITYSLIDER_ENABLED, captureQualitySlider);
        intent.putExtra(CallActivity.EXTRA_VIDEO_BITRATE, videoStartBitrate);
        intent.putExtra(CallActivity.EXTRA_VIDEOCODEC, videoCodec);
        intent.putExtra(CallActivity.EXTRA_HWCODEC_ENABLED, hwCodec);
        intent.putExtra(CallActivity.EXTRA_CAPTURETOTEXTURE_ENABLED, captureToTexture);
        intent.putExtra(CallActivity.EXTRA_NOAUDIOPROCESSING_ENABLED, noAudioProcessing);
        intent.putExtra(CallActivity.EXTRA_AECDUMP_ENABLED, aecDump);
        intent.putExtra(CallActivity.EXTRA_OPENSLES_ENABLED, useOpenSLES);
        intent.putExtra(CallActivity.EXTRA_AUDIO_BITRATE, audioStartBitrate);
        intent.putExtra(CallActivity.EXTRA_AUDIOCODEC, audioCodec);
        intent.putExtra(CallActivity.EXTRA_DISPLAY_HUD, displayHud);
        intent.putExtra(CallActivity.EXTRA_TRACING, tracing);
        intent.putExtra(CallActivity.EXTRA_RUNTIME, runTimeMs);
    }

    roomListView = (ListView) findViewById(R.id.room_listview);
    roomListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    connectButton = (ImageButton) findViewById(R.id.connect_button);
    connectButton.setOnClickListener(connectListener);

    // If an implicit VIEW intent is launching the app, go directly to that URL.
    //final Intent intent = getIntent();
    Uri wsurl = Uri.parse(wssUrl);
    //intent.getData();
    // Log.d(TAG, "connecting to:" + wsurl.toString());
    if (wsurl == null) {
        logAndToast(getString(R.string.missing_wsurl));
        Log.e(TAG, "Didn't get any URL in intent!");
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    if (from == null || from.length() == 0) {
        logAndToast(getString(R.string.missing_from));
        Log.e(TAG, "Incorrect from in intent!");
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    peerConnectionParameters = new PeerConnectionClient.PeerConnectionParameters(videoCallEnabled, tracing,
            videoWidth, videoHeight, cameraFps, videoStartBitrate, videoCodec, hwCodec, captureToTexture,
            audioStartBitrate, audioCodec, noAudioProcessing, aecDump, useOpenSLES);

    Intent intent = getIntent();
    Log.i(TAG, "created apprtc with uri:" + wsurl.toString() + " from:" + from);

    Log.i(TAG, "intent.EXTRA_TO:" + intent.getStringExtra(RTCConnection.EXTRA_TO));
    Log.i(TAG, "intent.EXTRA_FROM:" + intent.getStringExtra(RTCConnection.EXTRA_FROM));
    Log.i(TAG, "intent.EXTRA_INITIATOR:" + intent.getBooleanExtra(RTCConnection.EXTRA_INITIATOR, false));

    if (intent.getStringExtra(RTCConnection.EXTRA_TO) != null
            && !intent.getStringExtra(RTCConnection.EXTRA_TO).equals("")) {

        RTCConnection.to = intent.getStringExtra(RTCConnection.EXTRA_TO);
        RTCConnection.from = intent.getStringExtra(RTCConnection.EXTRA_FROM);
        RTCConnection.initiator = intent.getBooleanExtra(RTCConnection.EXTRA_INITIATOR, false);
        ;
        connectToUser();
    }

    /*  if(intent.getStringExtra(RTCConnection.EXTRA_TO)!=null
            && !intent.getStringExtra(RTCConnection.EXTRA_TO).equals("")){
            
          RTCConnection.to = intent.getStringExtra(RTCConnection.EXTRA_TO);
         // RTCConnection.from = intent.getStringExtra(RTCConnection.EXTRA_FROM);
          RTCConnection.initiator = intent.getBooleanExtra(RTCConnection.EXTRA_INITIATOR,false);;
            
      Intent serviceIntent = new Intent(this,SignalingService.class);
      serviceIntent.putExtra(RTCConnection.EXTRA_FROM, RTCConnection.to);
            
     //WebRTC-Signaling
     startService(intent);
    }*/

}

From source file:com.sublimis.urgentcallfilter.Magic.java

@SuppressWarnings("deprecation")
private void notification() {
    if (MyPreference.isNotifications()) {
        if (mContext != null) {
            NotificationManager notificationManager = (NotificationManager) mContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);

            if (notificationManager != null) {
                Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis());
                Intent notificationIntent = new Intent(mContext, ActivityMain.class);

                if (notification != null && notificationIntent != null) {
                    notificationIntent.setFlags(notificationIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent,
                            PendingIntent.FLAG_UPDATE_CURRENT);

                    notification.setLatestEventInfo(mContext,
                            mContext.getResources().getString(R.string.notification_title),
                            mContext.getResources().getString(R.string.notification_text), pendingIntent);

                    notificationManager.notify(0, notification);
                }//  w w w.j a  v  a 2s .c  om
            }
        }
    }
}

From source file:org.xbmc.android.remote.presentation.activity.MovieLibraryActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    // first, process individual menu events
    switch (mTabHost.getCurrentTab()) {
    case 0://w ww  .j a v  a2  s. co  m
        mMovieController.onOptionsItemSelected(item);
        break;
    case 1:
        mActorController.onOptionsItemSelected(item);
        break;
    case 2:
        mGenresController.onOptionsItemSelected(item);
        break;
    case 3:
        mFileController.onOptionsItemSelected(item);
        break;
    case 4:
        mMoviePosterWrapController.onOptionsItemSelected(item);
        break;
    }

    // then the generic ones.
    switch (item.getItemId()) {
    case MENU_REMOTE:
        final Intent intent;
        if (getSharedPreferences("global", Context.MODE_PRIVATE).getInt(RemoteController.LAST_REMOTE_PREFNAME,
                -1) == RemoteController.LAST_REMOTE_GESTURE) {
            intent = new Intent(this, GestureRemoteActivity.class);
        } else {
            intent = new Intent(this, RemoteActivity.class);
        }
        intent.addFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(intent);
        return true;
    case MENU_UPDATE_LIBRARY:
        mMovieController.refreshMovieLibrary(this);
        return true;
    case MENU_NOW_PLAYING:
        startActivity(new Intent(this, NowPlayingActivity.class));
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.SendPK.java

@SuppressLint("NewApi")
@Override//from   w  ww  . j  a  v  a  2s .c  om
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
    if (resultCode == Activity.RESULT_OK && resultData != null) {
        Uri uri = null;

        if (requestCode == SELECT_PHOTO) {
            uri = resultData.getData();
            Log.i("Uri", "Uri: " + uri.toString());
        } else if (requestCode == SELECT_PHOTO_KITKAT) {
            uri = resultData.getData();
            Log.i("Uri_kitkat", "Uri: " + uri.toString());
            final int takeFlags = resultData.getFlags()
                    & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            // Check for the freshest data.
            getActivity().getContentResolver().takePersistableUriPermission(uri, takeFlags);
        }

        selectedImagePath = FileUtils.getPath(getActivity(), uri);
        Log.i("path", "path: " + selectedImagePath);

        selectImageFile = new File(selectedImagePath);
        //File testFile = new File("file://storage/emulated/0/DCIM/hobbit.bmp");

        boolean success;

        String[] selected = new String[1];
        DD_Address adr = new DD_Address(peer);
        try {
            //util.EmbedInMedia.DEBUG = true;
            Log.i("success_embed", "success_embed 1: " + selectImageFile);
            success = DD.embedPeerInBMP(selectImageFile, selected, adr);
            Log.i("success_embed", "success_embed 2: " + success);
            if (success == true) {
                Toast.makeText(getActivity(), "Export success!", Toast.LENGTH_SHORT).show();
            } else
                Toast.makeText(getActivity(), "Unable to export:" + selected[0], Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Toast.makeText(getActivity(), "Unable to export!", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }

    }

    /*      if (resultCode == Activity.RESULT_OK && resultData != null) {
    Uri uri = null;
            
    if (requestCode == PK_SELECT_PHOTO) {
        uri = resultData.getData();
        Log.i("Uri", "Uri: " + uri.toString());
    } else if (requestCode == PK_SELECT_PHOTO_KITKAT) {
        uri = resultData.getData();
        Log.i("Uri_kitkat", "Uri: " + uri.toString());
        final int takeFlags = resultData.getFlags()
                & (Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        // Check for the freshest data.
        getActivity().getContentResolver().takePersistableUriPermission(uri, takeFlags);
    }
            
             
    selectedImagePath = FileUtils.getPath(getActivity(),uri);
    Log.i("path", "path: " + selectedImagePath); 
                
    selectImageFile = new File(selectedImagePath);
    //File testFile = new File("file://storage/emulated/0/DCIM/hobbit.bmp");
            
    boolean success;    
            
    try {
       //util.EmbedInMedia.DEBUG = true;
       success = saveSK(peer, selectImageFile);
       Log.i("success_embed", "success_embed: " + success); 
     if (success == true) {
         Toast.makeText(getActivity(), "Export success!", Toast.LENGTH_SHORT).show();
     } else 
         Toast.makeText(getActivity(), "Unable to export!", Toast.LENGTH_SHORT).show();  
    }
              catch (Exception e) {
     Toast.makeText(getActivity(), "Unable to export!", Toast.LENGTH_SHORT).show();
     e.printStackTrace();
              } 
                   
          }*/
    super.onActivityResult(requestCode, resultCode, resultData);
}

From source file:com.pranavpandey.smallapp.permission.PermissionSelectExternalStorage.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//  w  w w. jav  a2 s. com
public final void onActivityResult(final int requestCode, final int resultCode, final Intent resultData) {
    if (requestCode == REQUEST_CODE_STORAGE_ACCESS) {
        Uri treeUri = null;
        if (resultCode == Activity.RESULT_OK) {
            // Get Uri from Storage Access Framework.
            treeUri = resultData.getData();

            // Persist URI in shared preference so that you can use it later.
            // Use your own framework here instead of PreferenceUtil.
            SmallUtils.savePrefs(this, PREF_EXTERNAL_STORAGE_URI, treeUri.toString());
            Toast.makeText(this, treeUri.toString(), Toast.LENGTH_LONG).show();

            // Persist access permissions.
            final int takeFlags = resultData.getFlags()
                    & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            getContentResolver().takePersistableUriPermission(treeUri, takeFlags);
        }
    }
    finish();
}

From source file:com.coloreight.plugin.socialAuth.SocialAuth.java

public void getTwitterSystemAccount(final String networkUserName, final CallbackContext callbackContext) {
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {

            PluginResult pluginResult;//  ww  w .  j  av  a2  s  .  co m
            final JSONObject json = new JSONObject();
            final JSONObject account = new JSONObject();

            final Account[] twitterAccounts = accountManager
                    .getAccountsByType("com.twitter.android.auth.login");

            try {
                if (twitterAccounts.length > 0) {
                    json.put("granted", true);

                    for (int i = 0; i < twitterAccounts.length; i++) {
                        if (twitterAccounts[i].name.equals(networkUserName)) {
                            account.put("userName", twitterAccounts[i].name);

                            final Account twitterAccount = twitterAccounts[i];

                            accountManager.getAuthToken(twitterAccount, "com.twitter.android.oauth.token", null,
                                    false, new AccountManagerCallback<Bundle>() {
                                        @Override
                                        public void run(AccountManagerFuture<Bundle> accountManagerFuture) {
                                            try {
                                                Bundle bundle = accountManagerFuture.getResult();

                                                if (bundle.containsKey(AccountManager.KEY_INTENT)) {
                                                    Intent intent = bundle
                                                            .getParcelable(AccountManager.KEY_INTENT);

                                                    //clear the new task flag just in case, since a result is expected
                                                    int flags = intent.getFlags();
                                                    flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
                                                    intent.setFlags(flags);

                                                    requestedTwitterAccountName = networkUserName;

                                                    cordova.getActivity().startActivityForResult(intent,
                                                            TWITTER_OAUTH_REQUEST);
                                                } else {
                                                    account.put("oauth_token",
                                                            bundle.getString(AccountManager.KEY_AUTHTOKEN));

                                                    accountManager.getAuthToken(twitterAccount,
                                                            "com.twitter.android.oauth.token.secret", null,
                                                            false, new AccountManagerCallback<Bundle>() {
                                                                @Override
                                                                public void run(
                                                                        AccountManagerFuture<Bundle> accountManagerFuture) {
                                                                    try {
                                                                        Bundle bundle = accountManagerFuture
                                                                                .getResult();

                                                                        if (bundle.containsKey(
                                                                                AccountManager.KEY_INTENT)) {
                                                                            Intent intent = bundle
                                                                                    .getParcelable(
                                                                                            AccountManager.KEY_INTENT);

                                                                            //clear the new task flag just in case, since a result is expected
                                                                            int flags = intent.getFlags();
                                                                            flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
                                                                            intent.setFlags(flags);

                                                                            requestedTwitterAccountName = networkUserName;

                                                                            cordova.getActivity()
                                                                                    .startActivityForResult(
                                                                                            intent,
                                                                                            TWITTER_OAUTH_REQUEST);
                                                                        } else {
                                                                            account.put("oauth_token_secret",
                                                                                    bundle.getString(
                                                                                            AccountManager.KEY_AUTHTOKEN));

                                                                            json.put("data", account);

                                                                            Log.v(TAG, "Account data: "
                                                                                    + json.toString());

                                                                            PluginResult pluginResult = new PluginResult(
                                                                                    PluginResult.Status.OK,
                                                                                    json);
                                                                            pluginResult.setKeepCallback(true);
                                                                            callbackContext.sendPluginResult(
                                                                                    pluginResult);
                                                                        }

                                                                    } catch (Exception e) {
                                                                        PluginResult pluginResult = new PluginResult(
                                                                                PluginResult.Status.ERROR,
                                                                                e.getLocalizedMessage());
                                                                        pluginResult.setKeepCallback(true);
                                                                        callbackContext
                                                                                .sendPluginResult(pluginResult);
                                                                    }
                                                                }
                                                            }, null);
                                                }

                                            } catch (Exception e) {
                                                PluginResult pluginResult = new PluginResult(
                                                        PluginResult.Status.ERROR, e.getLocalizedMessage());
                                                pluginResult.setKeepCallback(true);
                                                callbackContext.sendPluginResult(pluginResult);
                                            }
                                        }
                                    }, null);
                        }
                    }
                } else {
                    json.put("code", "0");
                    json.put("message", "no have twitter accounts");

                    pluginResult = new PluginResult(PluginResult.Status.ERROR, json);
                    pluginResult.setKeepCallback(true);
                    callbackContext.sendPluginResult(pluginResult);
                }
            } catch (JSONException e) {
                pluginResult = new PluginResult(PluginResult.Status.ERROR, e.getLocalizedMessage());
                pluginResult.setKeepCallback(true);
                callbackContext.sendPluginResult(pluginResult);
            }
        }
    });
}

From source file:org.gnucash.android.ui.common.BaseDrawerActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_CANCELED) {
        super.onActivityResult(requestCode, resultCode, data);
        return;/* ww  w.  j  a va 2s .  c o m*/
    }

    switch (requestCode) {
    case AccountsActivity.REQUEST_PICK_ACCOUNTS_FILE:
        AccountsActivity.importXmlFileFromIntent(this, data, null);
        break;
    case BaseDrawerActivity.REQUEST_OPEN_DOCUMENT: //this uses the Storage Access Framework
        final int takeFlags = data.getFlags()
                & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        AccountsActivity.importXmlFileFromIntent(this, data, null);
        getContentResolver().takePersistableUriPermission(data.getData(), takeFlags);
        break;
    default:
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
}