Android app created to sending/receiving data using the Deep Linking.
-
Install JDK 8.
-
Install Android Studio and setup an emulador.
-
Open the Android Studio and build.
public final class MyActivity extends AppCompatActivity {
private void sendDataToClockIn() {
Uri.Builder builder = new Uri.Builder()
.scheme("clockin")
.authority("login")
.appendPath("oauth2")
.appendQueryParameter("organization", organization)
.appendQueryParameter("environment", environment)
.appendQueryParameter("email", email)
.appendQueryParameter("password", password)
.appendQueryParameter("appScheme", appScheme)
.appendQueryParameter("appName", appName)
.appendQueryParameter("appIdentifier", appIdentifier);
final Uri uri = builder.build();
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent = intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_ACTIVITY_NO_HISTORY);
final PackageManager packageManager = mContext.getPackageManager();
final List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
if (activities.size() > 0) {
startActivity(intent);
}
}
}
<manifest>
<application>
<!-- ... -->
<activity android:name=".ReceiveDataActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="myscheme" android:host="clockin" />
</intent-filter>
</activity>
<!-- ... -->
</application>
</manifest>
public final class ReceiveDataActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
receiveDataFromClockIn();
}
private void receiveDataFromClockIn(final Intent intent) {
final Intent intent = getIntent();
if (intent == null) {
return null;
}
final Uri intentData = intent.getData();
if (intentData == null) {
return null;
}
intent.setData(null);
final String host = intentData.getHost();
if (host == null || !host.equals("clockin")) {
return null;
}
final String clockInsStr = intentData.getQueryParameter("data");
if (clockInsStr == null) {
return null;
}
TypeToken type = new TypeToken<List<ClockInObject>>(){}.getType();
List<ClockInObject> clockIns = new Gson().toJson(clockInsStr, type);
// ...
}
}
public final class ClockInObject {
@SerializedName("name")
private String name;
@SerializedName("data")
private ClockInDataObject data;
}
public final class ClockInDataObject {
@SerializedName("clockinCoordinates")
private String clockinCoordinates;
@SerializedName("clockinDatetime")
private String clockinDatetime;
@SerializedName("employeePersonId")
private String employeePersonId;
//...
}
For more implementation details just build the example.
Information about deep linking protocol can be found on Wiki.
A brief summary of each release can be found on the releases.
© TOTVS Labs