小编yea*_*man的帖子

如何在Android中安全存储访问令牌和秘密?

我将使用oAuth从谷歌获取邮件和联系人.我不想每次都要求用户登录以获取访问令牌和密码.根据我的理解,我需要将它们与我的应用程序一起存储在数据库中SharedPreferences.但我有点担心安全问题.我读过你可以加密和解密令牌,但是攻击者很容易反编译你的apk和类并获得加密密钥.
在Android中安全存储这些令牌的最佳方法是什么?

security android oauth token preferences

114
推荐指数
4
解决办法
6万
查看次数

多次调用startforeground?

我已经创建了一个发送电子邮件的服务(EmailService)...每当我需要通过我的应用程序发送电子邮件时,它启动服务并通过意图传递电子邮件的ID ...

我正在使用startforeground(id_of_email, mynotifcation);它来防止它被杀死,并向用户显示电子邮件发送状态的通知.

我需要允许用户当时发送多封电子邮件,因此当用户需要发送另一封电子邮件时,它再次startservice使用新的意图(不同的电子邮件ID)进行调用...所以它startforeground(new_id_of_email, mynotifcation);再次调用.

问题是新的调用startforeground覆盖了以前的通知...(因此用户丢失了先前的通知,并且不知道他以前的电子邮件发生了什么)

service android

12
推荐指数
1
解决办法
3470
查看次数

点击通知进入当前活动

我正在使用这个解决方案:如何使通知意图恢复而不是制定新的意图?

当我正常运行我的应用程序时工作正常..但我的应用程序有共享功能.

当我选择要从图库应用程序共享的图像并在我的活动中打开它时,我在活动中创建通知.我希望当用户点击通知时,它会打开现有活动(由图库应用打开)

问题是,当我点击通知时,它不会恢复该活动,而是打开活动的新实例或之前已打开的另一个实例

编辑:更多解释

我的应用程序名为ShareApp,活动名为ShareActivity,问题是当我通过图库应用程序打开ShareActivity时,会在图库应用程序任务的堆栈顶部创建一个ShareActivity实例.现在,当我创建指向我的ShareActivity的通知时,我使用了intent:

Intent intent = new Intent(this, ShareActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Run Code Online (Sandbox Code Playgroud)

问题是,当我点击通知时,它指向ShareApp任务的堆栈中的ShareActivity实例,而不是gallery app任务的堆栈.

任何想法如何指向正确的任务的堆栈?

编辑2:我的代码

        int defaults = Notification.FLAG_NO_CLEAR;
        NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle(getString(R.string.app_name))
                        .setContentText(text)
                        .setDefaults(defaults);
        Intent intent = new Intent(this, this.getClass());
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

        mBuilder.setContentIntent(pendingIntent);
        NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(_ID, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)

编辑3:adb shell dumpsys活动(在应用David代码之后/sf/answers/1183112241/)

我的应用程序名为shareApp,我的活动是ShareActivity

在点击通知之前:

Main stack:
    TaskRecord{41965708 #6 A com.android.gallery3d}
    Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery3d/.app.Gallery bnds=[364,50][108,108]}
      Hist #2: ActivityRecord{417ccc28 com.yeahman.shareapp/.ShareActivity}
        Intent …
Run Code Online (Sandbox Code Playgroud)

notifications android

11
推荐指数
3
解决办法
3万
查看次数

ondestroy不总是被称为?

我已经在onDestroy我的活动中添加了一些缓存清理代码,但大部分时间代码都没有执行,除非我通过显式完成活动finish().

编辑:只读或onDestroyfinish()在系统资源不足时调用.那么我需要在哪里放置缓存清理代码?如果我将其放入onPause()并且用户返回应用程序,则清除缓存.我实际上是将重要的临时文件存储在不应删除的缓存中onPause.

android ondestroy

6
推荐指数
1
解决办法
9062
查看次数