Save intent in shared preference

前端 未结 2 1637
予麋鹿
予麋鹿 2021-01-14 00:19

I have an application from which i can launch other apps installed on my phone, with a long click i get the app picker, in result i receive an intent data, how can i save it

2条回答
  •  感情败类
    2021-01-14 00:36

    Ok i found a way I save the intent like this

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

    Then i retrieve it like this

    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();
        }
    

提交回复
热议问题