Android Application Development Cookbook: 93 Recipes for Building Winning Apps


Recipe 1.8 Making Your Application callable By others



Download 32,34 Mb.
Pdf ko'rish
bet40/56
Sana26.02.2022
Hajmi32,34 Mb.
#470540
1   ...   36   37   38   39   40   41   42   43   ...   56
Bog'liq
Android Application Development Cookbook

 
Recipe 1.8 Making Your Application callable By others

35
Figure 1-20 
Alternatively, you can use the 
android.content.Intent.ACTION_VIEW
constant (which evaluates 
to the same value as “
android.intent.action.VIEW
”) to call it. However, this time you will see a 
dialog asking you to choose an application to complete the action (see Figure 1-21):
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.amazon.com"));
startActivity(i);
This is because now more than one application can handle this action. 
Figure 1-21 
www.it-ebooks.info


36

ChAPter 1
Android FundAmentAls
Now go to the 
AndroidManifest.xml
file and modify the 

element:
android:name=".MyBrowserActivity"
android:label="@string/app_name" >






-->
 


The 

element in this case specifies the MIME media type that the activity is capable of 
handling. 
To call the activity with this MIME type, you have to use the 
setType()
method:
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
//---if you are using setType(), no need to use setData()---
//i.setData(Uri.parse("http://www.amazon.com"));

//---indicates the type that the target activity will handle--- 
i.setType("text/html");
i.putExtra("URL", "http://www.amazon.com");
startActivity(i);
Note that the 
setType()
method automatically clears any data you set using the 
setData()
method; hence, you do not need to use the 
setData()
method. To pass data to the activity in this 
case, you can use the 
putExtra()
method. 
The preceding code snippet will show a list of applications that are capable of handling the MIME 
type you specified (see Figure 1-22). 
To retrieve the data passed in using the 
putExtra()
method, you can use the 
getStringExtra()
method:
@Override
public void onCreate(Bundle savedInstanceState) 

super.onCreate(savedInstanceState); 
setContentView(R.layout.browser);
//Uri url = getIntent().getData();

Download 32,34 Mb.

Do'stlaringiz bilan baham:
1   ...   36   37   38   39   40   41   42   43   ...   56




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish