我想要获取我选择的实际音频文件的句柄.为了选择音频文件,我的意图如下:
Intent audioIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(audioIntent , 0);
Run Code Online (Sandbox Code Playgroud)
它允许我从弹出窗口中选择音频文件但是如何获取我选择的文件?
在图像的情况下,我有:
bitmap = android.provider.MediaStore.Images.Media.getBitmap(getContentResolver(), intent.getData());
Run Code Online (Sandbox Code Playgroud)
音频文件有类似的东西吗?
在阅读有关ServiceConnection类的文章时,我遇到了这个文档(http://developer.android.com/reference/android/content/ServiceConnection.html),其中写道"与系统中的许多回调一样,此类的方法是从你的过程的主线."
我想知道我是否创建了一个新线程并实现了ServiceConnection方法,系统将永远无法调用onServiceConnected(),因为它不是主线程?
我有一个警报管理器,我想看看警报是否已经设置,以及是否显示了一个不同的警报对话框,如果尚未设置它.我找到了一些我被告知应该工作的代码,但它不是.此外,如果已设置警报,警报对话框应提供取消警报的选项,但也不起作用.这是我的代码:
boolean alarmUp = (PendingIntent.getBroadcast(Main.this, 1,
new Intent(Main.this, Alarm_Receiver.class),
PendingIntent.FLAG_NO_CREATE) != null);
if (alarmUp){
//Sets up the custom alert dialog layout gathers the selected time for the notifications to be set
LayoutInflater factory = LayoutInflater.from(this);
final View time_picker = factory.inflate(R.layout.dialog_layout2, null);
AlertDialog.Builder alertDialogBuilder2 = new AlertDialog.Builder(this);
alertDialogBuilder2.setView(time_picker);
alertDialogBuilder2.setTitle("Select Your Notification Time:");
alertDialogBuilder2
.setMessage("Please select the time when you want the notifications to appear on your phone each day. Please note: If your phone restarts or runs out of battery you …Run Code Online (Sandbox Code Playgroud) 我试图将我的ListView上的值传递给我的第二个活动Intents.我不知道如何将文本值传递给我Intent导致的第二个活动.现在我Intent可以连接到第二个活动,但它不会传递tapped值的字符串.
我觉得我需要把一些东西传递给我,launchEditItem()但我不确定是什么.这是我正在处理的两个功能.
private void launchEditItem() {
Intent i = new Intent(this, EditItemActivity.class);
i.putExtra("itemOnList", ); // list item into edit text
startActivity(i);
}
private void setupEditItemListener() { // on click, run this function to display edit page
lvItems.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View item, int pos, long id) {
launchEditItem();
}
});
}
Run Code Online (Sandbox Code Playgroud)
我不确定放入什么价值i.putExtra(),但我认为我需要将一个参数传递给launchEditItem().
这是我目前在第二个活动中的内容:
public class EditItemActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用intent切换android中的活动.然而,不管我做什么,这总是崩溃.我在同一个问题上阅读了无数的主题,其中没有一个有帮助.所以我被迫提出自己的问题.
当我运行这个时,应用程序只是在4秒钟后崩溃
这是我的第一个活动(Splash):
package com.redflamedeveloper.torch;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
/** Called when the activity is first created. */
MediaPlayer mpSplash;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
mpSplash = MediaPlayer.create(this, R.raw.fire); //Splash Screen sound
mpSplash.start();
Thread logoTimer = new Thread(){ //4 Second Timer
public void run() {
try {
//Waits for 4 seconds
int logoTimer = 0;
while(logoTimer <4000){
sleep(100);
logoTimer = logoTimer + 100;
}
Intent intentMain = …Run Code Online (Sandbox Code Playgroud) 你如何从onResume()的覆盖调用getIntExtra ?
代码错误如下:
@Override
protected void onResume()
{
super.onResume();
setDDL_Selected(0);
setDDL_Selected(Intent.getIntExtra("DDL_ID", 0));
}
Run Code Online (Sandbox Code Playgroud)
编译器抛出以下错误:
非静态方法getIntExtra(java.lang.String,int)不能从静态上下文中引用?
我对String数组没什么问题.在一个课程中,我有简单的列表视图,有多种选择.最后,每个选项都放在String数组中并共享给下一个类.
SparseBooleanArray checked = listView.getCheckedItemPositions();
ArrayList<String> selectedItems = new ArrayList<String>();
for (int i = 0; i < checked.size(); i++) {
// Item position in adapter
int position = checked.keyAt(i);
// Add sport if it is checked i.e.) == TRUE!
if (checked.valueAt(i))
selectedItems.add(adapter.getItem(position));
}
String[] outputStrArr = new String[selectedItems.size()];
for (int i = 0; i < selectedItems.size(); i++) {
outputStrArr[i] = selectedItems.get(i);
}
Intent intent = new Intent(getApplicationContext(),
ReadComments.class);
// Create a bundle object
Bundle b = new Bundle();
b.putStringArray("selectedItems", outputStrArr); …Run Code Online (Sandbox Code Playgroud) 我有一个包含基本Listview的Activity.功能如下:
单击列表视图项 - >获取列表视图项名称 - >按意图传递名称并开始新活动.
除了新活动的开始之外,一切正常.它只是没有响应,我不明白为什么.我真的很感激一双额外的眼睛来看看这个.
listView = getListView();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, foodNames);
listView.setAdapter(adapter);
listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView parentView, View childView, int position, long id) {
TextView tv = (TextView) listView.getSelectedItem();
String value = tv.getText().toString();
Log.v("DEBUG","Name of item clicked" + value);
Intent intent = new Intent(childView.getContext(), FoodItemActivity.class);
intent.putExtra("FoodName", value );
startActivity(intent);
}
public void onNothingSelected(AdapterView parentView) {
}
});
Run Code Online (Sandbox Code Playgroud) 我已经创建了2个活动.当我从第一个通过intent调用第二个活动时,第二个活动的onCreate方法没有被调用.尽管第一个活动的onCreate方法正常调用它应该是. 以下是第一个活动的代码.
package com.webesperto.webespertofirstapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity implements OnClickListener {
int counter;
Button add, sub;
TextView tView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter = 0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
tView = (TextView) findViewById(R.id.textView1);
// Intent in = new Intent(AC);
add.setOnClickListener(this);
sub.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case …Run Code Online (Sandbox Code Playgroud) 为了练习,我在https://developer.android.com/training/basics/firstapp/index.html上做了"构建你的第一个应用程序"的例子. 现在我对Intents有问题.Eclipse说"无法访问的代码"我已经导入了类Intent(import android.content.Intent;)
Intent intent = getIntent();
Run Code Online (Sandbox Code Playgroud)
这是代码:
package com.example.test;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.annotation.TargetApi;
import android.os.Build;
import android.content.Intent;
import android.widget.TextView;
public class DisplayMessageActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Show the Up button in the action bar.
setupActionBar();
}
/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
} …Run Code Online (Sandbox Code Playgroud) android ×10
android-intent ×10
java ×3
alarmmanager ×1
audio ×1
crash ×1
eclipse ×1
listview ×1