-6

I want to make an android app that can be used as a default application for opening a certain kind of link (like if I click http://facebook.com it will show me suggested app to open that link, browser or facebook's app)

Amy
  • 1,114
  • 13
  • 35

2 Answers2

1

These are called Implicit Intents

Assume you want to open your app on web link click with link "myApp://someapp"

then in your App Manifest

<activity android:name="MyActivity">
    <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="myApp" android:host="path" />
    </intent-filter>
</activity>

Whenever you click the above link, it will suggest to open your app.

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
1

If you want to developed application that allow the other application to complete the action using your application, for example in your case you want to handle the any of url user click, your application will be listed for complete the action. You have to create the activity that will handle the deep linking. For that you need to add some attributes to your handle activity in your android manifest. see below example

The following XML snippet shows how you might specify an intent filter in your manifest for deep linking. The URIs that start with “http”

<activity
    android:name="com.example.android.BrowseActivity"
    >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
        <data android:scheme="http"
              android:host="www.example.com"
              android:pathPrefix="/gizmos" />
        <!-- note that the leading "/" is required for pathPrefix-->
        <!-- Accepts URIs that begin with custom url "example://gizmos” -->
        <data android:scheme="com.example.android"
              android:host="gizmos" />
    </intent-filter>
</activity>

Once you've added intent filters with URIs for activity content to your app manifest, Android is able to route any Intent that has matching URIs to your app at runtime.

Once the system starts your activity(BrowseActivity) through an intent filter, you can use data provided by the Intent to determine what you need to render. Call the getData() and getAction() methods to retrieve the data and action associated with the incoming Intent. You can call these methods at any time during the lifecycle of the activity, but you should generally do so during early callbacks such as onCreate() or onStart().

Here’s a snippet that shows how to retrieve data from an Intent inside BrowseActivity:

@Override 
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent intent = getIntent();
    String action = intent.getAction();
    Uri data = intent.getData();
} 

Let me know if you need more help on this point thank you.

rekire
  • 47,260
  • 30
  • 167
  • 264
Bhavdip Sagar
  • 1,951
  • 15
  • 27
  • I have update the code now it will handle both custom and http URL – Bhavdip Sagar May 12 '15 at 06:24
  • done let me know fine. – Bhavdip Sagar May 12 '15 at 06:32
  • cool I would like it thank you. – Bhavdip Sagar May 12 '15 at 06:35
  • First, id like to say thanks to all of you who have answered my question, and its wonderfull – Hardo Newbie May 12 '15 at 09:37
  • @BhavdipPathar so if i open http://www.example.com/gizmos/123456 and i want to get the code after the gizmos' slash (in this case is 123456) how can i get it ? can i get it from intent.getData() ? – Hardo Newbie May 12 '15 at 10:07
  • I think you receive the URI path not the content of that page I mean " you suppose to receiver such like example.com/gizmos/123456343 or example.com/gizmos/123456783. when you click on any of the url in your device it will open your activity and inside you activity getData() you will receive the URL not the actual data. – Bhavdip Sagar May 12 '15 at 10:24
  • Thanks ! i understand it now ! so if i want to get the data i need from the url, i just have to use the String Editing Function, like Mid, left , right. – Hardo Newbie May 12 '15 at 11:08