小编ful*_*oon的帖子

Marshmallow中的存储权限错误

在Lollipop中,下载功能在我的应用程序中运行良好,但是当我升级到Marshmallow时,我的应用程序崩溃并在我尝试从互联网下载到SD卡时出现此错误:

Neither user  nor current process has android.permission.WRITE_EXTERNAL_STORAGE
Run Code Online (Sandbox Code Playgroud)

它抱怨这行代码:

DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
Run Code Online (Sandbox Code Playgroud)

我在应用程序外的清单中拥有权限:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
Run Code Online (Sandbox Code Playgroud)

我清理并重建了项目,但它仍然崩溃.

permissions android android-6.0-marshmallow

147
推荐指数
5
解决办法
23万
查看次数

将SharedPrefs编辑器放在Utility类中?

将静态共享首选项编辑器放在实用程序类中是一个好主意/实践,这样我可以在需要时调用它吗?实用程序类中的方法如下所示:

public static SharedPreferences.Editor editor (Context context){
    final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    return sharedPrefs.edit();
}
Run Code Online (Sandbox Code Playgroud)

并在不同的类中使用它:

Utility.editor(mContext).putBoolean(categoryId, true);
Utility.editor(mContext).apply();
Run Code Online (Sandbox Code Playgroud)

java android android-sharedpreferences

5
推荐指数
1
解决办法
221
查看次数

iOS:Mac Catalyst,在其他 Mac 上测试 iOS 应用

我正在构建一个 iOS 应用程序,并且客户端想要启用在 Mac 上运行的功能。我启用了它并在我的 Mac 上按预期运行。我怎样才能让他们在他们的 Mac 上测试它?因为 TestFlight 只在 iOS 设备上运行。

macos xcode ios testflight mac-catalyst

5
推荐指数
2
解决办法
1345
查看次数

更改 Android 小部件中的 TextView 文本

我正在开发一个 android 小部件。在小部件中,我有一个文本字段和两个按钮。当我按下 button1 时,我希望文本字段显示某个文本,例如“one”,如果我单击 button2,则文本字段将显示为“2”。

onUpdate() 看起来像这样:

 @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds){ super.onUpdate(context, appWidgetManager, appWidgetIds); 

    remoteViews = new RemoteViews(context.getPackageName(), R.layout.activity_main);

    Intent intent = new Intent(context, CalculatorReceiver.class);
    intent.setAction(ACTION_WIDGET_RECEIVER);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

    PendingIntent actionPendingIntent =  PendingIntent.getBroadcast(context, 0, intent, 0);
    remoteViews.setOnClickPendingIntent(R.id.one, actionPendingIntent);
    appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); }
Run Code Online (Sandbox Code Playgroud)

onReceive() 方法如下所示:

@Override public void onReceive(Context context, Intent intent) {

    super.onReceive(context, intent);

    if(intent.getAction().equals(ACTION_WIDGET_RECEIVER)){

         Toast.makeText(context, "Hi I'm 1", Toast.LENGTH_LONG).show();

         }}
Run Code Online (Sandbox Code Playgroud)

现在,在小部件中,我只能在按下按钮时显示 Toast,但我想获取 textView 并更改其值。如何获取和更改 textView?

android widget

4
推荐指数
1
解决办法
6122
查看次数

在基本表视图单元格之间添加间距

我有基本的表格视图单元格,我想在它们之间设置一些间距.

在此输入图像描述

我试过了

cell.contentView.layoutMargins.top = 8
Run Code Online (Sandbox Code Playgroud)

cell.layoutMargins.top = 8 
Run Code Online (Sandbox Code Playgroud)

但那没用.我知道我可以创建一个自定义单元格,但我想知道如何以这种方式添加边距.

编辑:

然后我将单元格样式更改为自定义:

在此输入图像描述

并添加了一个视图,以便我可以设置一些约束

在此输入图像描述

但结果仍然相同,单元格之间没有间距,它有点忽略了自定义视图,我想因为它需要一个自定义类的单元格,但我不想这样做.

在此输入图像描述

uitableview ios swift

3
推荐指数
1
解决办法
2965
查看次数

iOS:以编程方式创建的 UINavigationController 的导航栏未扩展到安全区域

我希望导航栏扩展到以编程方式创建的 UINavigationController 中的安全区域。我正在开发一个项目,他们以编程方式创建初始视图控制器并在 SceneDelegate 中设置其导航栏:

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 
    guard let windowScene = (scene as? UIWindowScene) else { return }
    
    window = UIWindow(windowScene: windowScene)
    let initialViewController = initViewController()
    let navigationCotnroller = UINavigationController(rootViewController: initialViewController)
    navigationBarConfiguration(navigationCotnroller)
    
    window?.rootViewController = navigationCotnroller
    window?.makeKeyAndVisible()
    
}

private func initViewController () -> UIViewController {
    let view_controller_to_be_returned = DeviceSearchVC()
    view_controller_to_be_returned.title = "Devices"
    return view_controller_to_be_returned
}

private func navigationBarConfiguration (_ controller: UINavigationController) {
    controller.navigationBar.prefersLargeTitles = true
    controller.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
    controller.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: …
Run Code Online (Sandbox Code Playgroud)

uinavigationcontroller navigationbar ios swift safearealayoutguide

3
推荐指数
1
解决办法
2241
查看次数

在Android上使用Retrofit的JSON响应

我可以使用OkHttp3获取JSON响应,我想使用Retrofit来解析响应以从中获取名称和图像.我查看了Retrofit网站和一些教程,但仍然不清楚这个过程.

这是我的OkHttp3代码来获取JSON响应:

 Request request = new Request.Builder().url(url).build();

    client.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Call call, IOException e) {
            e.printStackTrace();

        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

            Headers responseHeaders = response.headers();
            for (int i = 0, size = responseHeaders.size(); i < size; i++) {
                System.out.println(responseHeaders.name(i) + responseHeaders.value(i));
            }
            System.out.println(response.body().string());
            String jData = response.body().string();// I want to parse jData using Retrofit

        }
    });
Run Code Online (Sandbox Code Playgroud)

JSON响应如下所示:

在此输入图像描述

我想得到每位艺术家的名字,身份证和形象,非常感谢任何帮助.

UPDATE

我添加了Pojo类,其中一个是Item类:

public class …
Run Code Online (Sandbox Code Playgroud)

android json retrofit okhttp3

-1
推荐指数
1
解决办法
6910
查看次数