我正在使用以下代码在Android中进行调用,但它给了我安全例外,请帮忙.
posted_by = "111-333-222-4";
String uri = "tel:" + posted_by.trim() ;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
权限
<uses-permission android:name="android.permission.CALL_PHONE" />
Run Code Online (Sandbox Code Playgroud)
例外
11-25 14:47:01.661: ERROR/AndroidRuntime(302): Uncaught handler: thread main exiting due to uncaught exception
11-25 14:47:01.681: ERROR/AndroidRuntime(302): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:111-333-222-4 cmp=com.android.phone/.OutgoingCallBroadcaster } from ProcessRecord{43d32508 302:com.Finditnear/10026} (pid=302, uid=10026) requires android.permission.CALL_PHONE
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.os.Parcel.readException(Parcel.java:1218)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.os.Parcel.readException(Parcel.java:1206)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1214)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
11-25 14:47:01.681: ERROR/AndroidRuntime(302): at android.app.Activity.startActivityForResult(Activity.java:2749) …Run Code Online (Sandbox Code Playgroud) android phone-call android-intent android-implicit-intent android-phone-call
有人可以告诉我如何使用getExtra()和putExtra()意图吗?实际上我有一个字符串变量,比如str,它存储一些字符串数据.现在,我想将这些数据从一个活动发送到另一个活动.
Intent i = new Intent(FirstScreen.this, SecondScreen.class);
String keyIdentifer = null;
i.putExtra(strName, keyIdentifer );
Run Code Online (Sandbox Code Playgroud)
然后在SecondScreen.java中
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.table);
TextView userName = (TextView)findViewById(R.id.userName);
Bundle bundle = getIntent().getExtras();
if(bundle.getString("strName")!= null)
{
//TODO here get the string stored in the string variable and do
// setText() on userName
}
}
Run Code Online (Sandbox Code Playgroud)
我知道这是一个非常基本的问题但不幸的是我被困在这里.请帮忙.
谢谢,
编辑:这里我试图从一个屏幕传递到另一个屏幕的字符串是动态的.那就是我有一个editText,我得到的字符串无论用户类型如何.然后借助于myEditText.getText().toString().我将输入的值作为字符串,然后我必须传递此数据.
我有两个活动:主要活动和儿童活动.
当我按下主活动中的按钮时,将启动子活动.
现在我想将一些数据发送回主屏幕.我使用了Bundle类,但它不起作用.它会抛出一些运行时异常.
这有什么解决方案吗?
我正试图在我的应用程序内打开Gallery内置应用程序中的图像/图片.
我有一张图片的URI(图片位于SD卡上).
你有什么建议吗?
我在AndroidManifest.xml中获得以下工具提示:
Google搜索无法将应用程序编入索引; 考虑使用ACTION-VIEW意图填充添加至少一个活动.有关详细信息,请参阅问题说明
添加深层链接以将您的应用添加到Google索引中,从Google搜索中获取应用的安装和流量.
任何人都可以解释为什么会这样吗?
我想在Android应用中添加"评价此应用"链接,以便在手机上打开用户Google Play商店应用中的应用列表.
market://or http://-link?market://或http://链接的屏幕,哪个最适合使用 - market://或者http://?出于调试原因,我想列出Intent的所有额外内容(及其值).现在,获取密钥不是问题
Set<String> keys = intent.getExtras().keySet();
Run Code Online (Sandbox Code Playgroud)
但获取键的值对我来说是一个,因为一些值是字符串,一些是布尔值...我怎么能在循环中获取值(循环键)并将值写入日志文件?谢谢你的提示!
在KitKat之前(或在新Gallery之前)Intent.ACTION_GET_CONTENT返回这样的URI
内容://媒体/外部/图像/媒体/ 3951.
使用ContentResolver和quering
MediaStore.Images.Media.DATA返回文件URL.
但是在KitKat中,Gallery会返回一个URI(通过"Last"),如下所示:
内容://com.android.providers.media.documents/document/image:3951
我该如何处理?
android android-intent android-contentresolver android-gallery
在我的Android应用程序中,我有两个活动类.我在第一个按钮上有一个按钮,我想在点击它时显示第二个按钮,但是我收到错误.以下是课程:
public class FirstActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button orderButton = (Button)findViewById(R.id.order);
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(FirstActivity.this, OrderScreen.class);
startActivity(intent);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
单击按钮时应显示的第二个类,但从不执行:
public class OrderScreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order);
Button orderButton = (Button) findViewById(R.id.end);
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
如何创建一个显示第二个活动的按钮?
我可以找到一种方法从我的通知中向我的活动发送参数.
我有一个创建通知的服务.当用户点击通知时,我想用一些特殊参数打开我的主要活动.例如项目ID,因此我的活动可以加载并呈现特殊项目详细信息视图.更具体地说,我正在下载一个文件,当下载文件时,我希望通知有一个意图,当点击它时,它会以特殊模式打开我的活动.我试图使用putExtra我的意图,但似乎无法提取它,所以我认为我做错了.
我的服务中创建通知的代码:
// construct the Notification object.
final Notification notif = new Notification(R.drawable.icon, tickerText, System.currentTimeMillis());
final RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewResource(R.id.image, R.drawable.icon);
contentView.setTextViewText(R.id.text, tickerText);
contentView.setProgressBar(R.id.progress,100,0, false);
notif.contentView = contentView;
Intent notificationIntent = new Intent(context, Main.class);
notificationIntent.putExtra("item_id", "1001"); // <-- HERE I PUT THE EXTRA VALUE
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notif.contentIntent = contentIntent;
nm.notify(id, notif);
Run Code Online (Sandbox Code Playgroud)
我的Activity中的代码尝试从通知中获取额外参数:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bundle extras = getIntent().getExtras();
if(extras != null){
Log.i( "dd","Extra:" + …Run Code Online (Sandbox Code Playgroud)