我正在尝试将图片从我的SD发送到其他应用,例如Gmail或Google云端硬盘。 但它正在崩溃。能帮我解决发生的问题吗?感谢您的帮助!
MainActivity.java
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import java.io.File;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
public void process(View view){
Intent intent = null;
Intent chooser = null;
if(view.getId() == R.id.sendImages)
{
File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
String[] listOfPictures = pictures.list();
Uri uri = null;
ArrayList<Uri> arrayList = new ArrayList<>();
for(String picture: listOfPictures)
{
uri = Uri.parse("file://" + pictures.toString() + picture);
arrayList.add(uri);
}
intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, arrayList);
chooser = Intent.createChooser(intent, "Send Multiple Images");
startActivity(chooser);
}
}
}
这里是Logcat
07-02 23:16:02.420 1368-1368/? D/StatusBar.NetworkController: onSignalStrengthsChanged received on slotId :0signalStrength=SignalStrength: 22 0 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 2147483647 2147483647 gsm|lte level=5 cdmdlevel=0 evdolevel=0
07-02 23:16:02.560 227-227/? V/WLAN_PSA: NL MSG, len[048], NL type[0x11] WNI type[0x5050] len[028]
07-02 23:16:04.150 9259-9259/? D/dalvikvm: GC_FOR_ALLOC freed <1K, 10% free 17668K/19496K, paused 16ms, total 17ms
07-02 23:16:04.150 9259-9259/? I/dalvikvm-heap: Grow heap (frag case) to 21.722MB for 2129936-byte allocation
07-02 23:16:04.170 9259-9264/? D/dalvikvm: GC_CONCURRENT freed <1K, 9% free 19748K/21580K, paused 3ms+1ms, total 22ms
07-02 23:16:04.250 8836-8836/com.example.hacback17.testimplicitintent D/AndroidRuntime: Shutting down VM
07-02 23:16:04.250 8836-8836/com.example.hacback17.testimplicitintent W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41be5d58)
07-02 23:16:04.260 8836-8836/com.example.hacback17.testimplicitintent E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.hacback17.testimplicitintent, PID: 8836
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:289)
at android.view.View.performClick(View.java:4444)
at android.view.View$PerformClick.run(View.java:18457)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:4444)
at android.view.View$PerformClick.run(View.java:18457)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.hacback17.testimplicitintent.MainActivity.process(MainActivity.java:79)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
at android.view.View.performClick(View.java:4444)
at android.view.View$PerformClick.run(View.java:18457)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
07-02 23:16:04.270 1832-2027/? I/WhetstoneService: Receive am_crash event for pid: 8836
07-02 23:16:04.270 1832-2027/? W/KloServer: Aborted broadcast does not supprt for: com.example.hacback17.testimplicitintent
07-02 23:16:04.270 2305-2763/? I/octvm_klo: klo lock
07-02 23:16:04.280 1005-2055/? W/ActivityManager: Force finishing activity com.example.hacback17.testimplicitintent/.MainActivity
07-02 23:16:04.350 2305-2763/? I/octvm_klo: get wanted event[mask:128, name:data_app_crash@1467481564357.txt] from the watchset
07-02 23:16:04.350 2305-2763/? I/octvm_klo: start gathering logcat log...
07-02 23:16:04.500 32225-32225/? D/AutotriggerReceiver: [onReceive] Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 cmp=com.qualcomm.logkit/.autotrigger.AutotriggerReceiver (has extras) }
07-02 23:16:04.500 32225-32225/? D/AutotriggerReceiver: [onReceive] android.intent.action.DROPBOX_ENTRY_ADDED: data_app_crash
07-02 23:16:04.610 9032-9301/? I/dalvikvm: Could not find method android.os.UserHandle.isOwner, referenced from method vqb.a
07-02 23:16:04.610 9032-9301/? W/dalvikvm: VFY: unable to resolve virtual method 3134: Landroid/os/UserHandle;.isOwner ()Z
07-02 23:16:04.610 9032-9301/? D/dalvikvm: VFY: replacing opcode 0x6e at 0x000c
07-02 23:16:04.680 2305-2763/? I/octvm_klo: gathering logcat log done
07-02 23:16:04.680 2305-2763/? I/octvm_klo: klo unlock
07-02 23:16:04.810 2010-2140/? D/PowerKeeperEventLogManager: notifyForegroundCompomentChanged ComponentInfo{com.miui.home/com.miui.home.launcher.Launcher}
07-02 23:16:04.810 1005-1019/? W/ActivityManager: Activity pause timeout for ActivityRecord{43103ee8 u0 com.example.hacback17.testimplicitintent/.MainActivity t491 f}
07-02 23:16:04.820 1005-1019/? I/Timeline: Timeline: App_transition_ready time:235693712
07-02 23:16:04.840 1005-1103/? I/Timeline: Timeline: App_transition_ready time:235693731
07-02 23:16:04.840 25183-25258/? I/RenderThread: RenderThread resumed
07-02 23:16:04.840 25183-25258/? D/ScreenElementRoot: resume
07-02 23:16:04.860 1005-1015/? I/Timeline: Timeline: App_transition_ready time:235693755
07-02 23:16:04.900 1411-1411/? D/wpa_supplicant: RX ctrl_iface - hexdump(len=11): 53 49 47 4e 41 4c 5f 50 4f 4c 4c
07-02 23:16:04.900 1411-1411/? D/wpa_supplicant: wlan0: Control interface command 'SIGNAL_POLL'
07-02 23:16:04.900 1411-1411/? D/wpa_supplicant: nl80211: survey data missing!
07-02 23:16:04.910 9032-9301/? D/dalvikvm: GC_FOR_ALLOC freed 1618K, 16% free 14641K/17244K, paused 37ms, total 39ms
07-02 23:16:04.910 9032-9301/? I/dalvikvm-heap: Grow heap (frag case) to 16.922MB for 196624-byte allocation
07-02 23:16:04.920 25183-25183/? I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@428f0058 time:235693817
07-02 23:16:04.930 32225-32225/? D/AutotriggerReceiver: [onReceive] Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 cmp=com.qualcomm.logkit/.autotrigger.AutotriggerReceiver (has extras) }
07-02 23:16:04.930 1005-1018/? I/Timeline: Timeline: App_transition_ready time:235693828
07-02 23:16:04.980 1368-1368/? D/StatusBar.NetworkController: onSignalStrengthsChanged received on slotId :0signalStrength=SignalStrength: 17 0 -120 -160 -120 -1 -1 99 2147483647 2147483647 2147483647 2147483647 2147483647 gsm|lte level=5 cdmdlevel=0 evdolevel=0
07-02 23:16:05.090 25183-25183/? D/FancyDrawable: doPause: [miui.maml.FancyDrawable@43952fc0]
07-02 23:16:05.090 25183-25183/? D/MultipleRenderable: setPause: true miui.maml.FancyDrawable@43952fc0
07-02 23:16:05.090 25183-25183/? D/RendererCore: self pause: miui.maml.RendererCore@4397a5e0
07-02 23:16:05.090 25183-25183/? D/ScreenElementRoot: pause
07-02 23:16:05.110 1005-1018/? I/Timeline: Timeline: Activity_windows_visible id: ActivityRecord{42942b20 u0 com.miui.home/.launcher.Launcher t1} time:235694002
07-02 23:16:05.110 1005-1018/? I/Timeline: Timeline: App_transition_stopped time:235694004
07-02 23:16:05.120 25183-25183/? D/FancyDrawable: doResume: [miui.maml.FancyDrawable@43952fc0]
07-02 23:16:05.120 25183-25183/? D/MultipleRenderable: setPause: false miui.maml.FancyDrawable@43952fc0
07-02 23:16:05.120 25183-25183/? D/RendererCore: self resume: miui.maml.RendererCore@4397a5e0
07-02 23:16:05.120 25183-25183/? D/ScreenElementRoot: resume
07-02 23:16:05.150 1005-2066/? I/ActivityManager: Waited long enough for: ServiceRecord{43cd8b20 u0 com.miui.cloudservice/.state.MiCloudSyncStateService}
07-02 23:16:05.760 1005-1019/? I/ActivityManager: Waited long enough for: ServiceRecord{433bb4f0 u0 com.miui.cloudservice/.sync.AlertSyncService}
07-02 23:16:05.760 1005-1019/? I/ActivityManager: Waited long enough for: ServiceRecord{433bb4f0 u0 com.miui.cloudservice/.sync.AlertSyncService}
07-02 23:16:05.780 1005-1019/? I/ActivityManager: Waited long enough for: ServiceRecord{433bb4f0 u0 com.miui.cloudservice/.sync.AlertSyncService}