回答編集履歴
2
コード整備
test
CHANGED
@@ -18,12 +18,9 @@
|
|
18
18
|
PackageManager manager = getPackageManager();
|
19
19
|
List<PackageInfo> infoList = manager.getInstalledPackages(PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES);
|
20
20
|
for (PackageInfo info : infoList) {
|
21
|
-
LaunchItem oLaunchItem = null;
|
22
|
-
if (manager.getLaunchIntentForPackage(info.packageName)
|
21
|
+
if (manager.getLaunchIntentForPackage(info.packageName) == null) continue;
|
23
|
-
|
22
|
+
if (info.packageName == packageName) continue;
|
24
|
-
|
23
|
+
return manager.getLaunchIntentForPackage(packageName).getComponent().getClassName() + "";
|
25
|
-
}
|
26
|
-
}
|
27
24
|
}
|
28
25
|
return "";
|
29
26
|
}
|
1
コード整備
test
CHANGED
@@ -1,3 +1,31 @@
|
|
1
1
|
`Intent#setClassName`を使用し、パッケージ名とアクティビティ名を指定すれば良いはずです。
|
2
2
|
ただ、Gmail側のアクティビティ名は把握できていませんので、下記を参考に調査してみてください。
|
3
3
|
参考: [Android開発 他のアプリを立ち上げるための方法 #アプリ - Qiita](https://qiita.com/xu1718191411/items/25faefe055ebb315d041)
|
4
|
+
|
5
|
+
```java
|
6
|
+
public class MainActivity {
|
7
|
+
private final String GMAIL_PACKAGE_NAME = "com.google.android.gm";
|
8
|
+
@Override public void onCreate (Bundle savedInstanceState) {
|
9
|
+
String GMAIL_CLASS_NAME = getPackageClassName(GMAIL_PACKAGE_NAME);
|
10
|
+
if (GMAIL_CLASS_NAME == "") {
|
11
|
+
// 取得できなかったときのエラー処理
|
12
|
+
}
|
13
|
+
Intent intent = new Intent(Intent.ACTION_SENDTO);
|
14
|
+
intent.setClassName(GMAIL_PACKAGE_NAME, GMAIL_CLASS_NAME);
|
15
|
+
startActivity(intent);
|
16
|
+
}
|
17
|
+
private String getPackageClassName (String packageName) {
|
18
|
+
PackageManager manager = getPackageManager();
|
19
|
+
List<PackageInfo> infoList = manager.getInstalledPackages(PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES);
|
20
|
+
for (PackageInfo info : infoList) {
|
21
|
+
LaunchItem oLaunchItem = null;
|
22
|
+
if (manager.getLaunchIntentForPackage(info.packageName) != null) {
|
23
|
+
if (info.packageName == packageName) {
|
24
|
+
return manager.getLaunchIntentForPackage(packageName).getComponent().getClassName() + "";
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
return "";
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|