Search code examples
androidandroid-intentrecordonactivityresultmediaprojectionmanager

How to save onActivityResult Intent data in android?


i am using MediaProjectionManager to record video from app,and also give permission for save audio and media storage.

<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
        Intent permissionIntent = mediaProjectionManager != null ? mediaProjectionManager.createScreenCaptureIntent() : null;
        startActivityForResult(permissionIntent, SCREEN_RECORD_REQUEST_CODE);
    }



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    recorder.startScreenRecording(data, resultCode, this);
 }

}

i want to save this Intent data for feature use, means i want to reuse this intent data from after application close and re-open time, i give all runtime permission also. is it possible, then please help.

Thanks.


Solution

  • You can use SharedPreferences to save Variables in Android.

    To store

    SharedPreferences settings = getSharedPreferences(PREFERENCES, 0);
                    SharedPreferences.Editor editor = settings.edit();
                    String uriString = data.toUri(requestCode); 
                    editor.putString("Contacts_app", uriString);
                    editor.commit();
    

    To retreive

    SharedPreferences settings = getSharedPreferences(PREFERENCES, 0);
        String contactsApp = settings.getString("Contacts_app", null);
        try {
            telApp = Intent.parseUri(contactsApp, 0);
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    

    For further information look here.