我正在使用以下代码在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
使用android我意识到隐含意图在大多数情况下是很好的选择,因为它们具有灵活性.但是什么是显性意图呢?使用它们有什么好处?什么是常见的情况,使用它们是一个好习惯?
android android-intent android-implicit-intent explicit-intent
android中显式和隐式活动调用有什么区别?如果用简单的例子解释答案就会很好.
android android-activity android-implicit-intent explicit-intent
我正在尝试在我的Android项目中实现文件选择器.到目前为止我能做的是:
Intent chooseFile;
Intent intent;
chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
chooseFile.setType("*/*");
intent = Intent.createChooser(chooseFile, "Choose a file");
startActivityForResult(intent, PICKFILE_RESULT_CODE);
Run Code Online (Sandbox Code Playgroud)
然后在我的 onActivityResult()
switch(requestCode){
case PICKFILE_RESULT_CODE:
if(resultCode==-1){
Uri uri = data.getData();
String filePath = uri.getPath();
Toast.makeText(getActivity(), filePath,
Toast.LENGTH_LONG).show();
}
break;
}
Run Code Online (Sandbox Code Playgroud)
这是打开文件选择器,但它不是我想要的.例如,我想选择一个文件(.txt),然后获取它File然后使用它.有了这段代码,我想我会得到完整的路径,但它不会发生; 例如,我得到:/document/5318/.但是通过这条路径我无法获取文件.我创建了一个名为方法PathToFile()返回一个File:
private File PathToFile(String path) {
File tempFileToUpload;
tempFileToUpload = new File(path);
return tempFileToUpload;
}
Run Code Online (Sandbox Code Playgroud)
我正在试图做的是让用户选择File从任何地方表示DropBox,Drive,SDCard,Mega,等...我没有找到正确方式做到这一点,我试图让Path然后得到一个File本Path …
android android-intent android-file android-implicit-intent android-fileprovider
您好我想从我们的默认联系簿意图中选择一个联系人.我尝试了几种方法来做到这一点.请在下面找到代码.所有这些代码的问题在于,他们打开一个中间文档屏幕,用户必须选择联系人,而不是打开联系簿.
private void openContactIntent() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, ContactsContract.Contacts.CONTENT_URI);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, REQ_CONTACT_DIRECTORY);
}
Run Code Online (Sandbox Code Playgroud)
我也试过了
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
Run Code Online (Sandbox Code Playgroud)
和
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
Run Code Online (Sandbox Code Playgroud)
android android-intent android-contacts android-implicit-intent contactpicker
我正在使用自定义隐式意图从另一个Android应用程序启动Unity应用程序.这工作正常,但我无法弄清楚如何读取Unity中的意图额外数据?
ANDROID打算推出UNITY APP
i=new Intent();
i.setAction("com.company.unityapp.MyMethod");
i.putExtra("KEY","This is the message string");
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
UNITY APP AndroidManifest.xml
<intent-filter>
<action android:name="com.company.unityapp.MyMethod" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
我的场景中有一个附带脚本的GameObject.在start方法中,我有这个代码来尝试读取与intent一起传递的额外数据
AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject intent = currentActivity.Call<AndroidJavaObject>("getIntent");
bool hasExtra = intent.Call<bool> ("hasExtra", "arguments");
if (hasExtra) {
AndroidJavaObject extras = intent.Call<AndroidJavaObject> ("getExtras");
arguments = extras.Call<string> ("getString", "arguments");
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,参数总是空的.任何帮助,将不胜感激.
c# android unity-game-engine android-intent android-implicit-intent
我是android的初学者.我需要知道有没有打开Create Message窗口的意图.我试过这个代码 -
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
Run Code Online (Sandbox Code Playgroud)
但是,它提出,Gmail, Email & Message我只需要提出信息.在我的应用程序中,当我按下按钮时,我将整合它.有谁知道这个?引导我.
call按钮怎么做?我把我的号码作为一个字符串EditText.这是我的示例代码:
String phone = editPhone.getText().toString();
btnPhone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
call();
}
});
public void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse(phone));
startActivity(callIntent);
} catch (ActivityNotFoundException activityException) {
Log.e("myphone dialer", "Call failed", e);
}
}
Run Code Online (Sandbox Code Playgroud)
我添加了所有permissions清单文件.
但我得到了 NullPointerexception
Android是否有办法使用意图浏览并从SD卡中选择任何文件?
就像是:
String uri = (Environment.getExternalStorageDirectory()).getAbsolutePath();
Intent i = new Intent(Intent.ACTION_PICK, Uri.parse(uri));
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用蓝牙将文件发送到其他设备.如果我在代码中提供文件名的完整路径,我可以发送.我希望我的用户选择应该发送的文件.
android bluetooth android-intent android-implicit-intent android-bluetooth
设备在空闲一段时间后,我的应用在Android O设备上未收到ACTION_SCREEN_ON或ACTION_USER_PRESENT.我的应用程序有小部件.当用户解锁手机时,我用来自后端的数据更新这些小部件.当我定位SDK 25时,此功能一直在工作.现在我正在使用目标SDK 26编译应用程序.我将获取小部件数据的服务转换为JobService.当用户将小部件添加到主屏幕时,Everythings工作正常.然后,如果我杀了应用程序并关闭屏幕并在5分钟后说如果我解锁手机,我的应用程序会收到ACTION_SCREEN_ON和ACTION_USER_PRESENT意图我可以启动服务并更新小部件上的数据.但是,如果我将设备闲置几个小时,然后当我解锁屏幕时,应用程序不会收到ACTION_SCREEN_ON和ACTION_USER_PRESENT意图.这是由于Android O对隐式意图的限制.如果是这样你怎么解决这个问题?如果没有,那么什么方法对你有用?
android android-appwidget android-implicit-intent android-8.0-oreo