Example usage for android.media RingtoneManager EXTRA_RINGTONE_INCLUDE_DRM

List of usage examples for android.media RingtoneManager EXTRA_RINGTONE_INCLUDE_DRM

Introduction

In this page you can find the example usage for android.media RingtoneManager EXTRA_RINGTONE_INCLUDE_DRM.

Prototype

String EXTRA_RINGTONE_INCLUDE_DRM

To view the source code for android.media RingtoneManager EXTRA_RINGTONE_INCLUDE_DRM.

Click Source Link

Document

Given to the ringtone picker as a boolean.

Usage

From source file:com.example.mydemos.view.RingtonePickerActivity.java

/** Called when the activity is first created. */
@Override/*from w w w.jav  a 2s  .c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.ringtone_picker);
    CharSequence sysTitle = (CharSequence) getResources().getText(R.string.sys_tone);
    CharSequence MusicTitle = (CharSequence) getResources().getText(R.string.sd_music);
    CharSequence RecordTitle = (CharSequence) getResources().getText(R.string.record_tone);
    Intent intent = getIntent();
    toneType = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);

    Log.e("duwenhua", "ringPick get toneType:" + toneType);

    //! by duwenhua
    //if(toneType == RingtoneManager.TYPE_RINGTONE_SECOND)
    //    toneType = RINGTONE_TYPE;

    //! by duwenhua
    mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
    mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //Log.i("lys", "mUriForDefaultItem == " + mUriForDefaultItem);
    if (savedInstanceState != null) {
        mSelectedId = savedInstanceState.getLong(SAVE_CLICKED_POS, -1);
    }
    //Log.i("lys", "mUriForDefaultItem 1== " + mUriForDefaultItem+", mSelectedId =="+mSelectedId);      
    mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
    mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI);
    //if(mUriForDefaultItem != null)
    //{
    //    mSelectedId = ContentUris.parseId(mUriForDefaultItem);
    //}

    //Log.i("lys", "RingtonePickerActivity.java onCreate mExistingUri == " + mExistingUri);   
    //String action = getIntent().getAction();
    //Log.i("lys", "PT Intent action == " + action);

    if (toneType == NOTIFICATION_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_NOTIFICATION_URI;
    } else if (toneType == RINGTONE_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI;
    } else if (toneType == ALARM_TYPE) {
        mUriForDefaultItem = Settings.System.DEFAULT_ALARM_ALERT_URI;
    }

    if (isAvailableToCheckRingtone() == true) {
        Ringtone ringtone_DefaultItem = checkRingtone_reflect(this, mUriForDefaultItem, toneType);
        if (ringtone_DefaultItem != null && ringtone_DefaultItem.getUri() != null) {
            mUriForDefaultItem = ringtone_DefaultItem.getUri();
            Log.i("lys", "RingtoneManager.getRingtone  mUriForDefaultItem== " + mUriForDefaultItem);
        } else {
            //mUriForDefaultItem = 'content/medial/';
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard start */
            String originalRingtone = Settings.System.getString(getApplicationContext().getContentResolver(),
                    "ringtone_original");
            if (originalRingtone != null && !TextUtils.isEmpty(originalRingtone)) {
                mUriForDefaultItem = Uri.parse(originalRingtone);
                Log.e("liyang", "select riongtone error  ,change to originalRingtone == " + mExistingUri);
            }
            /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard end */
            Log.i("lys", "mUriForDefaultItem set as default mUriForDefaultItem== 222");
        }

        if (mExistingUri != null) {
            Ringtone ringtone = checkRingtone_reflect(this, mExistingUri, toneType);
            if (ringtone != null && ringtone.getUri() != null) {
                //mUriForDefaultItem = ringtone.getUri(); 
                mExistingUri = ringtone.getUri();
                Log.i("lys", "RingtoneManager.getRingtone  mExistingUri== " + mExistingUri);
            } else {
                mExistingUri = mUriForDefaultItem;
                Log.i("lys", "mExistingUri set as default mExistingUri== " + mExistingUri);
            }
        }
    }

    boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, false);
    Log.e("lys", "includeDrm ==" + includeDrm);
    mRingtoneManager = new RingtoneManager(this);
    mRingtoneManager.setIncludeDrm(includeDrm);
    if (toneType != -1) {
        mRingtoneManager.setType(toneType);
    }

    setVolumeControlStream(mRingtoneManager.inferStreamType());
    //   toneActivityType = mRingtoneManager.getActivityType();
    if (toneType == ALARM_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.alarm_tone);
    } else if (toneType == NOTIFICATION_TYPE) {
        sysTitle = (CharSequence) getResources().getText(R.string.notification_tone);
    }

    listView = new ListView(this);
    listView.setOnItemClickListener(this);
    //listView.setBackgroundColor(#ff5a5a5a);
    listView.setFastScrollEnabled(true);
    //listView.setFastScrollAlwaysVisible(true);
    listView.setEmptyView(findViewById(android.R.id.empty));
    //mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);

    //mHasDefaultItem = true; //temp
    if (mHasDefaultItem) {
        //chengcheng
        addDefaultStaticItem(listView, com.android.internal.R.string.ringtone_default);

    }

    setDefaultRingtone();

    if (mHasSilentItem) {
        // chengcheng
        addSilendStaticItem(listView, com.android.internal.R.string.ringtone_silent);
    }
    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mAudioFocusListener = new OnAudioFocusChangeListener() {
        public void onAudioFocusChange(int focusChange) {

        }
    };

    okBtn = (Button) findViewById(R.id.ok);
    okBtn.setOnClickListener(this);
    cancelBtn = (Button) findViewById(R.id.cancel);
    cancelBtn.setOnClickListener(this);

    TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
    mTabHost.addTab(mTabHost.newTabSpec("tab_system").setIndicator(sysTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_music").setIndicator(MusicTitle, null).setContent(this));
    mTabHost.addTab(mTabHost.newTabSpec("tab_record").setIndicator(RecordTitle, null).setContent(this));
    mTabHost.setCurrentTab(0);
    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            // stopMediaPlayer();
            createTabContent(tabId);
        }
    });
}

From source file:com.android.mms.ui.MessageUtils.java

public static void selectRingtone(Context context, int requestCode) {
    if (context instanceof Activity) {
        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, false);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_MORE_RINGTONES, false);
        intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, context.getString(R.string.select_audio));
        if (FeatureOption.MTK_DRM_APP) {
            intent.putExtra(OmaDrmStore.DrmIntentExtra.EXTRA_DRM_LEVEL, OmaDrmStore.DrmIntentExtra.LEVEL_SD);
        }/*  w  w w. ja v  a 2 s .com*/
        ((Activity) context).startActivityForResult(intent, requestCode);
    }
}