How to start an Intent from preference page AND GET RESULTS?

by Xin Zhao » Sat, 07 Mar 2009 08:37:37 GMT


Sponsored Links
 Hey guys,

I am trying to start an intent from a preference activity, AND GET RESULTS
once the new intent is done. As such, I can update the summary of the
preference.

Normall we do startActivityForResult() to wait for results. But how can I do
this here?

My code is as follow:

      PreferenceScreen intentPref =
getPreferenceManager().createPreferenceScreen(this);
      Intent intent = new Intent(this, PolicyEditor.class);
      intent.putExtra(PhoneCardDbAdapter.COL_ROWID, (long)rule.mRuleID);
      intentPref.setIntent(intent);  <--- I want to make sure once the
activity related to intent is done, we can update the summary
      title = "Rule " + (i+1);
      summary = rule.ruleSummary();
      intentPref.setTitle(title);
      intentPref.setSummary(summary);
      mlaunchPrefCat.addPreference(intentPref);

Any idea?

Thanks,
xin

--~--~---------~--~----~------------~-------~--~----~



How to start an Intent from preference page AND GET RESULTS?

by gymshoe » Wed, 29 Apr 2009 06:09:04 GMT


 see:
 http://www.anddev.org/starting_intent_from_preferences_screen-t4505.html 


This invokes an Intent directly from Preferences XML which is handy.
(Perhaps you could specify ACTION_GET_CONTENT to return a value to
your app, although I have not tried this.)  Invoking the intent works
OK internally, but I have not been able to invoke an activity outside
of my application. For instance, I have not been able to invoke the
generic phone Dialer. I have only been able to invoke activities
defined in my manifest file.  This doesn't seem fair since you can
invoke outside activities through java code using intents...

br,
Jim




--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. New Posting at funfashion4u (on 16 Apr 09)

alfred-e-obama-mad< http://www.***.com/ ;
Airplane
Door Open < http://www.***.com/ ; Airplane
Crash-6 < http://www.***.com/ ;
Airplane
Crash-5 < http://www.***.com/ ;
Airplane
Crash-4 < http://www.***.com/ ;
Airplane
Crash-3 < http://www.***.com/ ;
Airplane
Crash-2 < http://www.***.com/ ;
Airplane
Crash-1 < http://www.***.com/ ;
Aerotechnics
Flight < http://www.***.com/ ;
adverti{*filter*}t
on tank< http://www.***.com/ {*filter*}t-on-tank.html>
Adidas
Aderti{*filter*}t< http://www.***.com/ {*filter*}t.html>
A
kid superman < http://www.***.com/ ;
Elephant
Crowd < http://www.***.com/ ; A Car
Crash in 1912< http://www.***.com/ ;
4
Wheel Drive < http://www.***.com/ ; 2
Dogs Kissing < http://www.***.com/ ;
Vampires < http://www.***.com/ ;
Tuba< http://www.***.com/ ; Navy
CHief and 
Seaman< http://www.***.com/ ;
Hobbies
of Darth 
Vader< http://www.***.com/ ;
Reasons
not to join the
empire...< http://www.***.com/ ;
Redneck
Jedi < http://www.***.com/ ; Star Wars
Xmas < http://www.***.com/ ;

--~--~---------~--~----~------------~-------~--~----~

2. how to get media from MediaStore

Hello,

I`d like to implememt media list for SoundRecorder which is open_src
app.

But I`ve found some Runtime error.


I`ve insert media file into the MediaStore.Audio.Media using
'addToMediaDB(File file)'

===============================================================

private Uri addToMediaDB(File file) {
        Resources res = getResources();
        ContentValues cv = new ContentValues();
        long current = System.currentTimeMillis();
        long modDate = file.lastModified();
        Date date = new Date(current);
        SimpleDateFormat formatter = new SimpleDateFormat(
                res.getString(R.string.audio_db_title_format));
        String title = formatter.format(date);

        // Lets label the recorded audio file as NON-MUSIC so that the
file
        // won't be displayed automatically, except for in the
playlist.
        cv.put(MediaStore.Audio.Media.IS_MUSIC, "0");

        cv.put(MediaStore.Audio.Media.TITLE, title);
        Log.d(MediaStore.Audio.Media.TRACK.toString
(),MediaStore.Audio.Media.TRACK.toString());
        cv.put(MediaStore.Audio.Media.DATA, file.getAbsolutePath());
        cv.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current /
1000));
        cv.put(MediaStore.Audio.Media.DATE_MODIFIED, (int) (modDate /
1000));
//        cv.put(MediaStore.Audio.MediaColumns.DURATION,
mRecordingLength);
        cv.put(MediaStore.Audio.Media.MIME_TYPE, MIME_TYPE);
        cv.put(MediaStore.Audio.Media.ARTIST,
                res.getString(R.string.audio_db_artist_name));
        cv.put(MediaStore.Audio.Media.ALBUM,
                res.getString(R.string.audio_db_album_name));
        Log.d(TAG, "Inserting audio record: " + cv.toString());
        ContentResolver resolver = getContentResolver();
        Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        Log.d(TAG, "ContentURI: " + base);
        Uri result = resolver.insert(base, cv);
        Log.e(TAG, result.toString());
        if (result == null) {
            new AlertDialog.Builder(this)
                .setTitle(R.string.app_name)
                .setMessage(R.string.error_mediadb_new_record)
                .setPositiveButton(R.string.button_ok, null)
                .setCancelable(false)
                .show();
            return null;
        }
        if (getPlaylistId(res) == -1) {
            createPlaylist(res, resolver);
        }
        int audioId = Integer.valueOf(result.getLastPathSegment());
        addToPlaylist(resolver, audioId, getPlaylistId(res));

        // Notify those applications such as Music listening to the
        // scanner events that a recorded audio file just created.
        sendBroadcast(new Intent
(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result));
        return result;
    }

==========================================================================

and I`ve put all of my files from sdcard.

==========================================================================

private void makePlaylist()
        {
                String[] cols = new String[] {
                MediaStore.Audio.Playlists._ID,
                MediaStore.Audio.Playlists.NAME
        };

                String status = Environment.getExternalStorageState();
                Uri uri;

        if (status.equals(Environment.MEDIA_MOUNTED))
                list_path = new File("/sdcard");
        else
                list_path = new File("/data/sec_media");

        File f_list[] = list_path.listFiles();

        f_len = f_list.length;

        for(int i=0;i < f_len ; i++){
                uri = addToMediaDB(f_list[i]);
        }
    }

==========================================================================

According to logs, media files was in MediaStore.Audio.Media

==========================================================================

02-25 02:13:20.385: DEBUG/SoundRecorder(1057): Inserting audio record:
is_music=0 mime_type=audio/amr artist=Your recordings title=2009-02-25
02:13:20 _data=/sdcard/recording13246.amr date_modified=1235030668
album=Audio recordings date_added=1235528000

02-25 02:13:20.385: DEBUG/SoundRecorder(1057): ContentURI:
content://media/external/audio/media

02-25 02:13:20.415: ERROR/SoundRecorder(1057): 
content://media/external/audio/media/322

==========================================================================

I thought "322" was _ID.

However when I excute program, error has occured.

I`d like show my audio file through ListView.

==========================================================================

public class MyPlaylist extends ListActivity {
        SoundRecorder mSr;
        Uri playlist_uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

        String[] projection = new String[] {
                        MediaStore.Audio.Media.TITLE,
                        MediaStore.Audio.Media.ARTIST
         };

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                // TODO Auto-generated method stub
                super.onCreate(savedInstanceState);

                setContentView(R.layout.playlist);
                Log.e("Playlist","onCreate");

                Cursor cursor = managedQuery(playlist_uri, projection, null, 
null,
null);

        // Used to map notes entries from the database to views
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.play_row, cursor, new String[]
{MediaStore.Audio.Media.TITLE }, new int[] {R.id.text1});
        setListAdapter(adapter);
        }
}

==========================================================================

and here are error message.

==========================================================================

02-25 02:13:24.065: ERROR/AndroidRuntime(1057): Caused by:
java.lang.IllegalArgumentException: column '_id' does not exist

==========================================================================

I couldn`t find any solutions.

I think there are some problem when I`m using content provider.

But for me, it is very difficult to understand.

Could you please give me a solution?

--~--~---------~--~----~------------~-------~--~----~

3. Problem with detecting onTouchEvent()

4. How to terminate an APK on emulator?

5. Get active apps displayed on screen

6. Developing absolute layout - no drag drop click drag in eclipse ??

7. PackageManager.installPackage(Uri packageURI) error on Androdi 1.5 SDK