从Play商店安装时,应用程序无法正常工作

时间:2014-07-18 20:40:28

标签: android google-play

我在我的应用中面临一个非常奇怪的问题。我使用通知通过服务将我的应用从后台带到前台。我的问题是,当我从pc安装apk文件(通过Eclipse或通过将apk复制到我的设备)时,通知工作完美。当我从Play商店(相同的apk)安装我的应用程序,并且用户点击通知时,它会启动EntryScreen的新实例并且不能用作启动器图标!知道为什么会这样吗?

提前致谢!

服务代码:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    Intent intentForeground = new Intent(getApplicationContext(),EntryScreen.class);

    intentForeground.setAction(Intent.ACTION_MAIN);

    intentForeground.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent pendint = PendingIntent.getActivity(getApplicationContext(), 0, intentForeground, PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.final_driver_notification_icon)
            .setContentTitle("...")
            .setContentText("...")
            .setContentIntent(pendint)
            .setTicker("...");

    Notification notif = mBuilder.build();

    int notID = 1;

    startForeground(notID, notif);


    return super.onStartCommand(intent, flags, startId);
}

1 个答案:

答案 0 :(得分:0)

问题可能在Manifest中,您需要在通知中打开的活动中添加launchMode。例如,如果您的活动是EntryScreen.class,请参阅清单的代码。

<activity
            android:name=".EntryScreen"
            android:launchMode="singleTask"/>