How to start and choose an application

The purpose of this application is to implicitly activate a separate application to view the URL "http://www.google.com". So, App Chooser should appear and let me choose between at least two browsers: by default, which will show me the site www.google.com and another simple “browser” that just shows me the URL. The problem is that App chooser does not appear when I use implicit activity. Perhaps I wrote the wrong intent filters for the second "simple browser".

private void startImplicitActivation() {

    Log.i(TAG, "Entered startImplicitActivation()");

    // TODO - Create a base intent for viewing a URL 
    // (HINT:  second parameter uses parse() from the Uri class)
    Uri adress = Uri.parse(URL);
    Intent intentUrlView = new Intent(Intent.ACTION_VIEW, adress);

    // TODO - Create a chooser intent, for choosing which Activity
    // will carry out the baseIntent. Store the Intent in the 
    // chooserIntent variable below. HINT: using the Intent class' 
    // createChooser())
    Intent chooserIntent = Intent.createChooser(intentUrlView, CHOOSER_TEXT);
    //chooserIntent = null;

    Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
    // TODO - Start the chooser Activity, using the chooser intent
    if (intentUrlView.resolveActivity(getPackageManager()) != null) {
        startActivity(chooserIntent);
    }
}

MANIFESTO

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="course.labs.intentslab.mybrowser"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MyBrowserActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <!-- TODO - Add necessary intent filter information so that this
                            Activity will accept Intents with the 
                            action "android.intent.action.VIEW" and with an "http" 
                            schemed URL -->
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http" />
        <category android:name="android.intent.category.BROWSABLE" />
        </activity>
    </application>

+4
source share
5 answers

Seriously, you have a GUI editor for the manifest.

it

<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<category android:name="android.intent.category.BROWSABLE" />

<intent-filter>, . :

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

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

        <!-- TODO - Add necessary intent filter information so that this
                        Activity will accept Intents with the 
                        action "android.intent.action.VIEW" and with an "http" 
                        schemed URL -->
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>

</activity>

:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="http" />
            <data android:scheme="https" />
            <data android:scheme="about" />
            <data android:scheme="javascript" />
        </intent-filter>
        <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:scheme="https" />
            <data android:scheme="inline" />
            <data android:scheme="file" />
            <data android:mimeType="text/html" />
            <data android:mimeType="text/plain" />
            <data android:mimeType="application/xhtml+xml" />
            <data android:mimeType="application/vnd.wap.xhtml+xml" />
        </intent-filter>
+8

, 3- HandHeld Android. , , AndroidManifest.xml .

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />

, AndroidUnit,

, - ActionListener .

Intent baseIntent = new Intent(Intent.ACTION_VIEW);
        baseIntent.setData(Uri.parse(URL));

Intent chooserIntent = Intent.createChooser(baseIntent, "Select Application");

Coursera . , .

+18

:

Intent phoneCall=new Intent(Intent.ACTION_DIAL,Uri.fromParts("tel",contactNumber,null));
            //Intent sms=new Intent(Intent.ACTION_VIEW,Uri.parse("sms:"+contactNumber));
            Intent whatsapp=new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:"+contactNumber));
            Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
            builder.appendPath("time");
            ContentUris.appendId(builder, Calendar.getInstance().getTimeInMillis());
            Intent calendarIntent = new Intent(Intent.ACTION_VIEW).setData(builder.build());

            Intent chooser=Intent.createChooser(whatsapp,"chooser??");//default action
            chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS,new Intent[]{phoneCall,calendarIntent});//additional actions
            startActivity(chooser);
+1
source

Here is how I do it:

Step 1: first in rows,

<string name="webklink">&lt;a href="http://www.google.com">SomeLink&lt;/a></string>

Step 2: My layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/webklink"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Step 3: Get the link from the strings.

public class OpenWeb extends Activity {


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

        TextView someLink = (TextView)findViewById(R.id.textView1);
        if(someLink!=null){

            someLink.setMovementMethod(LinkMovementMethod.getInstance());
            someLink.setText(Html.fromHtml(getResources().getString(R.string.webklink)));
        }

    }
}

Hope this helps .. :)

0
source

You need to start lab3a_MyBrowserbefore launch lab3a_IntentsLabso that the browser is installed on your phone. Then it will be visible to your choice.

0
source

Source: https://habr.com/ru/post/1527101/


All Articles