Commit 613b3462 authored by Kevin Cooper's avatar Kevin Cooper

Simplify `getMainActivityClass`

Just return the className. The old code didn't work with activity aliases. For example, when launching with `<activity-alias android:name=".SplashActivity" android:targetActivity=".MainActivity" />`, the old code would try to get the class for `SplashActivity` which threw `ClassNotFoundException`.
parent 157ad2ff
...@@ -41,16 +41,11 @@ public class FIRLocalMessagingHelper { ...@@ -41,16 +41,11 @@ public class FIRLocalMessagingHelper {
sharedPreferences = (SharedPreferences) mContext.getSharedPreferences(PREFERENCES_KEY, Context.MODE_PRIVATE); sharedPreferences = (SharedPreferences) mContext.getSharedPreferences(PREFERENCES_KEY, Context.MODE_PRIVATE);
} }
public Class getMainActivityClass() { public String getMainActivityClassName() {
String packageName = mContext.getPackageName(); String packageName = mContext.getPackageName();
Intent launchIntent = mContext.getPackageManager().getLaunchIntentForPackage(packageName); Intent launchIntent = mContext.getPackageManager().getLaunchIntentForPackage(packageName);
String className = launchIntent.getComponent().getClassName(); String className = launchIntent.getComponent().getClassName();
try { return className;
return Class.forName(className);
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
} }
private AlarmManager getAlarmManager() { private AlarmManager getAlarmManager() {
...@@ -59,8 +54,8 @@ public class FIRLocalMessagingHelper { ...@@ -59,8 +54,8 @@ public class FIRLocalMessagingHelper {
public void sendNotification(Bundle bundle) { public void sendNotification(Bundle bundle) {
try { try {
Class intentClass = getMainActivityClass(); String intentClassName = getMainActivityClassName();
if (intentClass == null) { if (intentClassName == null) {
return; return;
} }
...@@ -197,7 +192,8 @@ public class FIRLocalMessagingHelper { ...@@ -197,7 +192,8 @@ public class FIRLocalMessagingHelper {
mContext.sendOrderedBroadcast(i, null); mContext.sendOrderedBroadcast(i, null);
if(!mIsForeground || bundle.getBoolean("show_in_foreground")){ if(!mIsForeground || bundle.getBoolean("show_in_foreground")){
Intent intent = new Intent(mContext, intentClass); Intent intent = new Intent();
intent.setClassName(mContext, intentClassName);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.setAction(bundle.getString("click_action")); intent.setAction(bundle.getString("click_action"));
...@@ -232,8 +228,8 @@ public class FIRLocalMessagingHelper { ...@@ -232,8 +228,8 @@ public class FIRLocalMessagingHelper {
} }
public void sendNotificationScheduled(Bundle bundle) { public void sendNotificationScheduled(Bundle bundle) {
Class intentClass = getMainActivityClass(); String intentClassName = getMainActivityClassName();
if (intentClass == null) { if (intentClassName == null) {
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment