当前位置: 编程技术>移动开发
本页文章导读:
▪widget -notification widget ----notification
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, tickerText, System.currentTimeMillis());
//System.currentTimeMillis().........
▪ 资料IO 文件IO
final String FILE_PATH="/data/data/com.android.hymake.ecard/";
final String FILE_NAME="CARD.XML";
final String TEXT_ENCODING = "UTF-8";
File file;
FileOutputStream out;
FileInputStream in;
String display;
.........
▪ 读取raw 文件夹上的资源 读取raw 文件夹下的资源
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
/**
* This example sho.........
[1]widget -notification
来源: 互联网 发布时间: 2014-02-18
widget ----notification
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, tickerText, System.currentTimeMillis());
//System.currentTimeMillis()代表立即显示,这里是设置显示的时间
Intent intent = new Intent(this,MainActibity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);//这里的intent是如果这个notification被点击后返回到MainActivity页面
notification.setLatestEventInfo(this, title, content, contentIntent);
notificationManager.notify(R.layout.notification, notification);//第一个是notification的id,可以自己指定
所有的Notification都是由NotificationManager来管理,所以,第一步应该得到一个NotificationManager,以便管理这个Activity.
Notification notification = new Notification();
notification.defaults = Notification.DEFAULT_VIBRTE;
//当Notification出现的时候便随着振动
notification.defaults = Notification.DEFAULT_SOUND;//当Notification出现的时候便随着音乐
notification.defaults = Notification.DEFAULT_ALL;//当Notification出现的时候便随着音乐和振动
//下面是自定义的一个notification
nf =new Notification(R.drawable.icon,"带进度条的提醒",System.currentTimeMillis()) ;
nf.icon = R.drawable.icon;
nf.contentView= new RemoteViews(this.getPackageName(),R.layout.notification); //RemoteViews: 一个可以在其他应用进程中运行的类,是构造AppWidget的核心。目前,OPhone平台上的RemoteViews支持的布局(Layout)类暂时只有FrameLayout, LinearLayout和RelativeLayout,并且不支持自定义类
nf.contentView.setProgressBar(R.id.ProgressBar01, 100, 0, false);
nf.contentIntent=PendingIntent.getActivity( this, 0, new Intent(this,remoteview.class) ,0);
[2] 资料IO
来源: 互联网 发布时间: 2014-02-18
文件IO
final String FILE_PATH="/data/data/com.android.hymake.ecard/";
final String FILE_NAME="CARD.XML";
final String TEXT_ENCODING = "UTF-8";
File file;
FileOutputStream out;
FileInputStream in;
String display;
//生成保存本机名片的XML文件并显示内容
private void generateLocalECardXml(){
try {
String infoToWriter = getLocalECardInfo();
out = this.openFileOutput(FILE_NAME, MODE_PRIVATE);
out.write(infoToWriter.getBytes());
Log.i(TAG, "filewrite:"+infoToWriter);
out.close();
Log.i(TAG, "create local ecard xml file successfully!");
in = this.openFileInput(FILE_NAME);
byte[] temp = new byte[1024];
int length = in.read(temp);
display = EncodingUtils.getString(temp, TEXT_ENCODING);
Log.i(TAG, "fileread:"+display);
in.close();
Toast.makeText(Ecard.this, display, Toast.LENGTH_LONG).show();
} catch (Exception e) {
// TODO Auto-generated catch block
Log.e(TAG, e.getMessage());
}
}
//读取本机名片并生成XML形式的实符串
private String getLocalECardInfo() throws Exception{
StringBuffer xmlStr;
//获取名片表中第一条记录
mCardsCursor = mDbHelper.get(1, CardsDbAdapter.DATABASE_TB_CARDS);
if (mCardsCursor==null){
setListAdapter(null);
Log.e(TAG,"本机名片不在!");
throw new Exception("本机名片不在!");
}
xmlStr = new StringBuffer("<?xml version=\"1.0\" encoding=\"utf-8\"?><cardinfo>");
xmlStr.append("<username>").append(getNotNullStr(mCardsCursor.getString(1)))
.append("</username");
xmlStr.append("<phonenumber>").append(getNotNullStr(mCardsCursor.getString(3)))
.append("</phonenumber>");
xmlStr.append("<useraddress>").append(getNotNullStr(mCardsCursor.getString(4)))
.append("</useraddress>");
xmlStr.append("<usernote>").append(getNotNullStr(mCardsCursor.getString(5)))
.append("</usernote>");
xmlStr.append("</cardinfo>");
return xmlStr.toString();
}
public static String getNotNullStr(String str){
return null==str?"":str;
}
[3] 读取raw 文件夹上的资源
来源: 互联网 发布时间: 2014-02-18
读取raw 文件夹下的资源
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
/**
* This example show how to use raw files from /raw folder
* @author FaYnaSoft Labs
*
*/
public class Main extends Activity {
private static String LOG_APP_TAG = "tag";
private EditText editField;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editField = (EditText) findViewById(R.id.textId);
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InputStream inputStream = null;
try {
inputStream = getResources().openRawResource(R.raw.hello_world);
byte[] reader = new byte[inputStream.available()];
while (inputStream.read(reader) != -1) {}
editField.setText(new String(reader));
editField.setSelection(editField.getText().length());
} catch(IOException e) {
Log.e(LOG_APP_TAG, e.getMessage());
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
Log.e(LOG_APP_TAG, e.getMessage());
}
}
}
}
});
}
}
InputStream inputStream = getResources().openRawResource(R.raw.rawresource);
最新技术文章: