java-无法使用共享意图发送选定的图像

java-无法使用共享意图发送选定的图像,第1张

概述我正在创建一个应用程序,该应用程序提供MainActivity.java中某些照片的网格视图,然后在选择照片后,将一个新类定向到FullImageActivity.java.之后,我使用ShareIntents通过社交应用程序共享选定图像.在执行此 *** 作时,该应用程序在我的设备中崩溃,但是在PC模拟器中,该应用程序不会崩

我正在创建一个应用程序,该应用程序提供MainActivity.java中某些照片的网格视图,然后在选择照片后,将一个新类定向到FullImageActivity.java.
之后,我使用ShareIntents通过社交应用程序共享选定的图像.
在执行此 *** 作时,该应用程序在我的设备中崩溃,但是在PC模拟器中,该应用程序不会崩溃,而是发送空白消息.

这是我的** MainActivity.java ** //表示网格视图.

@OverrIDepublic voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    GrIDVIEw grIDVIEw = (GrIDVIEw) findVIEwByID(R.ID.grID_vIEw); //initial grID vIEw welcome screen    grIDVIEw.setAdapter(new ImageAdapter(this));    grIDVIEw.setonItemClickListener(new OnItemClickListener() {        @OverrIDe        public voID onItemClick(AdapterVIEw<?> parent, VIEw v,                int position, long ID) {            Intent i = new Intent(getApplicationContext(), FullimageActivity.class);   //switching classes            i.putExtra("ID", position);            startActivity(i);        }    });}}

这是** FullimageActivity.java **

@Suppresslint("SdCardpath")public class FullimageActivity extends Activity {@OverrIDepublic voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.full_image);    Intent i = getIntent();    int position = i.getExtras().getInt("ID");    ImageAdapter imageAdapter = new ImageAdapter(this);    ImageVIEw imageVIEw = (ImageVIEw) findVIEwByID(R.ID.full_image_vIEw);    imageVIEw.setimageResource(imageAdapter.mThumbIDs[position]);}@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) {    getMenuInflater().inflate(R.menu.main, menu);    return true;}@OverrIDepublic boolean onoptionsItemSelected(MenuItem item) {    // Handle item selection    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.ID.full_image_vIEw); //file to be saved as per user selection    file sd = Environment.getExternalStorageDirectory();    String filename = "test.png"; //saved as png file    file dest = new file(sd, filename);    try {        fileOutputStream out;        out = new fileOutputStream(dest);        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);        out.flush();        out.close();    } catch (fileNotFoundException e) {        // Todo auto-generated catch block        e.printstacktrace();    } catch (IOException e) {        // Todo auto-generated catch block        e.printstacktrace();    }    switch (item.getItemID()) {        case R.ID.item:            Uri uri = Uri.fromfile(dest);            Intent shareIntent = new Intent();            shareIntent.setAction(Intent.ACTION_SEND);            shareIntent.putExtra(Intent.EXTRA_STREAM, uri);            shareIntent.setType("image/png");            startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share))); //shared via Intent            return true;        default:            return super.onoptionsItemSelected(item);    }}}

显示我用来创建full_image.xml的选定图像

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"xmlns:tools="http://schemas.androID.com/tools"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:orIEntation="vertical" ><ImageVIEw    androID:ID="@+ID/full_image_vIEw"        androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    tools:ignore="ContentDescription" />

我将图像存储在此类中声明的数组中
** ImageAdapter.java **

package com.jai.desimeme;public class ImageAdapter extends BaseAdapter {private Context mContext;// KeePing all Images in arraypublic  Integer[] mThumbIDs = {        R.drawable.rage_0001,R.drawable.rage_178,};// Constructorpublic ImageAdapter(Context c){    mContext = c;}@OverrIDepublic int getCount() {    return mThumbIDs.length;}@OverrIDepublic Object getItem(int position) {    return mThumbIDs[position];}@OverrIDepublic long getItemID(int position) {    return 0;}@OverrIDepublic VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) {    ImageVIEw imageVIEw = new ImageVIEw(mContext);    imageVIEw.setimageResource(mThumbIDs[position]);    imageVIEw.setScaleType(ImageVIEw.ScaleType.CENTER_CROP);    imageVIEw.setLayoutParams(new GrIDVIEw.LayoutParams(70, 70));    return imageVIEw;}}

因此,有一个LogCat UPDATED

04-23 05:03:07.907: W/EGL_emulation(1172): eglSurfaceAttrib not implemented04-23 05:03:08.137: D/dalvikvm(1172): GC_FOR_ALLOC freed 33K, 3% free 4846K/4952K, paused 39ms, total 40ms04-23 05:03:10.607: W/EGL_emulation(1172): eglSurfaceAttrib not implemented04-23 05:03:11.767: D/AndroIDRuntime(1172): Shutting down VM04-23 05:03:11.777: W/dalvikvm(1172): threadID=1: thread exiting with uncaught exception (group=0xb4a8cb90)04-23 05:03:11.777: E/AndroIDRuntime(1172): FATAL EXCEPTION: main04-23 05:03:11.777: E/AndroIDRuntime(1172): Process: com.jai.desimeme, PID: 117204-23 05:03:11.777: E/AndroIDRuntime(1172): java.lang.NullPointerException04-23 05:03:11.777: E/AndroIDRuntime(1172):     at com.jai.desimeme.FullimageActivity.onoptionsItemSelected(FullimageActivity.java:55)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at androID.app.Activity.onMenuItemSelected(Activity.java:2599)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at com.androID.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1012)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at com.androID.internal.vIEw.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at com.androID.internal.vIEw.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at com.androID.internal.vIEw.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at com.androID.internal.vIEw.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:177)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at androID.Widget.AdapterVIEw.performItemClick(AdapterVIEw.java:299)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at androID.Widget.AbsListVIEw.performItemClick(AbsListVIEw.java:1113)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at androID.Widget.AbsListVIEw$PerformClick.run(AbsListVIEw.java:2904)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at androID.Widget.AbsListVIEw.run(AbsListVIEw.java:3638)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at androID.os.Handler.handleCallback(Handler.java:733)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at androID.os.Handler.dispatchMessage(Handler.java:95)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at androID.os.Looper.loop(Looper.java:137)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at androID.app.ActivityThread.main(ActivityThread.java:4998)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at java.lang.reflect.Method.invokeNative(Native Method)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at java.lang.reflect.Method.invoke(Method.java:515)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:593)04-23 05:03:11.777: E/AndroIDRuntime(1172):     at dalvik.system.NativeStart.main(Native  Method)04-23 05:03:15.517: I/Process(1172): Sending signal. PID: 1172 SIG: 904-23 05:03:16.447: D/dalvikvm(1200): GC_FOR_ALLOC freed 60K, 4% free 3117K/3244K,   paused 27ms, total 30ms04-23 05:03:16.707: D/(1200): HostConnection::get() New Host Connection established 0xb8c69818, tID 120004-23 05:03:16.967: W/EGL_emulation(1200): eglSurfaceAttrib not implemented04-23 05:03:16.977: D/Openglrenderer(1200): Enabling deBUG mode 004-23 05:03:17.057: D/dalvikvm(1200): GC_FOR_ALLOC freed 5K, 4% free 3206K/3336K, paused 21ms, total 22ms04-23 05:03:17.127: D/dalvikvm(1200): GC_FOR_ALLOC freed <1K, 4% free 3608K/3740K, paused 20ms, total 21ms04-23 05:03:17.247: D/dalvikvm(1200): GC_FOR_ALLOC freed <1K, 4% free 4027K/4164K, paused 20ms, total 20ms04-23 05:03:17.357: D/dalvikvm(1200): GC_FOR_ALLOC freed 1K, 4% free 4345K/4480K, paused 21ms, total 21ms04-23 05:03:17.447: I/Choreographer(1200): Skipped 63 frames!  The application may be doing too much work on its main thread.

此LogCat是在不会崩溃的模拟器上跟踪的,但是我无法在我的设备上跟踪此日志. :( 解决了

和Manifest.xml

<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID"package="com.jai.desimeme"androID:installLocation="auto"androID:versionCode="1"androID:versionname="1.1" ><uses-sdk    androID:minSdkVersion="8"    androID:targetSdkVersion="17" /><uses-permission androID:name="androID.permission.INTERNET" /><uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission androID:name="androID.permission.READ_EXTERNAL_STORAGE"/><uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE"/><application    androID:allowBackup="true"    androID:icon="@drawable/ic_launcher"    androID:label="@string/app_name"    androID:permission="androID.permission.WRITE_EXTERNAL_STORAGE"    androID:theme="@style/Apptheme" >    <activity        androID:name="com.jai.desimeme.MainActivity"        androID:label="@string/app_name" >        <intent-filter>            <action androID:name="androID.intent.action.MAIN" />            <category androID:name="androID.intent.category.LAUNCHER" />        </intent-filter>        <intent-filter>            <action androID:name="androID.intent.action.SEND" />            <category androID:name="androID.intent.category.DEFAulT" />            <data androID:mimeType="image/*" />        </intent-filter>        <intent-filter>            <action androID:name="androID.intent.action.SEND" />            <category androID:name="androID.intent.category.DEFAulT" />            <data androID:mimeType="text/plain" />        </intent-filter>        <intent-filter>            <action androID:name="androID.intent.action.SEND_MulTIPLE" />            <category androID:name="androID.intent.category.DEFAulT" />            <data androID:mimeType="image/*" />        </intent-filter>    </activity>    <!-- FullimageActivity -->    <activity androID:name="com.jai.desimeme.FullimageActivity" >    </activity>    <activity        androID:name="com.jai.desimeme.About"        androID:theme="@androID:style/theme.Dialog" >    </activity>    <activity        androID:name="com.jai.desimeme.ShareActivity"        androID:label="@string/Title_activity_share" >    </activity></application></manifest>

请通过这个指导我… 总结

以上是内存溢出为你收集整理的java-无法使用共享意图发送选定的图像全部内容,希望文章能够帮你解决java-无法使用共享意图发送选定的图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1076683.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存