-
Notifications
You must be signed in to change notification settings - Fork 2
/
URInterop.java
43 lines (35 loc) · 1.5 KB
/
URInterop.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.unified.intenttester;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.widget.Toast;
import java.util.List;
public class URInterop
{
public static final String ACTION_URI_SEND = "com.unifiedremote.ACTION_URI_SEND";
public static final String ACTION_URI_CONFIGURE = "com.unifiedremote.ACTION_URI_CONFIGURE";
public static final String EXTRA_URI = "com.unifiedremote.EXTRA_URI";
public static void configure(Activity activity, int requestCode) {
Intent intent = new Intent(ACTION_URI_CONFIGURE);
// verify that the intent resolves (i.e Unified Remote is installed)
PackageManager packageManager = activity.getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;
if (isIntentSafe) {
activity.startActivityForResult(intent, requestCode);
} else {
Toast.makeText(activity, "Unified Remote not installed...", Toast.LENGTH_LONG).show();
}
}
public static String result(Intent data) {
if (data != null)
if (data.hasExtra(EXTRA_URI))
return data.getStringExtra(EXTRA_URI);
return "";
}
public static void send(Context context, String uri) {
context.sendBroadcast(new Intent(ACTION_URI_SEND).putExtra(EXTRA_URI, uri));
}
}