我从远程数据库中获取了一个Base64字符串的位图,(encodedImage
是用Base64表示图像的字符串):
profileImage = (ImageView)findViewById(R.id.profileImage);
byte[] imageAsBytes=null;
try {
imageAsBytes = Base64.decode(encodedImage.getBytes());
} catch (IOException e) {e.printStackTrace();}
profileImage.setImageBitmap(
BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length)
);
Run Code Online (Sandbox Code Playgroud)
profileImage是我的ImageView
好的,但是我必须在显示我ImageView
的布局之前调整此图像的大小.我必须将其调整为120x120.
有人能告诉我调整大小的代码吗?
我找到的示例无法应用于获得位图的base64字符串.
我在我的应用中使用Google通知,直到现在我在清单中完成了以下操作:
<!-- GCM -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- This app has permission to register and receive data message. -->
<!-- Creates a custom permission so only this app can receive its messages. NOTE: APP_PACKAGE.permission.C2D_MESSAGE -->
<permission android:name="com.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.permission.C2D_MESSAGE" />
<!-- END GCM -->
Run Code Online (Sandbox Code Playgroud)
它完美运行,直到我将Nexus 7更新为Android 5.0.
现在,当我尝试使用Eclipse在此设备中安装应用程序时,出现此错误:
INSTALL_FAILED_DUPLICATE_PERMISSION perm = com.myapp.permission.C2D_MESSAGE pkg …
android android-notifications google-cloud-messaging android-5.0-lollipop
我有一个表示BitMap图像的Base64字符串.
我需要再次将该String转换为BitMap图像,以便在我的Android应用程序中的ImageView上使用它
怎么做?
这是我用来将图像转换为base64字符串的代码:
//proceso de transformar la imagen BitMap en un String:
//android:src="c:\logo.png"
Resources r = this.getResources();
Bitmap bm = BitmapFactory.decodeResource(r, R.drawable.logo);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
//String encodedImage = Base64.encode(b, Base64.DEFAULT);
encodedImage = Base64.encodeBytes(b);
Run Code Online (Sandbox Code Playgroud) 可以在Java代码中动态更改此属性吗?
android:layout_marginRight
Run Code Online (Sandbox Code Playgroud)
我有一个TextView
,必须动态地将其位置改为左侧的一些像素.
如何以编程方式执行?
有人能告诉我将图像(最大200KB)转换为Base64字符串的代码吗?
我需要知道如何使用android,因为我必须添加上传图像的功能到我的主应用程序中的远程服务器,将它们作为字符串放入数据库的一行.
我在谷歌和StackOverflow中搜索,但我找不到我能负担得起的简单示例,而且我找到了一些例子,但他们并没有谈到转换成字符串.然后我需要转换为字符串以通过JSON上传到我的远程服务器.
我将一个活动号码传递给活动
然后,在这样的活动中,我有一个按钮来调用该号码,这是代码:
callButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(bundle.getString("mobilePhone")));
}
});
Run Code Online (Sandbox Code Playgroud)
出了点问题,因为当我按下按钮时没有任何反应......
我究竟做错了什么?
PD:我正在使用Android 1.5兼容项目...也许电话与1.5不兼容?
我正在开展一项活动来配置我的应用程序,我必须用一条线来划分配置窗口的各个部分.我用过这个:divider_horizontal_bright
从这个例子:
http://android.cryx.li/doku.php?id=know:settings:start
但它不起作用!当我在我的Android手机上测试时,它没有显示水平线.为什么?
我使用的是Android 2.1
我需要知道assets文件夹上文件的字符串路径,因为我使用的是需要接收字符串路径的map API,我的地图必须存储在assets文件夹中
这是我正在尝试的代码:
MapView mapView = new MapView(this);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setMapFile("file:///android_asset/m1.map");
setContentView(mapView);
Run Code Online (Sandbox Code Playgroud)
出现问题"file:///android_asset/m1.map"
因为没有加载地图.
哪个是存储在我的assets文件夹中的文件m1.map的正确字符串路径文件?
谢谢
编辑Dimitru:此代码不工作,它不能在is.read(buffer);
与IOException异常
try {
InputStream is = getAssets().open("m1.map");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
text = new String(buffer);
} catch (IOException e) {throw new RuntimeException(e);}
Run Code Online (Sandbox Code Playgroud) 我有一个处理程序的服务,必须每5秒在logcat中写入"Hello".但是它没有在logcat上写任何内容......就像服务没有执行一样,我在它上面放了一个断点,调试模式永远不会在断点上停止.
我在我的应用程序的第一个活动中启动了这项服务:
startService(new Intent(GPSLoc.this, MyServiceNotifications.class)); //enciendo el service
Run Code Online (Sandbox Code Playgroud)
我确信代码startService
已执行,因为它在启动另一个活动之前被调用,而另一个活动开始.
这是我的服务代码:
public class MyServiceNotifications extends Service {
boolean serviceStopped;
private Handler mHandler;
private Runnable updateRunnable = new Runnable() {
@Override
public void run() {
if (serviceStopped == false)
{
createNotificationIcon();
}
queueRunnable();
}
};
private void queueRunnable() {
// 600000 : cada 10 minutos, comprueba si hay nuevas notificaciones y actualiza la
// notification BAR
mHandler.postDelayed(updateRunnable, 5000);
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public …
Run Code Online (Sandbox Code Playgroud) 我有一个包含这个的html字符串:
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="spanish press" content="spain, spanish newspaper, news,economy,politics,sports">
<title></title>
</head>
<body id="body">
<!-- The following code will render a clickable image ad in the page -->
<script src="http://www.myscript.com/a"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我需要在android中将该网站显示为webview.
我试着用这一切:
webView.loadDataWithBaseURL(null, txt, "text/html", "UTF-8", null);
webView.loadDataWithBaseURL("x-data://base", txt, "text/html", "UTF-8", null);
webView.loadDataWithBaseURL("notreal/", txt, "text/htm", "utf-8",null);
Run Code Online (Sandbox Code Playgroud)
我也尝试删除DOCTYPE标签:
txt=txt.replace("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">", "");
没有人有工作.我刚刚实现了将字符串显示到webview(html代码),但不是必须使用该html代码创建的网站.
怎么了?