1

i have an application which associates pdf files in my Manifest(via intent-filters), so when someone click on pdf link in the default browser i can execute that action with my app and download it with a progressbar. my question is, is it a way that i can associate other files but not "hard coded" in my manifest, but to let the user choose(or write) that file extention in preferences for example and i can add it dynamically from code. i know that probably this can be done with broadcast receiver but cant find any examples or simple code for that matter. ive seen preference menu like that in bsplayer settings .. but cant post image cuz dont have enough reputation.

I will try to explain more detailed my problem, because i think that there was some misunderstanding with the answer below.

  1. i have an application which have the fallowing code in my manifest.

       <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
    
            <data android:scheme="http" />
            <data android:host="*" />
            <data android:pathPattern=".*\\.pdf" />
        </intent-filter>
    

2.i launch my app which registers .pdf files with it. so next time i click on pdf link in my browser, a window pops up, making me choose with what application should i complete that action. if i choose my application, my main activity is launched, in which i use getIntent() and my app downloads the file using progressbar.

3.the problem is that i want to download and other files like that ie. jpg, png .. etc, but giving the user a choice which ones, or even making him write the extentions for the files he wants to download using my application if clicks on link somewhere that leads to that kind of files.

4.to make this thing happen, file extensions should be added dynamically in code somewow and not in manifest. i was looking some examples for broadcast receiver, since that class can use IntentFilter class, but cant really understand what i should be doing with it.

5.My main goal: starting my app, there is layout with some spinner or edit box. the user choose/writes some extension (.dwf). that extension is now registered with my app. if the next time the user browsing internet clicks on link which leads to .dwf file he could choose to continue the action with my app. and the file should be downloaded just like the .pdf

6.sry for my bad english and some help will be appreciated. also code ;)

BlastFire
  • 317
  • 1
  • 5
  • 15

1 Answers1

0
boolean enabled=prefs.getBoolean(key, false);
int flag=(enabled ?
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
ComponentName component=new ComponentName(MyActivity.this, TargetActivity.class);

getPackageManager()
    .setComponentEnabledSetting(component, flag,
                                PackageManager.DONT_KILL_APP);

Depending upon your preference you can Disable the activity that handles the File type in your BOOT_COMPLETED Reciever. I Believe you will have to have different activities to handle different file types and then disable selectively

nandeesh
  • 24,740
  • 6
  • 69
  • 79
  • but do never ever let the user write the file type. Specify the ones your activity can handle and put the list of options to the user. – Budius Aug 15 '12 at 11:07
  • nandeesh, thank you for your answer. can you point me to a tutorial for registering certain file extension within receiver. – BlastFire Aug 15 '12 at 11:24
  • check this. http://stackoverflow.com/questions/4799576/register-new-file-type-in-android. and if my answer helped do upvote and accept – nandeesh Aug 15 '12 at 11:25
  • @nandeesh, the thing is that i dont want to use intent-filter in my manifest, but do it in the code. like using IntentFilter and adding category, view and data from code somehow. – BlastFire Aug 15 '12 at 11:42
  • but the problem with doing it in code is your app process might get stopped in th background. Then the reciever will be unregistered. It will not recieve any intents – nandeesh Aug 15 '12 at 12:01
  • @nandeesh, maybe you are right, but i need to know how this can be done. i mean i need some example code since i lack knowledge about that matter. :) – BlastFire Aug 15 '12 at 12:06