Commit 8adfea4f authored by Libin Lu's avatar Libin Lu Committed by GitHub

Merge pull request #449 from cooperka/patch-2

Support Android activity aliases
parents 3f5c41ed 613b3462
...@@ -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