我需要将使用我的应用程序拍摄的照片保存在特定文件夹中.我已经阅读了很多这个问题的解决方案,但我无法使它们中的任何一个工作,所以我寻求帮助.
MainActivity.java
public void onClick(View v) {
Intent camera = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
//Folder is already created
String dirName = Environment.getExternalStorageDirectory().getPath()
+ "/MyAppFolder/MyApp" + n + ".png";
Uri uriSavedImage = Uri.fromFile(new File(dirName));
camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
startActivityForResult(camera, 1);
n++;
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud) android android-sdcard android-gallery android-camera-intent
我db.sqlite在Asset文件夹中有我的文件,当我尝试打开它时出现此错误:
android.database.sqlite.SQLiteCantOpenDatabaseException:未知错误(代码14):无法打开数据库
我尝试了不同的路径和名称(有和没有扩展名),但我不能使它工作.
package com.example.APP.db;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
public class DataBaseHelper extends SQLiteOpenHelper {
// The Android's default system path of your application database.
private static String DB_PATH = "/data/data/com.example.APP/databases/";
private static String DB_NAME = "app";
private SQLiteDatabase myDataBase;
private final Context myContext;
/**
* Constructor Takes and keeps a reference of the passed context in order …Run Code Online (Sandbox Code Playgroud) 我正在使用Mosquitto和Paho的Python实现来尝试传达几个程序.当我使用最后一个功能时,我遇到了一些麻烦.我的代码是这样的:
会员键:
import paho.mqtt.client as mqtt
def on_message(client, userdata, msg):
print 'Received: ' + msg.payload
client = mqtt.Client()
client.on_message = on_message
client.connect('localhost', 1883)
client.subscribe('hello/#')
client.loop_forever()
Run Code Online (Sandbox Code Playgroud)
出版商:
import paho.mqtt.client as mqtt
client = mqtt.Client()
client.will_set('hello/will', 'Last will', 0, False)
client.connect('localhost', 1883)
client.publish('hello/world', 'Regular msg', 0, False)
client.disconnect()
Run Code Online (Sandbox Code Playgroud)
输出:
Received: Last will
Run Code Online (Sandbox Code Playgroud)
我应该只接收常规消息,因为我client.disconnect()用来关闭连接.如果我评论该will_set行,我会收到常规消息.我也尝试在同一主题上发布它们并且它不起作用.