我需要创建一个简单的通知,如果可能的话,它会与声音和图标一起显示在通知栏中?我还需要它与Android 2.2兼容,所以我发现NotificationCompat.Builder适用于4以上的所有API.如果有更好的解决方案,请随意提及.
notifications android android-notifications android-notification-bar
如何为NotificationCompat.Builder创建的通知添加声音?我在res中创建了一个原始文件夹并在那里添加了声音.那么我现在如何将其添加到通知中?这是我的通知代码
int NOTIFY_ID=100;
Intent notificationIntent = new Intent(this, Notification.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.notification)
.setContentTitle("Warning")
.setContentText("Help!")
NotificationManager mgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mgr.notify(NOTIFY_ID, mBuilder.build());
Run Code Online (Sandbox Code Playgroud) 所以我在我的活动中创建了这个通知
Notification n = new Notification.Builder(getApplicationContext())
.setContentTitle("New mail from " + sender)
.setContentText(subject)
.setSmallIcon(R.drawable.notification)
.build();
Run Code Online (Sandbox Code Playgroud)
我现在如何在状态/通知栏中显示声音?
我尝试添加一组textview,我将其定义为一个公共变量,但是当我运行应用程序时,它会在进入for循环时立即关闭.这是代码:
LinearLayout myLayout = (LinearLayout) findViewById(R.id.my_layout);
LayoutParams lp = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
pairs=new TextView[num_match+1];
for(int l=1;l<=num_match;l++)
{
pairs[l].setTextSize(15);
pairs[l].setLayoutParams(lp);
pairs[l].setId(l);
pairs[l].setText(m1[l]+" - "+m2[l]);
myLayout.addView(pairs[l]);
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个下面的类,它上网并向php脚本发送请求.AsyncTask为了在4.0.4上工作,我创建了它而不是在主线程中创建它,但是当我测试它时它不起作用,虽然它在2.2上工作正常.你知道这是什么问题吗?
class download extends AsyncTask<String, Integer, String> {
protected String doInBackground(String s1, String s2) {
String result = "";
//http post
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("Vreme", s1));
nameValuePairs.add(new BasicNameValuePair("Datum", s2));
InputStream is = null;
try {
String adresa = "http://senzori.open.telekom.rs/script.php";
HttpPost httppost = new HttpPost(adresa);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString()); …Run Code Online (Sandbox Code Playgroud) 例如,我想打,你在文本框输入两个数字一个页面,当你点击该按钮将调用PHP文件,该文件总结它们,然后如果表达式是错误的,结果在某种标签的输出(对不起,我我习惯了c#参考)
那怎么办呢?:d