【问题标题】:Dynamically change intent URI in SharedPreferences?在 SharedPreferences 中动态更改意图 URI?
【发布时间】:2014-03-06 07:39:59
【问题描述】:

我的用户可以从“设置”屏幕跳转到 Google Play 对我的应用进行评分,方法是点击启动意图的首选项:

在 XML 中:

<Preference
    android:title="@string/prefRate"
    android:summary="@string/prefRateHint">
    <intent android:action="android.intent.action.VIEW"
        android:data="market://details?id=app.package.name" />
</Preference>

在代码中:

public class SettingsActivity extends PreferenceActivity {
         @Override
         protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         addPreferencesFromResource(R.xml.prefs);
    }
}

现在我打算上传到商店 URL 不同的亚马逊。有没有办法在显示设置屏幕之前以编程方式更改 SharedPreferences 中的意图 URL?

【问题讨论】:

    标签: android


    【解决方案1】:

    示例: 在首选项文件中是链接,您想将其更改为另一个并更改可见文本(标题)

    <Preference
        android:key="my_key"
        android:title="@string/originalTitle">
        <intent android:action="android.intent.action.VIEW"
            android:data="https://originallink" />
    </Preference>
    
    Intent intent = new Intent();
    intent.setAction("android.intent.action.VIEW");
    intent.setData(Uri.parse("https://newlink"));
    getPreferenceScreen().findPreference("my_key").setIntent(intent);
    getPreferenceScreen().findPreference("my_key").setTitle(getString(R.string.newTitle));
    

    【讨论】:

      【解决方案2】:

      它会在您的代码中添加几个字节,但是拥有两个单独的 prefs_play、prefs_amazon 文件并在您发现它们正在使用哪个存储时建立引用呢?无论如何,这将是我最初对服务进行测试时得出的快速而肮脏的方式。

      【讨论】:

      • 应该想到的,需要更多的咖啡。谢谢!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-19
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-31
      相关资源
      最近更新 更多