我的Android Java不打印照片吗?

时间:2016-01-02 15:17:35

标签: java android bitmap

我的代码用于在用户登录Facebook时获取用户照片的网址。它成功地做到了这一点但是,当我尝试将它们输出到我的应用程序中的屏幕时,没有任何反应。为什么是这样?我的代码如下:

        super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my_photos);
    Profile profile = Profile.getCurrentProfile();
     final String id= profile.getId();
    GraphRequest request = GraphRequest.newMeRequest(
            AccessToken.getCurrentAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(
                        JSONObject object,
                        GraphResponse response) {

                    JSONObject photos = object.optJSONObject("photos");
                    JSONArray data = photos.optJSONArray("data");

                    for(int i =0;i<data.length();i++) {
                        JSONObject link = data.optJSONObject(i);
                        String link2 = link.optString("picture");
                        Log.e("Photos", String.valueOf(link2));
                        URL url = null;
                        try {
                            url = new URL(link2);
                        } catch (MalformedURLException e) {
                            e.printStackTrace();
                        }
                        Bitmap src = null;
                        try {
                            src = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
                        Canvas cs = new Canvas(dest);

                        cs.drawBitmap(dest,20f,20f,null);


                    }

                }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,picture,photos{link,picture}");
    request.setParameters(parameters);
    request.executeAsync();

1 个答案:

答案 0 :(得分:0)

至少确保MySQL使用预期/需要的字符编码发送数据,并正确编码xml的特殊字符。让我们假设您的XML文档声明自己是utf-8编码。

$mysqli = new mysqli('...');
$mysqli->set_charset('utf8'); // or 'utf8m4b'
//...

echo '<markers>';
while ( $row=mysqli_fetch_assoc($result3) ) {
    echo '<museums name="', htmlspecialchars($row['name'], ENT_XML1, 'UTF-8'), '" />';
}
echo '</markers>';

但我建议使用像php XMLWriter这样的内容。

相关问题