我正在开发一个需要获取IMSI的应用程序.我用:
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imsi = mTelephonyMgr.getSubscriberId();
Run Code Online (Sandbox Code Playgroud)
它适用于大多数手机,但一些手机只返回6位而不是15位.这是错误的.
任何人都知道以编程方式检索IMSI的另一种方法吗?其他APIS?方法?
问候
我试图通过Android手机中的HttpClient将照片上传到服务器,但有时我得到这个错误,它不会一直发生.谁知道怎么解决呢?
我的代码如下:
HttpClient client =new DefaultHttpClient();
HttpPut httpPut = new HttpPut(uploadUrl);
InputStream in =null;
HttpResponse response =null;
try {
in = new FileInputStream(filepath);
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(in);
entity.setContentLength(new File(basepath+path).length());
httpPut.setEntity(entity);
response = client.execute(httpPut);
System.out.println(response.getStatusLine());
consume(response.getEntity());
}
Run Code Online (Sandbox Code Playgroud)
.......
错误信息:
11-22 10:32:50.370: W/System.err(15224): org.apache.http.client.ClientProtocolException
11-22 10:32:50.370: W/System.err(15224): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
11-22 10:32:50.370: W/System.err(15224): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
11-22 10:32:50.370: W/System.err(15224): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
11-22 10:32:50.370: W/System.err(15224): at com.hp.nimbus.android.skydrive.util.SkyDriveUtils_Rest.doUploadPhoto(SkyDriveUtils_Rest.java:203)
11-22 10:32:50.380: W/System.err(15224): at com.hp.nimbus.android.skydrive.util.SkyDriveUtils_Rest.uploadPhoto(SkyDriveUtils_Rest.java:250)
11-22 10:32:50.380: W/System.err(15224): at com.hp.nimbus.android.skydrive.FolderMonitorService$1.onEvent(FolderMonitorService.java:36)
11-22 10:32:50.380: W/System.err(15224): at android.os.FileObserver$ObserverThread.onEvent(FileObserver.java:125)
11-22 …Run Code Online (Sandbox Code Playgroud) 只想阻止方向,直到我的视图中加载了所有数据.所以我想到了以下代码,但它不起作用.
private class task extends AsyncTask<String, Void, String> {
protected String doInBackground(String... params) {
...
}
protected void onPostExecute(String result) {
...
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
protected void onPreExecute() {
...
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行这两行SENSOR并且NOSENSOR我的屏幕自动变为水平,而不理解为什么.那可能会发生?
编辑: 我将以下行检查当前方向,结果如下:
protected void onPreExecute() {
if (getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE) {
Log.e("TAG","LANDSCAPE");
}else{
Log.e("TAG","PORTRAIT");
}
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
}
Run Code Online (Sandbox Code Playgroud)
Logcat的结果:
LANDSCAPE
Run Code Online (Sandbox Code Playgroud)
但是,如果我删除两行(SetRequestedOrientation),我在logcat中得到这个:
PORTRAIT
Run Code Online (Sandbox Code Playgroud) 我目前正在使用apache poi工作Java项目.现在,在我的项目中,我想将doc文件转换为pdf文件.转换成功完成但我只获得pdf中的文本而不是任何文本样式或文本颜色.我的pdf文件看起来像黑白.虽然我的doc文件是彩色的,并且具有不同的文本样式.
这是我的代码,
POIFSFileSystem fs = null;
Document document = new Document();
try {
System.out.println("Starting the test");
fs = new POIFSFileSystem(new FileInputStream("/document/test2.doc"));
HWPFDocument doc = new HWPFDocument(fs);
WordExtractor we = new WordExtractor(doc);
OutputStream file = new FileOutputStream(new File("/document/test.pdf"));
PdfWriter writer = PdfWriter.getInstance(document, file);
Range range = doc.getRange();
document.open();
writer.setPageEmpty(true);
document.newPage();
writer.setPageEmpty(true);
String[] paragraphs = we.getParagraphText();
for (int i = 0; i < paragraphs.length; i++) {
org.apache.poi.hwpf.usermodel.Paragraph pr = range.getParagraph(i);
// CharacterRun run = pr.getCharacterRun(i);
// run.setBold(true);
// run.setCapitalized(true);
// run.setItalic(true); …Run Code Online (Sandbox Code Playgroud) 如何在android中打印网站的IP地址?我可以运行inetaddress并使用netbean中的system.out.println()打印它.下面是我的示例编码.
public String getHostAddress () {
InetAddress addr=null;
try {
addr= InetAddress.getByName("www.google.com");
}
catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return addr.getHostAddress();
}
Run Code Online (Sandbox Code Playgroud)
它总是显示不幸的是,你的程序已经停止.可能知道有没有办法在Android中获取被访问网站的IP地址?
05-19 14:22:39.008: I/dalvikvm(1062): threadid=3: reacting to signal 3
05-19 14:22:39.049: I/dalvikvm(1062): Wrote stack traces to '/data/anr/traces.txt'
05-19 14:22:39.688: I/dalvikvm(1062): threadid=3: reacting to signal 3
05-19 14:22:39.828: I/dalvikvm(1062): Wrote stack traces to '/data/anr/traces.txt'
05-19 14:22:39.929: D/AndroidRuntime(1062): Shutting down VM
05-19 14:22:39.948: W/dalvikvm(1062): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
05-19 14:22:40.039: E/AndroidRuntime(1062): FATAL …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用android中的loadDataWithBaseURL()方法显示html文件的内容.
我只有一个String,其中包含一个名为source的String中的Html文件数据,然后我将其传递给该方法.
例如
String source; //contain html tags with images
View.loadDataWithBaseURl(null,source,"text/html","UTF-8","about:blank");
Run Code Online (Sandbox Code Playgroud)
视图中显示的数据很好.我的问题是,如果我的html文件包含任何图像,那么我无法显示它?我怎样才能做到这一点?
我有3个类,并且名为WebServiceCleint的类正在扩展,Asynctask并且在doInBackgrnd()im传递url和im从webservice获取数据.但我从另一个名为VerifyTeacherId的类中调用此方法.现在我怎样才能显示进度对话框??? 我应该在哪里写pg.show和pg.dismiss.???
public class WebServiceClient extends AsyncTask<String, Void, String>
{
private static final String base_path = "http://www.gdaschools.in/";
protected static final String SLASH = "/";
private ProgressDialog dialog;
private Activity activity;
public WebServiceClient(Activity activity) {
this.activity = activity;
this.dialog = new ProgressDialog(activity);
}
@Override
protected void onPreExecute() {
this.dialog.setMessage("Progress start");
this.dialog.show();
}
@Override
protected String doInBackground(String... params) {
StringBuffer sb = new StringBuffer();
sb.append(base_path);
sb.append(params[0]);
HttpRetriever retrieveResponse = new HttpRetriever();
retrieveResponse.retrieve(sb.toString());
return retrieveResponse.getResponseXml();
}
@Override
protected void …Run Code Online (Sandbox Code Playgroud) 好,
所以我正在制作一个UI元素的库项目.该库有一些基于ActionBarSherlock的活动,它是android中操作栏的向后兼容库.在这些活动中,我想在操作栏中有一个按钮,无论用户在图书馆项目中使用哪种活动,都会将其带回家.
一些术语."库"指的是我正在研究的Android UI库项目."应用程序"是指开发人员可能在使用库时使用的任何客户.
通常,当你进行一项活动而你想打电话给另一项活动时,你会做这样的事情.
intent = new Intent(this, WhateverMyActivityName.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
很简单.但这是棘手的一点.Android库几乎不知道什么应用程序正在使用它们.所以'WhateverMyActivityName.class'是无用的,因为没有办法预测开发人员应用程序将调用他们的活动.
我需要更换
intent = new Intent(this, WhateverMyActivityName.class);
Run Code Online (Sandbox Code Playgroud)
有这样的东西
intent = new Intent(this, getApplication().MainActivity().getClass());
Run Code Online (Sandbox Code Playgroud)
或者可能使用某种意图动作来调用应用程序中的主Activity (Intent.ACTION_MAIN or Intent.CATEGORY_LAUNCHER)
简而言之:如何从库项目中获取应用程序主要活动?
android android-intent android-library library-project android-activity
我怎样才能缩放图库中的所选图像,我试过这个,但它不能很好地工作.`
public void onItemSelected (AdapterView<?> parent, View v, int position, long id)
{
Animation grow = AnimationUtils.loadAnimation(DetailTvShow.this, R.anim.grow);
Button btn = (Button)findViewById(R.id.button1);
btn.setText("saison "+(position+1));
View sideView = v.findViewById(position + 1);
View sideView1 = v.findViewById(position - 1);
if ((sideView != null)||(sideView1 != null)){
((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(80, 115));
((ImageView)sideView1).setLayoutParams(new `enter code here`Gallery.LayoutParams(80, 115));
}
/* sideView = parent.findViewById(position + 1);
if (sideView != null)
((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(80, 115)); */
v.startAnimation(grow);
v.setLayoutParams(new Gallery.LayoutParams(105, 140));
}`
Run Code Online (Sandbox Code Playgroud) 我想使用Android SDK进行托管,其中返回的结果按其各自的文件扩展名进行过滤(例如,不一定是名称).我做了很多研究,很累,希望社区可以帮助我..我肯定答案就在那里,但是,除了阅读SQL书或其他什么,我只是想做点什么这应该很简单,但找不到解决方案.
我想要做的事情基本上是这样的:
managedQuery(Audio.Media.EXTERNAL_CONTENT_URI, myProjection, Audio.Media.DATA + " like ? ", new String[] {"%mp3%"}, null );
Run Code Online (Sandbox Code Playgroud)
这工作除了,如果标题是"mymp3.wav",这个查询仍将返回它,因为'mp3'在名称中,但这不是我想要的 - >我希望它纯粹基于文件过滤扩展(或者,如果有办法,可以使用文件类型[例如,如果mp3的文件扩展名更改为.wav,即使文件的内容实际上是mp3,也可以用于我的目的]) .解决方案应指明一种过滤多种扩展/文件类型的方法(例如,如果我希望查询返回所有.mp3文件以及.wav文件,但不返回.amr文件).
此外,虽然我有你,但我想按字母顺序对结果进行排序.我尝试过类似的东西:
managedQuery(Audio.Media.EXTERNAL_CONTENT_URI, myProjection, null, null, MediaStore.Audio.Media.TITLE + " ASC" );
Run Code Online (Sandbox Code Playgroud)
但是,这不会过滤整个结果...也就是说,返回的列表按照mp3标题进行排序,然后,最后,它会向列表追加.wav文件也按字母顺序排序但我希望整个列表都是按字母顺序排列的,无论文件类型如何.
我知道有人在这里可以轻松回答这个问题 - >提前谢谢!!!
android ×9
apache ×1
apache-poi ×1
cursor ×1
gallery ×1
html ×1
hwpf ×1
image ×1
java ×1
mediastore ×1
projection ×1
sql ×1
webview ×1